Ticket #37342: Portfile.no-newlib

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

Portfile to build without newlib but with eCos headers

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