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

Last change on this file was 153720, checked in by ryandesign@…, 14 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.6 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.5
8set llvm_version_no_dot 35
9name                    llvm-${llvm_version}
10revision                8
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
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            216817
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.5.2.src.tar.xz \
97                    rmd160  a6117b21f7f6ffe694ed152fba492015450b63f8 \
98                    sha256  44196156d5749eb4b4224fe471a29cc3984df92570a4a89fa859f7394fc0c575 \
99                    cfe-3.5.2.src.tar.xz \
100                    rmd160  72b746b57dbcdc4b1464de150148c2c0af99a750 \
101                    sha256  4feb575f74fb3a74b6245400460230141bf610f235ef3a25008cfe6137828620 \
102                    compiler-rt-3.5.2.src.tar.xz \
103                    rmd160  ce3a3efa32eb9a095c5e00708d3641f8ee15610b \
104                    sha256  542d7aadd21e7fe35bea0a7912bc965f08a1a566746cebcca76f96dcfeb74dc3 \
105                    libcxx-3.5.2.src.tar.xz \
106                    rmd160  0aab9e8ef62dd6a9e9f7d4ca620553fab40b00f8 \
107                    sha256  bbf1269de11f43fe766c7ff108ec076d16ec9ddd4e929eec87027eee48a13647 \
108                    clang-tools-extra-3.5.2.src.tar.xz \
109                    rmd160  8b8dc7835393863e5c22e8f7c35a61330e0ad425 \
110                    sha256  f21a374d74b194d8c984546266491b518859b5f12ed9abd49337b8060d3fc004 \
111                    polly-3.5.2.src.tar.xz \
112                    rmd160  ba98b905524b33a2489164e5fd8739b163eb0b19 \
113                    sha256  9d2a4bb8607e0879a0537165b9c2af7cfe4cc998627a62951106bffa1929dbe8
114
115patch.pre_args  -p1
116patchfiles    \
117        0001-MacPorts-Only-Update-install-targets-for-clang-subpo.patch \
118        0002-MacPorts-Only-Use-full-path-for-the-dylib-id-instead.patch \
119        0003-MacPorts-Only-Don-t-embed-the-deployment-target-in-t.patch \
120        0004-MacPorts-Only-Skip-checking-for-python-in-configure.patch \
121        0005-Set-the-Mach-O-CPU-Subtype-to-ppc7400-when-targeting.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-Fix-name-of-scan-view-executable-insid.patch \
128        1003-MacPorts-Only-Fix-libclang_rt-dylib-ids.patch \
129        1004-MacPorts-Only-Relocate-clang-resources-using-llvm-ve.patch \
130        1005-Call-powerpc-darwin-external-tools-with-arch-ppc.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-Do-not-build-a-separate-x86_64h-Haswell-slice-for-th.patch \
136        2003-Build-Darwin-libclang_rt-libraries-against-real-SDKs.patch \
137        2004-Clean-up-indentation-after-previous-change.patch \
138        2005-Update-CheckArches-to-fallback-on-Intel-ppc-if-ld-v-.patch \
139        2006-Fall-back-on-xcodebuild-sdk-when-xcrun-sdk-is-not-su.patch \
140        2007-On-darwin-build-ppc-slices-of-the-compiler-runtime-i.patch \
141        3001-buildit-build-fix-for-Leopard.patch \
142        3002-buildit-Set-compatibility-version-to-RC_ProjectSourc.patch \
143        3003-Fix-local-and-iterator-when-building-with-Lion-and-n.patch \
144        3004-Fix-missing-long-long-math-prototypes-when-using-the.patch \
145        3005-implement-atomic-using-mutex-lock_guard-for-64b-ops-.patch \
146        compiler_rt-toolchain.patch
147
148    # I'm not sure if we need to delete this.  It seems to build fine with it
149    # present, but we used to explicitly only use this patch for the llvm subport.
150    patchfiles-delete \
151        0004-MacPorts-Only-Skip-checking-for-python-in-configure.patch
152
153    # Introduces a failure during build (-arch ?? passed to ld), to be investigated:
154    patchfiles-delete \
155        1005-Call-powerpc-darwin-external-tools-with-arch-ppc.patch
156
157    if {![variant_isset arm_runtime]} {
158        # Alternate fix for #33272.
159        patchfiles-append   disable-arm-runtime.patch
160    }
161
162    build.target        clang-only
163    destroot.target     install-clang
164}
165
166build.env-append        VERBOSE=1 \
167                        REQUIRES_RTTI=1 \
168                        LLVM_SUBMIT_VERSION=3 \
169                        LLVM_SUBMIT_SUBVERSION=7.1
170destroot.env-append     VERBOSE=1 \
171                        REQUIRES_RTTI=1 \
172                        LLVM_SUBMIT_VERSION=3 \
173                        LLVM_SUBMIT_SUBVERSION=7.1
174
175configure.dir           ${workpath}/build
176build.dir               ${configure.dir}
177
178configure.cmd           ${worksrcpath}/configure
179configure.pre_args-delete --prefix=${prefix}
180configure.args          --enable-bindings=none --enable-libffi --enable-shared --enable-jit \
181                        --enable-optimized --disable-profiling --enable-pic \
182                        --enable-debug-symbols --disable-debug-runtime \
183                        --prefix="${sub_prefix}" --disable-assertions
184
185if {${subport} eq "llvm-${llvm_version}"} {
186    select.group        llvm
187    select.file         ${filespath}/mp-${subport}
188} elseif {${subport} eq "clang-${llvm_version}"} {
189    select.group        clang
190    select.file         ${filespath}/mp-${subport}
191
192    configure.args-append --with-python=${prefix}/bin/python2.7
193}
194
195# llvm-3.5 and later requires a C++11 runtime
196# XCode 4.3's clang (318.x) fails per https://trac.macports.org/ticket/44161
197# XCode 4.5's clang (421.11.66) fails due to http://llvm.org/bugs/show_bug.cgi?id=20184
198# Xcode 4.6.x's clang (425.0.28) works, assuming 425.0.24 from 4.6.0 works too
199compiler.blacklist *gcc* {clang < 425.0.24}
200
201if {${subport} eq "clang-${llvm_version}"} {
202    # Don't self-host.  We may have issues if we have a slightly newer llvm version that
203    # is not binary compatible with the older clang version we're trying to use.
204
205    compiler.blacklist-append macports-clang-${llvm_version}
206}
207
208# blacklist current and future versions if they're not available in order to
209# help break potential dependency cycles.
210foreach ver {3.5 3.6 3.7 3.8 3.9 devel} {
211    if {![file exists ${prefix}/bin/clang-mp-${ver}]} {
212        compiler.blacklist-append macports-clang-${ver}
213    }
214}
215
216platform darwin {
217    # Note that we are forcing this choice.  This means that anything linking
218    # against llvm-3.5 needs to also be using libc++.  This is possibly
219    # problematic, but luckily there is just a limited set of such dependents.
220
221    configure.cxx_stdlib libc++
222    depends_lib-append port:libcxx
223    supported_archs i386 x86_64
224
225    pre-fetch {
226        if {![file exists /usr/lib/libc++.dylib]} {
227            ui_error "$name requires a C++11 runtime, which your configuration does not allow"
228            error "unsupported configuration"
229        }
230    }
231}
232
233variant universal {
234    build.env-append \
235        UNIVERSAL=1 \
236        UNIVERSAL_ARCH="[get_canonical_archs]"
237    destroot.env-append \
238        UNIVERSAL=1 \
239        UNIVERSAL_ARCH="[get_canonical_archs]"
240
241    post-extract {
242        # workaround a bug in Apple's shipped gcc driver-driver, patched in
243        # ours with driverdriver-num_infiles.patch
244        if {${configure.compiler} eq "gcc-4.0" ||
245            ${configure.compiler} eq "gcc-4.2" ||
246            ${configure.compiler} eq "llvm-gcc-4.2"} {
247            system "echo \"static int ___ignoreme;\" > ${worksrcpath}/tools/llvm-shlib/ignore.c"
248        }
249    }
250}
251
252variant assertions description "Enable assertions for error detection (has performance impacts, especially on JIT)" {
253    configure.args-delete --disable-assertions
254    configure.args-append --enable-assertions
255}
256
257platform darwin {
258    if {${build_arch} eq "i386"} {
259        configure.pre_args-append --build=i686-apple-darwin${os.major}
260    } elseif {${build_arch} eq "ppc"} {
261        configure.pre_args-append --build=powerpc-apple-darwin${os.major}
262    } elseif {${build_arch} eq "ppc64"} {
263        configure.pre_args-append --build=powerpc64-apple-darwin${os.major}
264    } else {
265        configure.pre_args-append --build=${build_arch}-apple-darwin${os.major}
266    }
267
268    if {[string match "*ppc*" [get_canonical_archs]]} {
269        # http://trac.macports.org/ticket/33987
270        configure.args-append --with-optimize-option=-Os
271        configure.optflags    -Os
272    }
273
274    if {${subport} eq "clang-${llvm_version}" && ${os.major} <= 9} {
275        patchfiles-append leopard-no-asan.patch leopard-no-blocks.patch
276    }
277
278    # TODO: The llvm build system sets a 10.1 deployment target on Yosemite
279    if {[vercmp ${macosx_deployment_target} 10.10] >= 0} {
280        macosx_deployment_target 10.9
281    }
282}
283
284post-extract {
285    if {${subport} eq "llvm-${llvm_version}"} {
286        if {[variant_isset polly]} {
287            if {${worksrcdir} eq "trunk"} {
288                system "cd ${worksrcpath}/tools && svn co -r ${svn.revision} http://llvm.org/svn/llvm-project/polly/trunk polly"
289            } elseif {${worksrcdir} eq "release_${llvm_version_no_dot}" } {
290                system "cd ${worksrcpath}/tools && svn co -r ${svn.revision} http://llvm.org/svn/llvm-project/polly/branches/release_${llvm_version_no_dot} polly"
291            } else {
292                file rename ${workpath}/polly-${version}.src ${worksrcpath}/tools/polly
293            }
294        }
295    } elseif {${subport} eq "clang-${llvm_version}"} {
296        if {${worksrcdir} eq "trunk"} {
297            system "cd ${worksrcpath}/tools && svn co -r ${svn.revision} http://llvm.org/svn/llvm-project/cfe/trunk clang"
298            system "cd ${worksrcpath}/projects && svn co -r ${compiler_rt_rev} http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt"
299            system "cd ${worksrcpath}/projects && svn co -r ${libcxx_rev} http://llvm.org/svn/llvm-project/libcxx/trunk libcxx"
300            system "cd ${worksrcpath}/tools/clang/tools && svn co -r ${clang-modernize_rev} http://llvm.org/svn/llvm-project/clang-tools-extra/trunk extra"
301        } elseif {${worksrcdir} eq "release_${llvm_version_no_dot}" } {
302            system "cd ${worksrcpath}/tools && svn co -r ${svn.revision} http://llvm.org/svn/llvm-project/cfe/branches/release_${llvm_version_no_dot} clang"
303            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"
304            system "cd ${worksrcpath}/projects && svn co -r ${libcxx_rev} http://llvm.org/svn/llvm-project/libcxx/branches/release_${llvm_version_no_dot} libcxx"
305            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"
306        } else {
307            file rename ${workpath}/cfe-${version}.src ${worksrcpath}/tools/clang
308            file rename ${workpath}/compiler-rt-${version}.src ${worksrcpath}/projects/compiler-rt
309            file rename ${workpath}/libcxx-${version}.src ${worksrcpath}/projects/libcxx
310            file rename ${workpath}/clang-tools-extra-${version}.src ${worksrcpath}/tools/clang/tools/extra
311        }
312    }
313}
314
315post-patch {
316    if {${subport} eq "clang-${llvm_version}"} {
317        reinplace "s|@@PREFIX@@|${prefix}|g" \
318            ${worksrcpath}/projects/compiler-rt/make/platform/clang_darwin.mk \
319            ${worksrcpath}/projects/compiler-rt/make/platform/clang_macho_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        depends_lib-append \
352            port:gmp \
353            path:lib/pkgconfig/isl.pc:isl \
354            path:lib/pkgconfig/cloog-isl.pc:cloog
355    }
356
357    variant ocaml description {Enable generation of OCaml binding} {
358        depends_lib-append   port:ocaml
359
360        configure.args-delete --enable-bindings=none
361        configure.args-append --enable-bindings=ocaml
362
363        destroot.args-append  OVERRIDE_libdir=${sub_prefix}/lib
364    }
365} elseif {${subport} eq "clang-${llvm_version}"} {
366    variant arm_runtime description {Build and install the arm runtime for iOS development (requires iOS SDK)} {}
367
368    # The iOS SDK was shipped with all Xcode releases after 4.0
369    if {[info exists xcodeversion] && [vercmp "4.0" ${xcodeversion}] <= 0} {
370       default_variants-append +arm_runtime
371    }
372
373    variant analyzer description {Install clang static analyzer} {
374        depends_run-append port:perl5
375
376        post-patch {
377            reinplace "s|/usr/bin/env perl|${prefix}/bin/perl5|g" \
378                ${worksrcpath}/tools/clang/tools/scan-build/ccc-analyzer \
379                ${worksrcpath}/tools/clang/tools/scan-build/c++-analyzer \
380                ${worksrcpath}/tools/clang/tools/scan-build/scan-build
381            reinplace "s|/usr/bin/env python|${prefix}/bin/python2.7|g" \
382                ${worksrcpath}/tools/clang/tools/scan-build/set-xcode-analyzer \
383                ${worksrcpath}/tools/clang/tools/scan-view/scan-view
384        }
385
386        post-destroot {
387            file mkdir ${destroot}${sub_prefix}/libexec
388            file copy ${worksrcpath}/tools/clang/tools/scan-build ${destroot}${sub_prefix}/libexec/scan-build
389            file copy ${worksrcpath}/tools/clang/tools/scan-view ${destroot}${sub_prefix}/libexec/scan-view
390
391            file delete -force ${destroot}${sub_prefix}/libexec/scan-build/.svn
392            file delete -force ${destroot}${sub_prefix}/libexec/scan-view/.svn
393            file delete -force ${destroot}${sub_prefix}/libexec/scan-view/Resources/.svn
394
395            ln -s ${sub_prefix}/libexec/scan-build/scan-build ${destroot}${sub_prefix}/bin/scan-build
396            ln -s ${sub_prefix}/libexec/scan-view/scan-view ${destroot}${sub_prefix}/bin/scan-view
397            ln -s ${sub_prefix}/bin ${destroot}${sub_prefix}/libexec/scan-build/bin
398
399            xinstall -m 755 "${filespath}/llvm-bin" "${destroot}${prefix}/bin/scan-build-${suffix}"
400            reinplace "s:EXEC_PATH:${sub_prefix}/bin/scan-build:" "${destroot}${prefix}/bin/scan-build-${suffix}"
401
402            xinstall -m 755 "${filespath}/llvm-bin" "${destroot}${prefix}/bin/scan-view-${suffix}"
403            reinplace "s:EXEC_PATH:${sub_prefix}/bin/scan-view:" "${destroot}${prefix}/bin/scan-view-${suffix}"
404        }
405    }
406
407
408    post-patch {
409        reinplace "s|@CLANG_FORMAT_PATH@|${prefix}/bin/clang-format-${suffix}|g" \
410            ${worksrcpath}/tools/clang/tools/clang-format/clang-format-bbedit.applescript \
411            ${worksrcpath}/tools/clang/tools/clang-format/clang-format-diff.py            \
412            ${worksrcpath}/tools/clang/tools/clang-format/clang-format-sublime.py         \
413            ${worksrcpath}/tools/clang/tools/clang-format/clang-format.el                 \
414            ${worksrcpath}/tools/clang/tools/clang-format/clang-format.py
415    }
416
417    post-destroot {
418        file mkdir ${destroot}${sub_prefix}/libexec
419        file copy ${worksrcpath}/tools/clang/tools/clang-format ${destroot}${sub_prefix}/libexec/clang-format
420
421        file delete -force ${destroot}${sub_prefix}/libexec/clang-format/.svn
422        file delete -force ${destroot}${sub_prefix}/libexec/clang-format/Makefile
423        file delete -force ${destroot}${sub_prefix}/libexec/clang-format/Release+Debug+Asserts
424        file delete -force ${destroot}${sub_prefix}/libexec/clang-format/CMakeLists.txt
425        file delete -force ${destroot}${sub_prefix}/libexec/clang-format/ClangFormat.cpp
426    }
427
428    if {${os.platform} eq "darwin" && ${os.major} > 15} {
429        depends_build
430        depends_lib
431        depends_run
432        archive_sites
433        pre-fetch {
434            ui_error "${subport} is not supported on macOS Sierra or newer."
435            return -code error {unsupported platform}
436        }
437    }
438}
439
440livecheck.type          none
Note: See TracBrowser for help on using the repository browser.