Ticket #37342: Portfile.newlib

File Portfile.newlib, 12.0 KB (added by billy@…, 11 years ago)

Portfile to build with newlib

Line 
1# $Id: $
2
3PortSystem                      1.0
4
5name                    arm-eabi-gcc
6version                 4.3.2
7
8# Parameters for this port.
9set newlibversion       1.16.0
10set crossgcc-target arm-eabi
11set default-languages --enable-languages="c,c++"
12
13description             gcc cross-compilers for arm-eabi, with newlib runtime library.
14long_description        gnu compilers collection (including c, c++) for \
15                                        arm-eabi, with newlib runtime library.
16homepage                        http://gcc.gnu.org/
17platforms               darwin
18categories              cross devel
19maintainers             nomaintainer
20# an exception in the license allows dependents to not be GPL
21license             {GPL-3+ Permissive}
22master_sites            gnu:gcc/gcc-${version}/:gcc \
23                                        ftp://sources.redhat.com/pub/newlib/:newlib \
24                                        http://www.mirrorservice.org/sites/sourceware.org/pub/newlib/:newlib
25distfiles                       gcc-${version}.tar.bz2:gcc newlib-${newlibversion}.tar.gz:newlib
26
27#set ecosgccpatches  ecoscentric-gnutools-20090121-sw-patches.tar.bz2
28#master_sites-append http://mirrors.kernel.org/sources.redhat.com/ecos/gnutools/src/
29#distfiles-append    ${ecosgccpatches}
30
31worksrcdir                      gcc-${version}
32checksums                       gcc-${version}.tar.bz2 \
33                    md5     5dfac5da961ecd5f227c3175859a486d \
34                    sha1    787b566ad4f386a9896e2d5703e6ff5e7ccaca58 \
35                    rmd160  0ced28bd2e0d89f081cf88273b5f1530599b52fb \
36                                        newlib-${newlibversion}.tar.gz \
37                                        md5 bf8f1f9e3ca83d732c00a79a6ef29bc4 \
38                                        sha1 841edec33d19a9e549984982fb92445ee967e265 \
39                                        rmd160 fa40ff43e858da3093c9f3b5b203724b9b327696
40#                    ${ecosgccpatches} \
41#                    md5     fe55a99b6b0aa32cb2a579c0a4a5fad9 \
42#                    sha1    dec0d163195080999d7de39854cb889a1d834f0c \
43#                    rmd160  a053e18390aba0d7e6f3c72577a6768476900908
44
45
46patchfiles                      patch-gcc-config-arm-t-arm-elf.diff \
47                    patch-newlib-libc-configure.diff \
48                                        Make-lang.in.diff
49
50# All cross ports violate the mtree layout.
51destroot.violate_mtree  yes
52
53# Download everything to gcc/
54dist_subdir                     gcc
55
56depends_lib                     port:${crossgcc-target}-binutils \
57                    port:gmp \
58                    port:mpfr \
59                    port:gettext \
60                    port:libmpc
61
62# arm-eabi-binutils is not universal
63universal_variant       no
64
65# gcc is .bz2, newlib is .gz.
66# let's extract only gcc with MacPorts infrastructure, we'll do newlib manually.
67use_bzip2                       yes
68extract.only            gcc-${version}.tar.bz2
69
70# Extract eCos patches and apply
71#post-extract {
72#    system -W ${workpath} "tar -jxf ${distpath}/${ecosgccpatches}"
73#    system -W ${workpath} "patch -p0 < patches/gcc-${version}-arm.patch"
74#    system -W ${workpath} "patch -p0 < patches/gcc-${version}.patch"
75#}
76
77# Extract newlib and create a symlink of newlib/newlib in gcc directory.
78post-extract    {
79        system "cd ${workpath} && gzip -dc ${distpath}/newlib-${newlibversion}.tar.gz | tar -xf -"
80        system "ln -s ${workpath}/newlib-${newlibversion}/newlib ${workpath}/gcc-${version}/"
81}
82
83# Since we don't build gcc and binutils at the same time, gcc's Makefile will try to transform
84# program names as gcc's name (add -${version} with ${version} being the version of gcc).
85# But it won't work because binutils binaries don't have the ${version} suffix, and even if they
86# had, they would actually have the binutils' version suffix (and not gcc's version).
87# So let's tell gcc's Makefile not to do that mistake.
88
89set environment [list AR_FOR_TARGET=${crossgcc-target}-ar \
90                                AS_FOR_TARGET=${crossgcc-target}-as \
91                                LD_FOR_TARGET=${crossgcc-target}-ld \
92                                NM_FOR_TARGET=${crossgcc-target}-nm \
93                                RANLIB_FOR_TARGET=${crossgcc-target}-ranlib \
94                STRIP_FOR_TARGET=${crossgcc-target}-strip]
95
96proc multilibpatch_enable { options dirnames exceptions matches } {
97        global worksrcpath
98        system "echo 'MULTILIB_OPTIONS += ${options}' >> ${worksrcpath}/gcc/config/arm/t-arm-elf"
99        system "echo 'MULTILIB_DIRNAMES += ${dirnames}' >> ${worksrcpath}/gcc/config/arm/t-arm-elf"
100        system "echo 'MULTILIB_EXCEPTIONS += ${exceptions}' >> ${worksrcpath}/gcc/config/arm/t-arm-elf"
101        system "echo 'MULTILIB_MATCHES += ${matches}' >> ${worksrcpath}/gcc/config/arm/t-arm-elf"
102}
103
104variant be description {big endian multilib support} {
105        post-patch {
106                multilibpatch_enable \
107                        "mlittle-endian/mbig-endian" \
108                        "le be" \
109                        "" \
110                        "mbig-endian=mbe mlittle-endian=mle"
111        }
112}
113
114variant ep9312 description {ep9312 multilib support} {
115        post-patch {
116                multilibpatch_enable \
117                        "mcpu=ep9312" \
118                        "ep9312" \
119                        "*mthumb/*mcpu=ep9312* *mcpu=ep9312*/*mhard-float*" \
120                        ""
121        }
122}
123
124variant fpu description {fpu multilib support} {
125        post-patch {
126                multilibpatch_enable \
127                        "mhard-float/msoft-float" \
128                        "fpu soft" \
129                        "*mthumb/*mhard-float*" \
130                        ""
131        }
132        configure.args-append   --enable-fpu
133}
134
135variant interwork description {thumb interwork multilib support} {
136        post-patch {
137                multilibpatch_enable \
138                        "mno-thumb-interwork/mthumb-interwork" \
139                        "normal interwork" \
140                        "" \
141                        ""
142        }
143        configure.args-append   --enable-interwork
144}
145
146variant under description {leading underscore multilib support} {
147        post-patch {
148                multilibpatch_enable \
149                        "fno-leading-underscore/fleading-underscore" \
150                        "eabi under" \
151                        "" \
152                        ""
153        }
154        configure.args-append   --enable-underscore
155}
156
157variant nofmult description {no fpu multiplication multilib support} {
158        post-patch {
159                multilibpatch_enable \
160                        "mcpu=arm7" \
161                        "nofmult" \
162                        "*mthumb*/*mcpu=arm7*" \
163                        ""
164        }
165        configure.args-append   --enable-nofmult
166}
167
168# Use llvm-gcc-4.2, doesn't build with clang
169configure.compiler llvm-gcc-4.2
170
171# Build in a different directory, as advised in the README file.
172pre-configure   {
173        file mkdir "${workpath}/build"
174}
175configure.dir   ${workpath}/build
176configure.cmd   ${workpath}/gcc-${version}/configure
177configure.cc-append    -I${prefix}/include
178configure.env   ${environment}
179configure.args  --infodir='${prefix}/share/info' \
180                                --mandir='${prefix}/share/man' \
181                                --target=${crossgcc-target} \
182                                --program-prefix=${crossgcc-target}- \
183                                --without-included-gettext \
184                                --enable-obsolete \
185                                --with-newlib \
186                                --disable-__cxa_atexit \
187                                --enable-multilib \
188                                --enable-biendian \
189                                --disable-libgfortran \
190                                --with-gxx-include-dir=${prefix}/${crossgcc-target}/include/c++/${version}/ \
191                                --enable-threads \
192                                ${default-languages}
193
194configure.cc_archflags
195configure.cxx_archflags
196configure.objc_archflags
197configure.ld_archflags
198if {${os.platform} == "darwin" && ($build_arch == "x86_64" || $build_arch == "ppc64")} {
199    configure.args-append --build=${build_arch}-apple-darwin${os.major}
200}
201
202build.dir       ${workpath}/build
203
204build.args              ${environment}
205destroot.args   ${environment}
206
207post-patch {
208        namespace eval crossgcc {}
209
210        # Fix the info pages and related stuff.
211        #       
212        # path: path to the doc directory (e.g. gas/doc/)
213        # makefile: path to Makefile.in (e.g. gas/doc/Makefile.in)
214        # name: name of the info page (e.g. as)
215        # suffix: suffix of the souce page (texinfo or texi)
216        proc crossgcc::fixinfo { path makefile name suffix } {
217                global crossgcc-target worksrcpath
218
219                # Fix the source
220                reinplace "s|setfilename ${name}.info|setfilename ${crossgcc-target}-${name}.info|g" \
221                        ${worksrcpath}/${path}/${name}.${suffix}
222                reinplace "s|(${name})|(${crossgcc-target}-${name})|g" \
223                        ${worksrcpath}/${path}/${name}.${suffix}
224                reinplace "s|@file{${name}}|@file{${crossgcc-target}-${name}}|g" \
225                        ${worksrcpath}/${path}/${name}.${suffix}
226               
227                # Fix the Makefile
228                reinplace "s| ${name}.info| ${crossgcc-target}-${name}.info|g" \
229                        ${worksrcpath}/${makefile}
230                reinplace "s|/${name}.info|/${crossgcc-target}-${name}.info|g" \
231                        ${worksrcpath}/${makefile}
232                reinplace "s|^${name}.info|${crossgcc-target}-${name}.info|g" \
233                        ${worksrcpath}/${makefile}
234                reinplace "s| ${name}.pod| ${crossgcc-target}-${name}.pod|g" \
235                        ${worksrcpath}/${makefile}
236                reinplace "s|/${name}.pod|/${crossgcc-target}-${name}.pod|g" \
237                        ${worksrcpath}/${makefile}
238                reinplace "s|^${name}.pod|${crossgcc-target}-${name}.pod|g" \
239                        ${worksrcpath}/${makefile}
240                reinplace "s| ${name}.${suffix}| ${crossgcc-target}-${name}.${suffix}|g" \
241                        ${worksrcpath}/${makefile}
242                reinplace "s|/${name}.${suffix}|/${crossgcc-target}-${name}.${suffix}|g" \
243                        ${worksrcpath}/${makefile}
244                reinplace "s|^${name}.${suffix}|${crossgcc-target}-${name}.${suffix}|g" \
245                        ${worksrcpath}/${makefile}
246               
247                # Rename the source
248                file rename ${worksrcpath}/${path}/${name}.${suffix} \
249                        ${worksrcpath}/${path}/${crossgcc-target}-${name}.${suffix}
250               
251                # Fix install-info's dir.
252                # (note: this may be effectless if there was no info dir to be fixed)
253                reinplace "s|--info-dir=\$(DESTDIR)\$(infodir)|--dir-file=\$(DESTDIR)\$(infodir)/${crossgcc-target}-gcc-dir|g" \
254                        "${worksrcpath}/${makefile}"
255        }
256
257        # Fix the gettext files and related stuff.
258        #       
259        # module: name of the module (e.g. gas)
260        proc crossgcc::fixgettext { module } {
261                global crossgcc-target worksrcpath
262
263                if { [ file exists "${worksrcpath}/${module}/Makefile.in" ] } {
264                        reinplace "s|@PACKAGE@|${crossgcc-target}-@PACKAGE@|g" \
265                                "${worksrcpath}/${module}/Makefile.in"
266                        reinplace "s|${module}\.mo|${crossgcc-target}-${module}.mo|g" \
267                                "${worksrcpath}/${module}/Makefile.in"
268                }
269                if { [ file exists "${worksrcpath}/${module}/doc/Makefile.in" ] } {
270                        reinplace "s|@PACKAGE@|${crossgcc-target}-@PACKAGE@|g" \
271                                "${worksrcpath}/${module}/doc/Makefile.in"
272                }
273        }
274
275        # gcc/doc/cpp.texi
276        crossgcc::fixinfo gcc/doc/ gcc/Makefile.in cpp texi
277
278        # gcc/doc/cppinternals.texi
279        crossgcc::fixinfo gcc/doc/ gcc/Makefile.in cppinternals texi
280
281        # gcc/doc/gcc.texi
282        crossgcc::fixinfo gcc/doc/ gcc/Makefile.in gcc texi
283
284        # gcc/doc/gccint.texi
285        crossgcc::fixinfo gcc/doc/ gcc/Makefile.in gccint texi
286
287        # gcc/fortran/gfortran.texi
288        crossgcc::fixinfo gcc/fortran/ gcc/fortran/Make-lang.in gfortran texi
289
290        # gcc/java/gcj.texi
291        crossgcc::fixinfo gcc/java/ gcc/java/Make-lang.in gcj texi
292
293        # gcc/doc/gccinstall.info
294        crossgcc::fixinfo gcc/doc/ gcc/Makefile.in gccinstall info
295
296        # gettext stuff.
297        crossgcc::fixgettext gcc
298        crossgcc::fixgettext libcpp
299}
300
301pre-destroot {
302        # gcc needs the cross directory structure to be present
303        # in order to fill it during installation.
304        file mkdir "${destroot}${prefix}/${crossgcc-target}/bin"
305        file mkdir "${destroot}${prefix}/${crossgcc-target}/lib"
306}
307
308post-destroot {
309        namespace eval crossgcc {}
310
311        # Rename a man page if it exists.
312        #
313        # section: section of the man page (e.g. 1)
314        # manpage: name of the man page (e.g. cpp)
315        proc crossgcc::rename_man_page { section manpage } {
316                global crossgcc-target destroot prefix
317
318                set manpage_path "${destroot}${prefix}/share/man/man${section}/${manpage}.${section}"
319                if { [ file exists ${manpage_path} ] } {
320                        file rename ${manpage_path} \
321                                "${destroot}${prefix}/share/man/man${section}/${crossgcc-target}-${manpage}.${section}"
322                }
323        }
324
325        # Stuff I don't want (either because they're in the system
326        # or because they would conflict with other FSF ports)
327        # (it's easier for maintainability purposes to fix things here)
328
329        # aliases for locales (should be on the system)
330        file delete "${destroot}${prefix}/share/locale/locale.alias"
331       
332        # FSF propaganda (should already be there or would conflict)
333        file delete -force "${destroot}${prefix}/share/man/man7"
334
335        # (host) libiberty
336        foreach f [glob -directory "${destroot}${prefix}/lib" libiberty.a */libiberty.a] {
337        file delete $f
338    }
339
340        # aliases for charsets (should already be there)
341        file delete "${destroot}${prefix}/lib/charset.alias"
342       
343        # Remove man pages for tools that are not built as part of cross-gcc
344        file delete "${destroot}${prefix}/share/man/man1/rmic.1"
345        file delete "${destroot}${prefix}/share/man/man1/rmiregistry.1"
346        file delete "${destroot}${prefix}/share/man/man1/jv-convert.1"
347        file delete "${destroot}${prefix}/share/man/man1/gij.1"
348       
349        # For some reason, some man pages are not prefixed while they should have been
350        # (to avoid conflicting).
351        crossgcc::rename_man_page 1 cpp
352        crossgcc::rename_man_page 1 gcjh
353        crossgcc::rename_man_page 1 gcov
354        crossgcc::rename_man_page 1 jcf-dump
355        crossgcc::rename_man_page 1 jv-scan
356       
357        # There is a bug in gcc/Makefile::install-driver
358        # For cross compilers, $(GCC_INSTALL_NAME) is equal to
359        # $(target_noncanonical)-gcc-$(version)
360        # and hence the driver isn't installed.
361        xinstall -c "${workpath}/build/gcc/xgcc" \
362                "${destroot}${prefix}/bin/${crossgcc-target}-gcc-${version}"
363}