source: trunk/dports/lang/llvm-3.6/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: 19.9 KB
Line 
1# $Id: Portfile 153720 2016-10-09 04:13:48Z ryandesign@macports.org $
2
3PortSystem              1.0
4PortGroup select        1.0
5PortGroup compiler_blacklist_versions 1.0
6
7set llvm_version        3.6
8set llvm_version_no_dot 36
9name                    llvm-${llvm_version}
10revision                4
11subport                 clang-${llvm_version} {}
12set suffix              mp-${llvm_version}
13set sub_prefix          ${prefix}/libexec/llvm-${llvm_version}
14dist_subdir             llvm
15categories              lang
16platforms               darwin
17license                 NCSA
18maintainers             jeremyhu larryv
19
20if {${subport} eq "llvm-${llvm_version}"} {
21    homepage            http://llvm.org/
22    description         llvm is a next generation compiler infrastructure
23    long_description    The LLVM Core libraries provide a modern source- and \
24                        target-independent optimizer, along with code \
25                        generation support for many popular CPUs (as well as \
26                        some less common ones!) These libraries are built \
27                        around a well specified code representation known as \
28                        the LLVM intermediate representation ("LLVM IR").
29
30    depends_lib         port:libedit port:libffi port:ncurses port:zlib
31    depends_run         bin:perl:perl5 port:llvm_select
32
33    # 3.2.6's install_name_tool doesn't support load commands we might see with newer clang+ld64
34    # 4.3 is just a guess here and should be updated if there are additional reports with other Xcode versions
35    if {[vercmp $xcodeversion 4.3] < 0 && [string match "*macports*" ${configure.compiler}]} {
36        depends_build-append port:cctools
37    }
38} elseif {${subport} eq "clang-${llvm_version}"} {
39    homepage            http://clang.llvm.org/
40    description         C, C++, Objective C and Objective C++ compiler
41    long_description    Clang is an "LLVM native" C/C++/Objective-C compiler, \
42                        which aims to deliver amazingly fast compiles (e.g. \
43                        about 3x faster than GCC when compiling Objective-C \
44                        code in a debug configuration), extremely useful error \
45                        and warning messages and to provide a platform for \
46                        building great source level tools. The included Clang \
47                        Static Analyzer is a tool that automatically finds bugs in \
48                        your code, and is a great example of the sort of tool \
49                        that can be built using the Clang frontend as a \
50                        library to parse C/C++ code.
51
52    depends_lib         port:libxml2 port:llvm-${llvm_version} port:python27
53    depends_run         port:clang_select port:ld64
54    depends_build       port:cctools
55    depends_skip_archcheck-append cctools ld64 subversion
56
57    # Clang doesn't actually use any of these, but the LLVM makefile
58    # system overlinks its binaries. Remove (or convert to build deps?)
59    # after #46040 is resolved.
60    depends_lib-append  port:libedit port:libffi port:ncurses port:zlib
61
62    default_variants    +analyzer
63}
64
65#fetch.type              svn
66#svn.revision            229298
67
68#set compiler_rt_rev     ${svn.revision}
69#set libcxx_rev          ${svn.revision}
70#set clang-modernize_rev ${svn.revision}
71#version                 ${llvm_version}-r${svn.revision}
72#worksrcdir              trunk
73#svn.url                 https://llvm.org/svn/llvm-project/llvm/trunk
74#worksrcdir              release_${llvm_version_no_dot}
75#svn.url                 https://llvm.org/svn/llvm-project/llvm/branches/release_${llvm_version_no_dot}
76#default_variants-append +assertions
77
78version                 ${llvm_version}.2
79epoch                   1
80master_sites            http://llvm.org/releases/${version}
81use_xz                  yes
82extract.suffix          .tar.xz
83distfiles               llvm-${version}.src${extract.suffix}
84worksrcdir              llvm-${version}.src
85
86if {${distfiles} ne ""} {
87    if {${subport} eq "llvm-${llvm_version}"} {
88        if {[variant_isset polly]} {
89            distfiles-append     polly-${version}.src${extract.suffix}
90        }
91    } elseif {${subport} eq "clang-${llvm_version}"} {
92        distfiles-append     cfe-${version}.src${extract.suffix} compiler-rt-${version}.src${extract.suffix} libcxx-${version}.src${extract.suffix} clang-tools-extra-${version}.src${extract.suffix}
93    }
94}
95
96checksums           llvm-3.6.2.src.tar.xz \
97                    rmd160  521cbc5fe2925ea3c6e90c7a31f752a04045c972 \
98                    sha256  f60dc158bfda6822de167e87275848969f0558b3134892ff54fced87e4667b94 \
99                    cfe-3.6.2.src.tar.xz \
100                    rmd160  10d913b4d5317f8c2520e5fc6117df30937317a8 \
101                    sha256  ae9180466a23acb426d12444d866b266ff2289b266064d362462e44f8d4699f3 \
102                    compiler-rt-3.6.2.src.tar.xz \
103                    rmd160  9b68a32d49d4bef4603d550934192f39fea42895 \
104                    sha256  0f2ff37d80a64575fecd8cf0d5c50f7ac1f837ddf700d1855412bb7547431d87 \
105                    libcxx-3.6.2.src.tar.xz \
106                    rmd160  42b8832d01d4e6b553babc93cb5dbd4ce2bb1931 \
107                    sha256  52f3d452f48209c9df1792158fdbd7f3e98ed9bca8ebb51fcd524f67437c8b81 \
108                    clang-tools-extra-3.6.2.src.tar.xz \
109                    rmd160  4e56b0d5a8056c3800522efb9cc4d52c94ab2af2 \
110                    sha256  6a0ec627d398f501ddf347060f7a2ccea4802b2494f1d4fd7bda3e0442d04feb \
111                    polly-3.6.2.src.tar.xz \
112                    rmd160  59515632836a37c2790677b5b332868578528e31 \
113                    sha256  f2a956730b76212f22a1c10f35f195795e4d027ad28c226f97ddb8c0fd16bcbc
114
115patch.pre_args  -p1
116patchfiles \
117        0001-Set-the-Mach-O-CPU-Subtype-to-ppc7400-when-targeting.patch \
118        0002-MacPorts-Only-Update-install-targets-for-clang-subpo.patch \
119        0003-MacPorts-Only-Use-full-path-for-the-dylib-id-instead.patch \
120        0004-MacPorts-Only-Don-t-embed-the-deployment-target-in-t.patch \
121        0005-MacPorts-Only-Skip-checking-for-python-in-configure.patch \
122        llvm-skip-unittests.patch
123
124if {${subport} eq "clang-${llvm_version}"} {
125    patchfiles-append \
126        1001-MacPorts-Only-Prepare-clang-format-for-replacement-w.patch \
127        1002-MacPorts-Only-Fall-back-on-xcodebuild-sdk-when-xcrun.patch \
128        1003-MacPorts-Only-Fix-name-of-scan-view-executable-insid.patch \
129        1004-MacPorts-Only-Fix-libclang_rt-dylib-ids.patch \
130        1005-MacPorts-Only-Relocate-clang-resources-using-llvm-ve.patch \
131        1006-Default-to-ppc7400-for-OSX-10.5.patch \
132        1007-Only-call-setpriority-PRIO_DARWIN_THREAD-0-PRIO_DARW.patch \
133        1008-Default-to-fragile-ObjC-runtime-when-targeting-darwi.patch \
134        2001-MacPorts-Only-Comment-out-SL-cctools-workaround.patch \
135        2002-Update-CheckArches-to-fallback-on-Intel-ppc-if-ld-v-.patch \
136        2003-Fall-back-on-xcodebuild-sdk-when-xcrun-sdk-is-not-su.patch \
137        2004-On-darwin-build-ppc-slices-of-the-compiler-runtime-i.patch \
138        2005-MacPorts-Only-Don-t-build-x86_64h-slice-of-compiler-.patch \
139        3001-buildit-build-fix-for-Leopard.patch \
140        3002-buildit-Set-compatibility-version-to-RC_ProjectSourc.patch \
141        3003-Fix-local-and-iterator-when-building-with-Lion-and-n.patch \
142        3004-Fix-missing-long-long-math-prototypes-when-using-the.patch \
143        3005-implement-atomic-using-mutex-lock_guard-for-64b-ops-.patch \
144        compiler_rt-toolchain.patch
145
146    # I'm not sure if we need to delete this.  It seems to build fine with it
147    # present, but we used to explicitly only use this patch for the llvm subport.
148    patchfiles-delete \
149        0005-MacPorts-Only-Skip-checking-for-python-in-configure.patch
150
151    build.target        clang-only
152    destroot.target     install-clang
153}
154
155build.env-append        VERBOSE=1 \
156                        REQUIRES_RTTI=1 \
157                        LLVM_SUBMIT_VERSION=3 \
158                        LLVM_SUBMIT_SUBVERSION=7.1
159destroot.env-append     VERBOSE=1 \
160                        REQUIRES_RTTI=1 \
161                        LLVM_SUBMIT_VERSION=3 \
162                        LLVM_SUBMIT_SUBVERSION=7.1
163
164configure.dir           ${workpath}/build
165build.dir               ${configure.dir}
166
167configure.cmd           ${worksrcpath}/configure
168configure.pre_args-delete --prefix=${prefix}
169configure.args          --enable-bindings=none --enable-libffi --enable-shared --enable-jit \
170                        --enable-optimized --disable-profiling --enable-pic \
171                        --enable-debug-symbols --disable-debug-runtime \
172                        --prefix="${sub_prefix}" --disable-assertions
173
174if {${subport} eq "llvm-${llvm_version}"} {
175    select.group        llvm
176    select.file         ${filespath}/mp-${subport}
177} elseif {${subport} eq "clang-${llvm_version}"} {
178    select.group        clang
179    select.file         ${filespath}/mp-${subport}
180
181    configure.args-append --with-python=${prefix}/bin/python2.7
182}
183
184# llvm-3.5 and later requires a C++11 runtime
185# XCode 4.3's clang (318.x) fails per https://trac.macports.org/ticket/44161
186# XCode 4.5's clang (421.11.66) fails due to http://llvm.org/bugs/show_bug.cgi?id=20184
187# Xcode 4.6.x's clang (425.0.28) works, assuming 425.0.24 from 4.6.0 works too
188compiler.blacklist *gcc* {clang < 425.0.24}
189
190if {${subport} eq "clang-${llvm_version}"} {
191    # Don't self-host.  We may have issues if we have a slightly newer llvm version that
192    # is not binary compatible with the older clang version we're trying to use.
193
194    compiler.blacklist-append macports-clang-${llvm_version}
195}
196
197# blacklist current and future versions if they're not available in order to
198# help break potential dependency cycles.
199foreach ver {3.6 3.7 3.8 3.9 devel} {
200    if {![file exists ${prefix}/bin/clang-mp-${ver}]} {
201        compiler.blacklist-append macports-clang-${ver}
202    }
203}
204
205platform darwin {
206    # Note that we are forcing this choice.  This means that anything linking
207    # against llvm-3.5 needs to also be using libc++.  This is possibly
208    # problematic, but luckily there is just a limited set of such dependents.
209
210    configure.cxx_stdlib libc++
211    depends_lib-append port:libcxx
212    supported_archs i386 x86_64
213
214    pre-fetch {
215        if {![file exists /usr/lib/libc++.dylib]} {
216            ui_error "$name requires a C++11 runtime, which your configuration does not allow"
217            error "unsupported configuration"
218        }
219    }
220}
221
222variant universal {
223    build.env-append \
224        UNIVERSAL=1 \
225        UNIVERSAL_ARCH="[get_canonical_archs]"
226    destroot.env-append \
227        UNIVERSAL=1 \
228        UNIVERSAL_ARCH="[get_canonical_archs]"
229
230    post-extract {
231        # workaround a bug in Apple's shipped gcc driver-driver, patched in
232        # ours with driverdriver-num_infiles.patch
233        if {${configure.compiler} eq "gcc-4.0" ||
234            ${configure.compiler} eq "gcc-4.2" ||
235            ${configure.compiler} eq "llvm-gcc-4.2"} {
236            system "echo \"static int ___ignoreme;\" > ${worksrcpath}/tools/llvm-shlib/ignore.c"
237        }
238    }
239}
240
241variant assertions description "Enable assertions for error detection (has performance impacts, especially on JIT)" {
242    configure.args-delete --disable-assertions
243    configure.args-append --enable-assertions
244}
245
246platform darwin {
247    if {${build_arch} eq "i386"} {
248        configure.pre_args-append --build=i686-apple-darwin${os.major}
249    } elseif {${build_arch} eq "ppc"} {
250        configure.pre_args-append --build=powerpc-apple-darwin${os.major}
251    } elseif {${build_arch} eq "ppc64"} {
252        configure.pre_args-append --build=powerpc64-apple-darwin${os.major}
253    } else {
254        configure.pre_args-append --build=${build_arch}-apple-darwin${os.major}
255    }
256
257    if {[string match "*ppc*" [get_canonical_archs]]} {
258        # http://trac.macports.org/ticket/33987
259        configure.args-append --with-optimize-option=-Os
260        configure.optflags    -Os
261    }
262
263    if {${subport} eq "clang-${llvm_version}" && ${os.major} <= 9} {
264        patchfiles-append leopard-no-asan.patch leopard-no-blocks.patch
265    }
266}
267
268post-extract {
269    if {${subport} eq "llvm-${llvm_version}"} {
270        if {[variant_isset polly]} {
271            if {${worksrcdir} eq "trunk"} {
272                system "cd ${worksrcpath}/tools && svn co -r ${svn.revision} http://llvm.org/svn/llvm-project/polly/trunk polly"
273            } elseif {${worksrcdir} eq "release_${llvm_version_no_dot}" } {
274                system "cd ${worksrcpath}/tools && svn co -r ${svn.revision} http://llvm.org/svn/llvm-project/polly/branches/release_${llvm_version_no_dot} polly"
275            } else {
276                file rename ${workpath}/polly-${version}.src ${worksrcpath}/tools/polly
277            }
278        }
279    } elseif {${subport} eq "clang-${llvm_version}"} {
280        if {${worksrcdir} eq "trunk"} {
281            system "cd ${worksrcpath}/tools && svn co -r ${svn.revision} http://llvm.org/svn/llvm-project/cfe/trunk clang"
282            system "cd ${worksrcpath}/projects && svn co -r ${compiler_rt_rev} http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt"
283            system "cd ${worksrcpath}/projects && svn co -r ${libcxx_rev} http://llvm.org/svn/llvm-project/libcxx/trunk libcxx"
284            system "cd ${worksrcpath}/tools/clang/tools && svn co -r ${clang-modernize_rev} http://llvm.org/svn/llvm-project/clang-tools-extra/trunk extra"
285        } elseif {${worksrcdir} eq "release_${llvm_version_no_dot}" } {
286            system "cd ${worksrcpath}/tools && svn co -r ${svn.revision} http://llvm.org/svn/llvm-project/cfe/branches/release_${llvm_version_no_dot} clang"
287            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"
288            system "cd ${worksrcpath}/projects && svn co -r ${libcxx_rev} http://llvm.org/svn/llvm-project/libcxx/branches/release_${llvm_version_no_dot} libcxx"
289            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"
290        } else {
291            file rename ${workpath}/cfe-${version}.src ${worksrcpath}/tools/clang
292            file rename ${workpath}/compiler-rt-${version}.src ${worksrcpath}/projects/compiler-rt
293            file rename ${workpath}/libcxx-${version}.src ${worksrcpath}/projects/libcxx
294            file rename ${workpath}/clang-tools-extra-${version}.src ${worksrcpath}/tools/clang/tools/extra
295        }
296    }
297}
298
299post-patch {
300    if {${subport} eq "clang-${llvm_version}"} {
301        reinplace "s|@@PREFIX@@|${prefix}|g" \
302            ${worksrcpath}/projects/compiler-rt/make/platform/clang_darwin.mk \
303            ${worksrcpath}/projects/compiler-rt/make/platform/clang_macho_embedded.mk
304    }
305}
306
307post-destroot {
308    file mkdir ${destroot}${prefix}/share/doc
309    file rename ${destroot}${sub_prefix}/docs/llvm ${destroot}${prefix}/share/doc/${subport}
310
311    foreach bin [glob ${destroot}${sub_prefix}/bin/*] {
312        set bin_filename [string map "${sub_prefix} ${prefix}" ${bin}]-${suffix}
313        set exec_path [string map "${destroot}${sub_prefix} ${sub_prefix}" ${bin}]
314
315        xinstall -m 755 "${filespath}/llvm-bin" "${bin_filename}"
316        reinplace "s:EXEC_PATH:${exec_path}:" "${bin_filename}"
317    }
318
319    if {${subport} eq "llvm-${llvm_version}"} {
320        # r156389 (a5d2435409858728970202226d0bbbee508fe408) temporarilary removed llvm man pages
321        #foreach man [glob ${destroot}${sub_prefix}/share/man/man1/*.1] {
322        #    set basename [string map "${destroot}${sub_prefix}/share/man/man1/ {}" ${man}]
323        #    file rename ${man} ${destroot}${prefix}/share/man/man1/[string map ".1 -${suffix}.1" ${basename}]
324        #}
325    } elseif {${subport} eq "clang-${llvm_version}"} {
326        system "ditto ${worksrcpath}/projects/libcxx/include ${destroot}${sub_prefix}/lib/c++/v1"
327
328        # http://trac.macports.org/ticket/33207
329        ln -s ${prefix}/libexec/ld64/ld ${destroot}${sub_prefix}/bin/ld
330    }
331}
332
333if {${subport} eq "llvm-${llvm_version}"} {
334    variant polly description {Provide the polly polyhedral optimizer} {
335        depends_lib-append      port:gmp
336        if {${worksrcdir} eq "trunk"} {
337            # Polly likes using bleeding-edge isl.
338            depends_lib-append  port:isl-devel
339        } else {
340            depends_lib-append  path:lib/pkgconfig/isl.pc:isl
341        }
342    }
343
344    # Unless upstream reverts to their old OCaml detection mechanism,
345    # this variant will be broken until #46161 is resolved.
346    variant ocaml description {Enable generation of OCaml binding} {
347        depends_lib-append   port:ocaml
348
349        configure.args-delete --enable-bindings=none
350        configure.args-append --enable-bindings=ocaml
351
352        destroot.args-append  OVERRIDE_libdir=${sub_prefix}/lib
353    }
354} elseif {${subport} eq "clang-${llvm_version}"} {
355    variant analyzer description {Install clang static analyzer} {
356        depends_run-append port:perl5
357
358        post-patch {
359            reinplace "s|/usr/bin/env perl|${prefix}/bin/perl5|g" \
360                ${worksrcpath}/tools/clang/tools/scan-build/ccc-analyzer \
361                ${worksrcpath}/tools/clang/tools/scan-build/c++-analyzer \
362                ${worksrcpath}/tools/clang/tools/scan-build/scan-build
363            reinplace "s|/usr/bin/env python|${prefix}/bin/python2.7|g" \
364                ${worksrcpath}/tools/clang/tools/scan-build/set-xcode-analyzer \
365                ${worksrcpath}/tools/clang/tools/scan-view/scan-view
366        }
367
368        post-destroot {
369            file mkdir ${destroot}${sub_prefix}/libexec
370            file copy ${worksrcpath}/tools/clang/tools/scan-build ${destroot}${sub_prefix}/libexec/scan-build
371            file copy ${worksrcpath}/tools/clang/tools/scan-view ${destroot}${sub_prefix}/libexec/scan-view
372
373            file delete -force ${destroot}${sub_prefix}/libexec/scan-build/.svn
374            file delete -force ${destroot}${sub_prefix}/libexec/scan-view/.svn
375            file delete -force ${destroot}${sub_prefix}/libexec/scan-view/Resources/.svn
376
377            ln -s ${sub_prefix}/libexec/scan-build/scan-build ${destroot}${sub_prefix}/bin/scan-build
378            ln -s ${sub_prefix}/libexec/scan-view/scan-view ${destroot}${sub_prefix}/bin/scan-view
379            ln -s ${sub_prefix}/bin ${destroot}${sub_prefix}/libexec/scan-build/bin
380
381            xinstall -m 755 "${filespath}/llvm-bin" "${destroot}${prefix}/bin/scan-build-${suffix}"
382            reinplace "s:EXEC_PATH:${sub_prefix}/bin/scan-build:" "${destroot}${prefix}/bin/scan-build-${suffix}"
383
384            xinstall -m 755 "${filespath}/llvm-bin" "${destroot}${prefix}/bin/scan-view-${suffix}"
385            reinplace "s:EXEC_PATH:${sub_prefix}/bin/scan-view:" "${destroot}${prefix}/bin/scan-view-${suffix}"
386        }
387    }
388
389
390    post-patch {
391        reinplace "s|@CLANG_FORMAT_PATH@|${prefix}/bin/clang-format-${suffix}|g" \
392            ${worksrcpath}/tools/clang/tools/clang-format/clang-format-bbedit.applescript \
393            ${worksrcpath}/tools/clang/tools/clang-format/clang-format-diff.py            \
394            ${worksrcpath}/tools/clang/tools/clang-format/clang-format-sublime.py         \
395            ${worksrcpath}/tools/clang/tools/clang-format/clang-format.el                 \
396            ${worksrcpath}/tools/clang/tools/clang-format/clang-format.py
397    }
398
399    post-destroot {
400        file mkdir ${destroot}${sub_prefix}/libexec
401        file copy ${worksrcpath}/tools/clang/tools/clang-format ${destroot}${sub_prefix}/libexec/clang-format
402
403        file delete -force ${destroot}${sub_prefix}/libexec/clang-format/.svn
404        file delete -force ${destroot}${sub_prefix}/libexec/clang-format/Makefile
405        file delete -force ${destroot}${sub_prefix}/libexec/clang-format/Release+Debug+Asserts
406        file delete -force ${destroot}${sub_prefix}/libexec/clang-format/CMakeLists.txt
407        file delete -force ${destroot}${sub_prefix}/libexec/clang-format/ClangFormat.cpp
408    }
409
410    if {${os.platform} eq "darwin" && ${os.major} > 15} {
411        depends_build
412        depends_lib
413        depends_run
414        archive_sites
415        pre-fetch {
416            ui_error "${subport} is not supported on macOS Sierra or newer."
417            return -code error {unsupported platform}
418        }
419    }
420}
421
422livecheck.type          none
Note: See TracBrowser for help on using the repository browser.