Ticket #39520: Portfile

File Portfile, 15.5 KB (added by Veence (Vincent), 11 years ago)

Portfile for llvm and clang 3.3 (Warning! Still somewhat buggy)

Line 
1# $Id: Portfile 105491 2013-04-22 19:13:41Z larryv@macports.org $
2
3PortSystem              1.0
4PortGroup select        1.0
5
6set llvm_version        3.3
7name                    llvm-${llvm_version}
8subport                 clang-${llvm_version} {}
9set suffix              mp-${llvm_version}
10set sub_prefix          ${prefix}/libexec/llvm-${llvm_version}
11dist_subdir             llvm
12categories              lang
13platforms               darwin
14license                 NCSA
15maintainers             jeremyhu
16
17version                 ${llvm_version}
18#set compiler_rt_rev     150641
19#set libcxx_rev          ${compiler_rt_rev}
20#epoch                   1
21master_sites            http://llvm.org/releases/${version}
22extract.suffix          .tar.gz
23
24if {${subport} == "llvm-${llvm_version}"} {
25    homepage            http://llvm.org/
26    description         llvm is a next generation compiler infrastructure
27    long_description    The LLVM Core libraries provide a modern source- and \
28                        target-independent optimizer, along with code \
29                        generation support for many popular CPUs (as well as \
30                        some less common ones!) These libraries are built \
31                        around a well specified code representation known as \
32                        the LLVM intermediate representation ("LLVM IR").
33
34    depends_lib         port:libffi
35    depends_run         bin:perl:perl5 port:llvm_select
36    distfiles           llvm-${version}.src${extract.suffix}
37    worksrcdir          llvm-${version}.src
38
39    checksums           rmd160  22878ad746c50b02a7ac8713dd6f8c95c7af4220 \
40                        sha256  68766b1e70d05a25e2f502e997a3cb3937187a3296595cf6e0977d5cd6727578
41
42} elseif {${subport} == "clang-${llvm_version}"} {
43    homepage            http://clang.llvm.org/
44    description         C, C++, Objective C and Objective C++ compiler
45    long_description    Clang is an "LLVM native" C/C++/Objective-C compiler, \
46                        which aims to deliver amazingly fast compiles (e.g. \
47                        about 3x faster than GCC when compiling Objective-C \
48                        code in a debug configuration), extremely useful error \
49                        and warning messages and to provide a platform for \
50                        building great source level tools. The included Clang \
51                        Static Analyzer is a tool automatically finds bugs in \
52                        your code, and is a great example of the sort of tool \
53                        that can be built using the Clang frontend as a \
54                        library to parse C/C++ code.
55
56    distfiles           cfe-${version}.src${extract.suffix}
57    distfiles-append    compiler-rt-${version}.src${extract.suffix}
58    distfiles-append    libcxx-${version}.src${extract.suffix}
59    distfiles-append    llvm-${version}.src${extract.suffix}
60    worksrcdir          llvm-${version}.src
61
62checksums           cfe-3.3.src.tar.gz \
63                    rmd160  ff5d684c83b0c1aa36595dcb457da80b58eaf58f \
64                    sha256  b1b55de4ab3a57d3e0331a83e0284610191c77d924e3446498d9113d08dfb996 \
65                    compiler-rt-3.3.src.tar.gz \
66                    rmd160  943675fe098d1fc197d381f55ad9a72681652d09 \
67                    sha256  0e2f3180d6316e6c43f064fdd406c5c6515e682c5f31c57c28335b68c7525423 \
68                    libcxx-3.3.src.tar.gz \
69                    rmd160  b97ba28e87d30dfe5b4f540ce20a190ac0bcab9c \
70                    sha256  c403ed18d2992719c794cdd760dc87a948b62a7c2a07beb39eb984dfeb1679f1 \
71                    llvm-3.3.src.tar.gz \
72                    rmd160  22878ad746c50b02a7ac8713dd6f8c95c7af4220 \
73                    sha256  68766b1e70d05a25e2f502e997a3cb3937187a3296595cf6e0977d5cd6727578
74
75    depends_lib         port:llvm-${llvm_version} port:libffi
76    depends_run         port:clang_select port:ld64
77    depends_extract     bin:svn:subversion
78    depends_skip_archcheck-append ld64 subversion
79
80    default_variants    +analyzer
81}
82
83#fetch.type              svn
84#svn.revision            180025
85
86#set compiler_rt_rev     ${svn.revision}
87#set libcxx_rev          ${svn.revision}
88#version                 ${llvm_version}-r${svn.revision}
89#worksrcdir              trunk
90#svn.url                 http://llvm.org/svn/llvm-project/llvm/trunk
91#worksrcdir              release_33
92#svn.url                 http://llvm.org/svn/llvm-project/llvm/branches/release_33
93#default_variants-append +assertions
94
95#patchfiles      tiger.patch \
96#                tiger-shlib.patch
97#                install_target.patch \
98
99patch.pre_args  -p1
100
101if {${subport} == "clang-${llvm_version}"} {
102#    patchfiles-append    tiger-shlib-clang.patch tiger-libclang.patch scan-build-PR-35006.patch \
103#                         0001-Comment-out-SL-cctools-workaround.patch
104
105    build.target        clang-only
106    destroot.target     install-clang
107}
108
109build.env-append        VERBOSE=1 \
110                        REQUIRES_RTTI=1
111destroot.env-append     VERBOSE=1 \
112                        REQUIRES_RTTI=1
113configure.cppflags
114configure.ldflags
115configure.pre_args-delete --prefix=${prefix}
116configure.args          --enable-bindings=none --enable-libffi --enable-shared --enable-jit \
117                        --enable-optimized --disable-profiling --enable-pic \
118                        --enable-debug-symbols --disable-debug-runtime \
119                        --prefix="${sub_prefix}" --enable-targets=x86,arm,powerpc
120
121if {${subport} == "llvm-${llvm_version}"} {
122    select.group        llvm
123    select.file         ${filespath}/mp-${subport}
124} elseif {${subport} == "clang-${llvm_version}"} {
125    select.group        clang
126    select.file         ${filespath}/mp-${subport}
127}
128
129# g++-4.0 fails to build some of the newer C++ for ppc
130# Intel looks ok, but I prefer using gcc-4.2 for consistency
131compiler.blacklist gcc-4.0
132
133# TODO: base should do this: http://trac.macports.org/ticket/32542
134if {[info exists portconfigure::compiler_name_map(${configure.compiler})]} {
135    depends_build-append port:$portconfigure::compiler_name_map(${configure.compiler})
136
137    # base 2.1.x ignores the argument and just use ${configure.compiler}
138    if {[portconfigure::arch_flag_supported ${configure.compiler}]} {
139        depends_skip_archcheck-append $portconfigure::compiler_name_map(${configure.compiler})
140    }
141
142    if {[string match macports-gcc* ${configure.compiler}]} {
143        depends_lib-append port:$portconfigure::compiler_name_map(${configure.compiler})
144    }
145}
146
147variant universal {
148    build.env-append \
149        UNIVERSAL=1 \
150        UNIVERSAL_ARCH="[get_canonical_archs]"
151    destroot.env-append \
152        UNIVERSAL=1 \
153        UNIVERSAL_ARCH="[get_canonical_archs]"
154
155    post-extract {
156        # workaround a bug in Apple's shipped gcc driver-driver, patched in
157        # ours with driverdriver-num_infiles.patch
158        if {${configure.compiler} == "gcc-4.0" ||
159            ${configure.compiler} == "gcc-4.2" ||
160            ${configure.compiler} == "llvm-gcc-4.2"} {
161            system "echo \"static int ___ignoreme;\" > ${worksrcpath}/tools/llvm-shlib/ignore.c"
162        }
163    }
164}
165
166variant assertions description "Enable assertions for error detection (has performance impacts, especially on JIT)" {
167    configure.args-append --enable-assertions
168}
169
170platform darwin {
171    if {${build_arch} == "i386" } {
172        configure.pre_args-append --build=i686-apple-darwin${os.major}
173    } elseif {${build_arch} == "ppc" } {
174        configure.pre_args-append --build=powerpc-apple-darwin${os.major}
175    } elseif {${build_arch} == "ppc64" } {
176        configure.pre_args-append --build=powerpc64-apple-darwin${os.major}
177    } else {
178        configure.pre_args-append --build=${build_arch}-apple-darwin${os.major}
179    }
180
181    if {[string match "*ppc*" [get_canonical_archs]]} {
182        # http://trac.macports.org/ticket/33987
183        configure.args-append --with-optimize-option=-Os
184    }
185
186    if {${subport} == "clang-${llvm_version}" && ${os.major} <= 9} {
187        patchfiles-append leopard-no-asan.patch
188    }
189}
190
191platform darwin 8 {
192    # Tiger's DevTools make has issues with the nested ifs in compiler-rt
193    depends_run-append      port:gmake
194    depends_skip_archcheck-append gmake
195    build.cmd               ${prefix}/bin/gmake
196    destroot.cmd            ${prefix}/bin/gmake
197
198    post-configure {
199        reinplace "/^RPATH/s/=.*/=/" ${worksrcpath}/Makefile.config
200    }
201}
202
203post-extract {
204    if {${subport} == "clang-${llvm_version}"} {
205        #system "cd ${worksrcpath}/tools && svn co -r ${svn.revision} http://llvm.org/svn/llvm-project/cfe/trunk clang"
206        #system "cd ${worksrcpath}/tools && svn co -r ${svn.revision} http://llvm.org/svn/llvm-project/cfe/branches/release_33 clang"
207        file mkdir ${worksrcpath}/tools
208        file rename ${workpath}/cfe-${llvm_version}.src ${worksrcpath}/tools/clang
209
210        #system "cd ${worksrcpath}/projects && svn co -r ${compiler_rt_rev} http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt"
211        #system "cd ${worksrcpath}/projects && svn co -r ${compiler_rt_rev} http://llvm.org/svn/llvm-project/compiler-rt/branches/release_33 compiler-rt"
212        file mkdir ${worksrcpath}/projects
213        file rename ${workpath}/compiler-rt-${llvm_version}.src ${worksrcpath}/projects/compiler-rt
214
215        #system "cd ${worksrcpath}/projects && svn co -r ${libcxx_rev} http://llvm.org/svn/llvm-project/libcxx/trunk libcxx"
216        #system "cd ${worksrcpath}/projects && svn co -r ${libcxx_rev} http://llvm.org/svn/llvm-project/libcxx/branches/release_33 libcxx"
217        file rename ${workpath}/libcxx-${llvm_version}.src ${worksrcpath}/projects/libcxx
218    }
219}
220
221post-patch {
222    if {${subport} == "clang-${llvm_version}"} {
223        # http://trac.macports.org/ticket/33272
224        if {![variant_isset arm_runtime]} {
225            reinplace {/^SubDirs/ s/arm//} ${worksrcpath}/projects/compiler-rt/lib/Makefile.mk
226            reinplace {/^UniversalArchs/ s/arm[^ )]* *//g} ${worksrcpath}/projects/compiler-rt/make/platform/clang_darwin.mk
227
228            reinplace {/cc_kext_ios5/ s/^/#/} ${worksrcpath}/projects/compiler-rt/make/platform/clang_darwin.mk
229            reinplace {s/cc_kext_ios5.a//} ${worksrcpath}/tools/clang/runtime/compiler-rt/Makefile
230        }
231    }
232}
233
234post-destroot {
235    file mkdir ${destroot}${prefix}/share/doc
236    file rename ${destroot}${sub_prefix}/docs/llvm ${destroot}${prefix}/share/doc/${subport}
237
238    foreach bin [glob ${destroot}${sub_prefix}/bin/*] {
239        set bin_filename [string map "${sub_prefix} ${prefix}" ${bin}]-${suffix}
240        set exec_path [string map "${destroot}${sub_prefix} ${sub_prefix}" ${bin}]
241
242        xinstall -m 755 "${filespath}/llvm-bin" "${bin_filename}"
243        reinplace "s:EXEC_PATH:${exec_path}:" "${bin_filename}"
244    }
245
246    if {${subport} == "llvm-${llvm_version}"} {
247        # r156389 (a5d2435409858728970202226d0bbbee508fe408) temporarilary removed llvm man pages
248        #foreach man [glob ${destroot}${sub_prefix}/share/man/man1/*.1] {
249        #    set basename [string map "${destroot}${sub_prefix}/share/man/man1/ {}" ${man}]
250        #    file rename ${man} ${destroot}${prefix}/share/man/man1/[string map ".1 -${suffix}.1" ${basename}]
251        #}
252
253        foreach liba [glob ${destroot}${sub_prefix}/lib/*dylib] {
254            set liba_nodr [string map "${destroot} {}" ${liba}]
255            system "install_name_tool -id ${liba_nodr} ${liba}"
256
257            foreach libb [glob ${destroot}${sub_prefix}/lib/*dylib] {
258                set libb_base [string map "${destroot}${sub_prefix}/lib/ {}" ${libb}]
259                set libb_nodr [string map "${destroot} {}" ${libb}]
260
261                system "install_name_tool -change @executable_path/../lib/${libb_base} ${libb_nodr} ${liba}"
262            }
263        }
264    } elseif {${subport} == "clang-${llvm_version}"} {
265        system "ditto ${worksrcpath}/projects/libcxx/include ${destroot}${sub_prefix}/lib/c++/v1"
266
267        # http://trac.macports.org/ticket/33207
268        ln -s ${prefix}/libexec/ld64/ld ${destroot}${sub_prefix}/bin/ld
269
270        system "install_name_tool -id ${sub_prefix}/lib/libclang.dylib ${destroot}${sub_prefix}/lib/libclang.dylib"
271        system "install_name_tool -change @executable_path/../lib/libLLVM-${llvm_version}svn.dylib ${sub_prefix}/lib/libLLVM-${llvm_version}svn.dylib ${destroot}${sub_prefix}/lib/libclang.dylib"
272        system "install_name_tool -change @executable_path/../lib/libLLVM-${llvm_version}.dylib ${sub_prefix}/lib/libLLVM-${llvm_version}.dylib ${destroot}${sub_prefix}/lib/libclang.dylib"
273    }
274}
275
276if {${subport} == "llvm-${llvm_version}"} {
277    variant ocaml description {Enable generation of OCaml binding} {
278        depends_lib-append   port:ocaml
279
280        configure.args-delete --enable-bindings=none
281        configure.args-append --enable-bindings=ocaml
282
283        destroot.args-append  OVERRIDE_libdir=${sub_prefix}/lib
284    }
285} elseif {${subport} == "clang-${llvm_version}"} {
286    variant arm_runtime description {Build and install the arm runtime for iOS development (requires iOS SDK)} {}
287
288    set pythonver ""
289    set pythonverdot ""
290
291    if {![variant_isset python25] && ![variant_isset python26]} {
292        default_variants +python27
293    }
294
295    variant python25 conflicts python26 python27 description {Use python 2.5} {
296        set pythonver 25
297        set pythonverdot 2.5
298    }
299
300    variant python26 conflicts python25 python27 description {Use python 2.6} {
301        set pythonver 26
302        set pythonverdot 2.6
303    }
304
305    variant python27 conflicts python25 python26 description {Use python 2.7} {
306        set pythonver 27
307        set pythonverdot 2.7
308    }
309
310    variant analyzer description {Install clang static analyzer} {
311        if {[string equal "${pythonver}" ""]} {
312            ui_error "You mush select a python variant to use the clang static analyzer (+analyzer)"
313            error "Invalid variant combination"
314        }
315
316        depends_run-append port:perl5 port:python${pythonver}
317
318        post-patch {
319            reinplace "s|/usr/bin/env perl|${prefix}/bin/perl5|g" \
320                ${worksrcpath}/tools/clang/tools/scan-build/ccc-analyzer \
321                ${worksrcpath}/tools/clang/tools/scan-build/c++-analyzer \
322                ${worksrcpath}/tools/clang/tools/scan-build/scan-build
323            reinplace "s|/usr/bin/env python|${prefix}/bin/python${pythonverdot}|g" \
324                ${worksrcpath}/tools/clang/tools/scan-build/set-xcode-analyzer \
325                ${worksrcpath}/tools/clang/tools/scan-view/scan-view
326        }
327
328        post-destroot {
329            file mkdir ${destroot}${sub_prefix}/libexec
330            file copy ${worksrcpath}/tools/clang/tools/scan-build ${destroot}${sub_prefix}/libexec/scan-build
331            file copy ${worksrcpath}/tools/clang/tools/scan-view ${destroot}${sub_prefix}/libexec/scan-view
332
333            file delete -force ${destroot}${sub_prefix}/libexec/scan-build/.svn
334            file delete -force ${destroot}${sub_prefix}/libexec/scan-view/.svn
335            file delete -force ${destroot}${sub_prefix}/libexec/scan-view/Resources/.svn
336
337            ln -s ${sub_prefix}/libexec/scan-build/scan-build ${destroot}${sub_prefix}/bin/scan-build
338            ln -s ${sub_prefix}/libexec/scan-view/scan-view ${destroot}${sub_prefix}/bin/scan-view
339            ln -s ${sub_prefix}/bin ${destroot}${sub_prefix}/libexec/scan-build/bin
340
341            xinstall -m 755 "${filespath}/llvm-bin" "${destroot}${prefix}/bin/scan-build-${suffix}"
342            reinplace "s:EXEC_PATH:${sub_prefix}/bin/scan-build:" "${destroot}${prefix}/bin/scan-build-${suffix}"
343
344            xinstall -m 755 "${filespath}/llvm-bin" "${destroot}${prefix}/bin/scan-view-${suffix}"
345            reinplace "s:EXEC_PATH:${sub_prefix}/bin/scan-view:" "${destroot}${prefix}/bin/scan-view-${suffix}"
346        }
347    }
348}
349
350livecheck.type          none