source: trunk/dports/lang/llvm-3.4/Portfile

Last change on this file was 153720, checked in by ryandesign@…, 10 months ago

Allow old llvm versions to build on Sierra

References #52424

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 20.8 KB
Line 
1# $Id: Portfile 153720 2016-10-09 04:13:48Z ryandesign@macports.org $
2
3# llvm-3.4 was the last version to not require C++11, thus it is needed
4# to build libc++ in order to support C++11 in order to build newer
5# versions of llvm on older platforms.  Bootstrapping is fun...
6
7PortSystem              1.0
8PortGroup select        1.0
9PortGroup compiler_blacklist_versions 1.0
10
11set llvm_version        3.4
12set llvm_version_no_dot 34
13name                    llvm-${llvm_version}
14revision                11
15subport                 clang-${llvm_version} {}
16set suffix              mp-${llvm_version}
17set sub_prefix          ${prefix}/libexec/llvm-${llvm_version}
18dist_subdir             llvm
19categories              lang
20platforms               darwin
21license                 NCSA
22maintainers             jeremyhu larryv
23
24if {${subport} eq "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 port:ncurses port:zlib
35    depends_run         bin:perl:perl5 port:llvm_select
36} elseif {${subport} eq "clang-${llvm_version}"} {
37    homepage            http://clang.llvm.org/
38    description         C, C++, Objective C and Objective C++ compiler
39    long_description    Clang is an "LLVM native" C/C++/Objective-C compiler, \
40                        which aims to deliver amazingly fast compiles (e.g. \
41                        about 3x faster than GCC when compiling Objective-C \
42                        code in a debug configuration), extremely useful error \
43                        and warning messages and to provide a platform for \
44                        building great source level tools. The included Clang \
45                        Static Analyzer is a tool that automatically finds bugs in \
46                        your code, and is a great example of the sort of tool \
47                        that can be built using the Clang frontend as a \
48                        library to parse C/C++ code.
49
50    depends_lib         port:libxml2 port:llvm-${llvm_version} port:python27
51    depends_run         port:clang_select port:ld64
52    depends_build       port:cctools
53    depends_skip_archcheck-append cctools ld64 subversion
54
55    # Clang doesn't actually use any of these, but the LLVM makefile
56    # system overlinks its binaries. Remove (or convert to build deps?)
57    # after #46040 is resolved.
58    depends_lib-append  port:libffi port:ncurses port:zlib
59
60    default_variants    +analyzer
61}
62
63#fetch.type              svn
64#svn.revision            198150
65#
66#set compiler_rt_rev     ${svn.revision}
67#set libcxx_rev          ${svn.revision}
68#set clang-modernize_rev ${svn.revision}
69#version                 ${llvm_version}-r${svn.revision}
70#worksrcdir              trunk
71#svn.url                 http://llvm.org/svn/llvm-project/llvm/trunk
72#worksrcdir              release_${llvm_version_no_dot}
73#svn.url                 http://llvm.org/svn/llvm-project/llvm/branches/release_${llvm_version_no_dot}
74#default_variants-append +assertions
75
76version                 ${llvm_version}.2
77epoch                   1
78master_sites            http://llvm.org/releases/${version} http://llvm.org/releases/${llvm_version}
79extract.suffix          .tar.gz
80distfiles               llvm-${version}.src${extract.suffix}
81worksrcdir              llvm-${version}.src
82
83if {${distfiles} ne ""} {
84    if {${subport} eq "llvm-${llvm_version}"} {
85        if {[variant_isset polly]} {
86            distfiles-append     polly-${llvm_version}.src${extract.suffix}
87        }
88    } elseif {${subport} eq "clang-${llvm_version}"} {
89        distfiles-append     cfe-${version}.src${extract.suffix} compiler-rt-${llvm_version}.src${extract.suffix} libcxx-${version}.src${extract.suffix} clang-tools-extra-${llvm_version}.src${extract.suffix}
90    }
91}
92
93checksums           llvm-3.4.2.src.tar.gz \
94                    rmd160  5fab44850977afccee34b21c6d339bc8dea21fce \
95                    sha256  17038d47069ad0700c063caed76f0c7259628b0e79651ce2b540d506f2f1efd7 \
96                    polly-3.4.src.tar.gz \
97                    rmd160  995dc606934494344e2bdc20c1d1f49bf0cedd3c \
98                    sha256  9f1a5fb73dddc0afe47a0f4108dea818e0d1d16485899141957f87f75fa50ee7 \
99                    cfe-3.4.2.src.tar.gz \
100                    rmd160  f6b177408f5f9d3a453d41f1f60534f8e1e2845b \
101                    sha256  5ba6f5772f8d00f445209356a7daf83c5bca2da5acd10de517ad2359ae95bc10 \
102                    compiler-rt-3.4.src.tar.gz \
103                    rmd160  530225a44fa743f80df759e5354a0854eb422306 \
104                    sha256  f37c89b1383ce462d47537a0245ac798600887a9be9f63073e16b79ed536ab5c \
105                    libcxx-3.4.2.src.tar.gz \
106                    rmd160  7984caf2d055ea967544107ae1f948c77556d764 \
107                    sha256  826543ee2feb5d3313b0705145255ebb2ed8d52eace878279c2525ccde6e727c \
108                    clang-tools-extra-3.4.src.tar.gz \
109                    rmd160  8af0af0ead94bd50b1e6cbdcde5c4770bba5de0d \
110                    sha256  ba85187551ae97fe1c8ab569903beae5ff0900e21233e5eb5389f6ceab1028b4
111
112patch.pre_args  -p1
113patchfiles \
114        0001-MacPorts-Only-Update-install-targets-for-clang-subpo.patch \
115        0002-MacPorts-Only-Skip-checking-for-python-in-configure.patch \
116        0003-MacPorts-Only-Fix-sample-project-regex-to-work-with-.patch \
117        0004-Set-the-Mach-O-CPU-Subtype-to-ppc7400-when-targeting.patch \
118        0005-_CS_DARWIN_USER-macros-available-on-darwin-9.-Thanks.patch \
119        0006-Fix-dylib-install-name-when-building-on-Tiger.patch \
120        0007-Define-EXC_MASK_CRASH-and-MACH_EXCEPTION_CODES-if-th.patch \
121        llvm-skip-unittests.patch
122
123if {${subport} eq "clang-${llvm_version}"} {
124    patchfiles-append \
125        1001-MacPorts-Only-Prepare-clang-format-for-replacement-w.patch \
126        1002-MacPorts-Only-Fix-name-of-scan-view-executable-insid.patch \
127        1003-MacPorts-Only-Fix-libclang_rt-dylib-ids.patch \
128        1004-MacPorts-Only-Relocate-clang-resources-using-llvm-ve.patch \
129        1005-Call-powerpc-darwin-external-tools-with-arch-ppc.patch \
130        1006-Default-to-ppc7400-for-OSX-10.5.patch \
131        1007-reinstate-fno-objc-legacy-dispatch-behavior-when-the.patch \
132        1008-Change-__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__.patch \
133        1009-Only-call-setpriority-PRIO_DARWIN_THREAD-0-PRIO_DARW.patch \
134        1010-Fix-dylib-install-name-when-building-on-Tiger.patch \
135        2001-MacPorts-Only-Comment-out-SL-cctools-workaround.patch \
136        2002-On-darwin-build-ppc-slices-of-the-compiler-runtime-i.patch \
137        3001-buildit-build-fix-for-Leopard.patch \
138        3002-buildit-Set-compatibility-version-to-RC_ProjectSourc.patch \
139        3003-Fix-local-and-iterator-when-building-with-Lion-and-n.patch \
140        3004-Fix-missing-long-long-math-prototypes-when-using-the.patch \
141        3005-implement-atomic-using-mutex-lock_guard-for-64b-ops-.patch \
142        compiler_rt-toolchain.patch
143
144    # I'm not sure if we need to delete this.  It seems to build fine with it
145    # present, but we used to explicitly only use this patch for the llvm subport.
146    patchfiles-delete \
147        0002-MacPorts-Only-Skip-checking-for-python-in-configure.patch
148
149    # Introduces a failure during build (-arch ?? passed to ld), to be investigated:
150    patchfiles-delete \
151        1005-Call-powerpc-darwin-external-tools-with-arch-ppc.patch
152
153    build.target        clang-only
154    destroot.target     install-clang
155}
156
157build.env-append        VERBOSE=1 \
158                        REQUIRES_RTTI=1 \
159                        LLVM_SUBMIT_VERSION=3 \
160                        LLVM_SUBMIT_SUBVERSION=7.1
161destroot.env-append     VERBOSE=1 \
162                        REQUIRES_RTTI=1 \
163                        LLVM_SUBMIT_VERSION=3 \
164                        LLVM_SUBMIT_SUBVERSION=7.1
165
166configure.dir           ${workpath}/build
167build.dir               ${configure.dir}
168
169configure.cmd           ${worksrcpath}/configure
170configure.pre_args-delete --prefix=${prefix}
171configure.args          --enable-bindings=none --enable-libffi --enable-shared --enable-jit \
172                        --enable-optimized --disable-profiling --enable-pic \
173                        --enable-debug-symbols --disable-debug-runtime \
174                        --prefix="${sub_prefix}" --disable-assertions
175
176if {${subport} eq "llvm-${llvm_version}"} {
177    select.group        llvm
178    select.file         ${filespath}/mp-${subport}
179} elseif {${subport} eq "clang-${llvm_version}"} {
180    select.group        clang
181    select.file         ${filespath}/mp-${subport}
182
183    configure.args-append --with-python=${prefix}/bin/python2.7
184}
185
186# g++-4.0 fails to build some of the newer C++ for ppc. Intel looks ok, but I prefer using gcc-4.2 for consistency
187# Leopard's gcc-4.2 (5577) miscompiles llvm-3.4 for i386.
188# XCode 4.3's clang (318.x) fails per https://trac.macports.org/ticket/44161
189compiler.blacklist gcc-4.0 {gcc-4.2 <= 5577} {clang < 421}
190
191variant universal {
192    build.env-append \
193        UNIVERSAL=1 \
194        UNIVERSAL_ARCH="[get_canonical_archs]"
195    destroot.env-append \
196        UNIVERSAL=1 \
197        UNIVERSAL_ARCH="[get_canonical_archs]"
198
199    post-extract {
200        # workaround a bug in Apple's shipped gcc driver-driver, patched in
201        # ours with driverdriver-num_infiles.patch
202        if {${configure.compiler} eq "gcc-4.0" ||
203            ${configure.compiler} eq "gcc-4.2" ||
204            ${configure.compiler} eq "llvm-gcc-4.2"} {
205            system "echo \"static int ___ignoreme;\" > ${worksrcpath}/tools/llvm-shlib/ignore.c"
206        }
207    }
208}
209
210variant assertions description "Enable assertions for error detection (has performance impacts, especially on JIT)" {
211    configure.args-delete --disable-assertions
212    configure.args-append --enable-assertions
213}
214
215if {${subport} eq "clang-${llvm_version}"} {
216    # Don't self-host.  We may have issues if we have a slightly newer llvm version that
217    # is not binary compatible with the older clang version we're trying to use.
218
219    compiler.blacklist-append macports-clang-${llvm_version}
220}
221
222# blacklist current and future versions if they're not available in order to
223# help break potential dependency cycles.
224foreach ver {3.4 3.5 3.6 3.7 3.8 3.9 devel} {
225    if {![file exists ${prefix}/bin/clang-mp-${ver}]} {
226        compiler.blacklist-append macports-clang-${ver}
227    }
228}
229
230platform darwin {
231    if {${build_arch} eq "i386"} {
232        configure.pre_args-append --build=i686-apple-darwin${os.major}
233    } elseif {${build_arch} eq "ppc"} {
234        configure.pre_args-append --build=powerpc-apple-darwin${os.major}
235    } elseif {${build_arch} eq "ppc64"} {
236        configure.pre_args-append --build=powerpc64-apple-darwin${os.major}
237    } else {
238        configure.pre_args-append --build=${build_arch}-apple-darwin${os.major}
239    }
240
241    if {[string match "*ppc*" [get_canonical_archs]]} {
242        # http://trac.macports.org/ticket/33987
243        configure.args-append --with-optimize-option=-Os
244        configure.optflags    -Os
245    }
246
247    if {${subport} eq "clang-${llvm_version}" && ${os.major} <= 9} {
248        patchfiles-append leopard-no-asan.patch leopard-no-blocks.patch
249    }
250
251    # TODO: The llvm build system sets a 10.1 deployment target on Yosemite
252    if {[vercmp ${macosx_deployment_target} 10.10] >= 0} {
253        macosx_deployment_target 10.9
254    }
255
256    if {${os.major} < 10} {
257        post-patch {
258            reinplace "/TARGETS_TO_BUILD=/s/R600//" ${worksrcpath}/configure
259        }
260    }
261
262    if {${os.major} < 9} {
263        # Tiger's DevTools make has issues with the nested ifs in compiler-rt
264        depends_run-append      port:gmake
265        build.cmd               ${prefix}/bin/gmake
266
267        post-configure {
268            reinplace "/^RPATH/s/=.*/=/" ${configure.dir}/Makefile.config
269        }
270    }
271}
272
273post-extract {
274    if {${subport} eq "llvm-${llvm_version}"} {
275        if {[variant_isset polly]} {
276            if {${worksrcdir} eq "trunk"} {
277                system "cd ${worksrcpath}/tools && svn co -r ${svn.revision} http://llvm.org/svn/llvm-project/polly/trunk polly"
278            } elseif {${worksrcdir} eq "release_${llvm_version_no_dot}" } {
279                system "cd ${worksrcpath}/tools && svn co -r ${svn.revision} http://llvm.org/svn/llvm-project/polly/branches/release_${llvm_version_no_dot} polly"
280            } else {
281                file rename ${workpath}/polly-${llvm_version} ${worksrcpath}/tools/polly
282            }
283        }
284    } elseif {${subport} eq "clang-${llvm_version}"} {
285        if {${worksrcdir} eq "trunk"} {
286            system "cd ${worksrcpath}/tools && svn co -r ${svn.revision} http://llvm.org/svn/llvm-project/cfe/trunk clang"
287            system "cd ${worksrcpath}/projects && svn co -r ${compiler_rt_rev} http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt"
288            system "cd ${worksrcpath}/projects && svn co -r ${libcxx_rev} http://llvm.org/svn/llvm-project/libcxx/trunk libcxx"
289            system "cd ${worksrcpath}/tools/clang/tools && svn co -r ${clang-modernize_rev} http://llvm.org/svn/llvm-project/clang-tools-extra/trunk extra"
290        } elseif {${worksrcdir} eq "release_${llvm_version_no_dot}" } {
291            system "cd ${worksrcpath}/tools && svn co -r ${svn.revision} http://llvm.org/svn/llvm-project/cfe/branches/release_${llvm_version_no_dot} clang"
292            system "cd ${worksrcpath}/projects && svn co -r ${compiler_rt_rev} http://llvm.org/svn/llvm-project/compiler-rt/branches/release_${llvm_version_no_dot} compiler-rt"
293            system "cd ${worksrcpath}/projects && svn co -r ${libcxx_rev} http://llvm.org/svn/llvm-project/libcxx/branches/release_${llvm_version_no_dot} libcxx"
294            system "cd ${worksrcpath}/tools/clang/tools && svn co -r ${clang-modernize_rev} http://llvm.org/svn/llvm-project/clang-tools-extra/branches/release_${llvm_version_no_dot} extra"
295        } else {
296            file rename ${workpath}/cfe-${version}.src ${worksrcpath}/tools/clang
297            file rename ${workpath}/compiler-rt-${llvm_version} ${worksrcpath}/projects/compiler-rt
298            file rename ${workpath}/libcxx-${version}.src ${worksrcpath}/projects/libcxx
299            file rename ${workpath}/clang-tools-extra-${llvm_version} ${worksrcpath}/tools/clang/tools/extra
300        }
301    }
302}
303
304post-patch {
305    if {${subport} eq "clang-${llvm_version}"} {
306        # http://trac.macports.org/ticket/33272
307        if {![variant_isset arm_runtime]} {
308            reinplace {/^SubDirs/ s/arm//} ${worksrcpath}/projects/compiler-rt/lib/Makefile.mk
309            reinplace {/^UniversalArchs/ s/arm[^ )]* *//g} ${worksrcpath}/projects/compiler-rt/make/platform/clang_darwin.mk
310
311            reinplace {/cc_kext_ios5/ s/^/#/} ${worksrcpath}/projects/compiler-rt/make/platform/clang_darwin.mk
312            reinplace {s/cc_kext_ios5.a//} ${worksrcpath}/tools/clang/runtime/compiler-rt/Makefile
313        }
314
315        reinplace {s/VERBOSE := 0/VERBOSE := 1/} ${worksrcpath}/projects/compiler-rt/make/config.mk
316
317        reinplace "s|@@PREFIX@@|${prefix}|g" \
318            ${worksrcpath}/projects/compiler-rt/make/platform/clang_darwin.mk \
319            ${worksrcpath}/projects/compiler-rt/make/platform/clang_darwin_embedded.mk
320    }
321}
322
323post-destroot {
324    file mkdir ${destroot}${prefix}/share/doc
325    file rename ${destroot}${sub_prefix}/docs/llvm ${destroot}${prefix}/share/doc/${subport}
326
327    foreach bin [glob ${destroot}${sub_prefix}/bin/*] {
328        set bin_filename [string map "${sub_prefix} ${prefix}" ${bin}]-${suffix}
329        set exec_path [string map "${destroot}${sub_prefix} ${sub_prefix}" ${bin}]
330
331        xinstall -m 755 "${filespath}/llvm-bin" "${bin_filename}"
332        reinplace "s:EXEC_PATH:${exec_path}:" "${bin_filename}"
333    }
334
335    if {${subport} eq "llvm-${llvm_version}"} {
336        # r156389 (a5d2435409858728970202226d0bbbee508fe408) temporarilary removed llvm man pages
337        #foreach man [glob ${destroot}${sub_prefix}/share/man/man1/*.1] {
338        #    set basename [string map "${destroot}${sub_prefix}/share/man/man1/ {}" ${man}]
339        #    file rename ${man} ${destroot}${prefix}/share/man/man1/[string map ".1 -${suffix}.1" ${basename}]
340        #}
341    } elseif {${subport} eq "clang-${llvm_version}"} {
342        system "ditto ${worksrcpath}/projects/libcxx/include ${destroot}${sub_prefix}/lib/c++/v1"
343
344        # http://trac.macports.org/ticket/33207
345        ln -s ${prefix}/libexec/ld64/ld ${destroot}${sub_prefix}/bin/ld
346    }
347}
348
349if {${subport} eq "llvm-${llvm_version}"} {
350    variant polly description {Provide the polly polyhedral optimizer} {
351        patchfiles-append polly-isl-0.13.patch
352
353        depends_lib-append \
354            port:gmp \
355            path:lib/pkgconfig/isl.pc:isl \
356            path:lib/pkgconfig/cloog-isl.pc:cloog
357    }
358
359    variant ocaml description {Enable generation of OCaml binding} {
360        depends_lib-append   port:ocaml
361
362        configure.args-delete --enable-bindings=none
363        configure.args-append --enable-bindings=ocaml
364
365        destroot.args-append  OVERRIDE_libdir=${sub_prefix}/lib
366    }
367} elseif {${subport} eq "clang-${llvm_version}"} {
368    variant arm_runtime description {Build and install the arm runtime for iOS development (requires iOS SDK)} {}
369
370    # The iOS SDK was shipped with all Xcode releases after 4.0
371    if {[info exists xcodeversion] && [vercmp "4.0" ${xcodeversion}] <= 0} {
372       default_variants-append +arm_runtime
373    }
374
375    variant analyzer description {Install clang static analyzer} {
376        depends_run-append port:perl5
377
378        post-patch {
379            reinplace "s|/usr/bin/env perl|${prefix}/bin/perl5|g" \
380                ${worksrcpath}/tools/clang/tools/scan-build/ccc-analyzer \
381                ${worksrcpath}/tools/clang/tools/scan-build/c++-analyzer \
382                ${worksrcpath}/tools/clang/tools/scan-build/scan-build
383            reinplace "s|/usr/bin/env python|${prefix}/bin/python2.7|g" \
384                ${worksrcpath}/tools/clang/tools/scan-build/set-xcode-analyzer \
385                ${worksrcpath}/tools/clang/tools/scan-view/scan-view
386        }
387
388        post-destroot {
389            file mkdir ${destroot}${sub_prefix}/libexec
390            file copy ${worksrcpath}/tools/clang/tools/scan-build ${destroot}${sub_prefix}/libexec/scan-build
391            file copy ${worksrcpath}/tools/clang/tools/scan-view ${destroot}${sub_prefix}/libexec/scan-view
392
393            file delete -force ${destroot}${sub_prefix}/libexec/scan-build/.svn
394            file delete -force ${destroot}${sub_prefix}/libexec/scan-view/.svn
395            file delete -force ${destroot}${sub_prefix}/libexec/scan-view/Resources/.svn
396
397            ln -s ${sub_prefix}/libexec/scan-build/scan-build ${destroot}${sub_prefix}/bin/scan-build
398            ln -s ${sub_prefix}/libexec/scan-view/scan-view ${destroot}${sub_prefix}/bin/scan-view
399            ln -s ${sub_prefix}/bin ${destroot}${sub_prefix}/libexec/scan-build/bin
400
401            xinstall -m 755 "${filespath}/llvm-bin" "${destroot}${prefix}/bin/scan-build-${suffix}"
402            reinplace "s:EXEC_PATH:${sub_prefix}/bin/scan-build:" "${destroot}${prefix}/bin/scan-build-${suffix}"
403
404            xinstall -m 755 "${filespath}/llvm-bin" "${destroot}${prefix}/bin/scan-view-${suffix}"
405            reinplace "s:EXEC_PATH:${sub_prefix}/bin/scan-view:" "${destroot}${prefix}/bin/scan-view-${suffix}"
406        }
407    }
408
409
410    post-patch {
411        reinplace "s|@CLANG_FORMAT_PATH@|${prefix}/bin/clang-format-${suffix}|g" \
412            ${worksrcpath}/tools/clang/tools/clang-format/clang-format-bbedit.applescript \
413            ${worksrcpath}/tools/clang/tools/clang-format/clang-format-diff.py            \
414            ${worksrcpath}/tools/clang/tools/clang-format/clang-format-sublime.py         \
415            ${worksrcpath}/tools/clang/tools/clang-format/clang-format.el                 \
416            ${worksrcpath}/tools/clang/tools/clang-format/clang-format.py
417    }
418
419    post-destroot {
420        file mkdir ${destroot}${sub_prefix}/libexec
421        file copy ${worksrcpath}/tools/clang/tools/clang-format ${destroot}${sub_prefix}/libexec/clang-format
422
423        file delete -force ${destroot}${sub_prefix}/libexec/clang-format/.svn
424        file delete -force ${destroot}${sub_prefix}/libexec/clang-format/Makefile
425        file delete -force ${destroot}${sub_prefix}/libexec/clang-format/Release+Debug+Asserts
426        file delete -force ${destroot}${sub_prefix}/libexec/clang-format/CMakeLists.txt
427        file delete -force ${destroot}${sub_prefix}/libexec/clang-format/ClangFormat.cpp
428    }
429
430    if {${os.platform} eq "darwin" && ${os.major} > 15} {
431        depends_build
432        depends_lib
433        depends_run
434        archive_sites
435        pre-fetch {
436            ui_error "${subport} is not supported on macOS Sierra or newer."
437            return -code error {unsupported platform}
438        }
439    }
440}
441
442livecheck.type          none
Note: See TracBrowser for help on using the repository browser.