source: trunk/dports/lang/llvm-3.9/Portfile @ 147848

Last change on this file since 147848 was 147848, checked in by jeremyhu@…, 4 years ago

llvm-3.9: Bump to r266579

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 18.7 KB
Line 
1# $Id: Portfile 147848 2016-04-18 02:10:58Z jeremyhu@macports.org $
2
3# TODO:
4#  * Update llvm_select and clang_select (#49844)
5#  * Update clang subport to build against installed llvm
6
7PortSystem              1.0
8PortGroup select        1.0
9PortGroup compiler_blacklist_versions 1.0
10PortGroup active_variants 1.1
11PortGroup cmake         1.0
12
13set llvm_version        3.9
14set llvm_version_no_dot 39
15name                    llvm-${llvm_version}
16subport                 clang-${llvm_version} {}
17set suffix              mp-${llvm_version}
18set sub_prefix          ${prefix}/libexec/llvm-${llvm_version}
19dist_subdir             llvm
20categories              lang
21platforms               darwin
22license                 NCSA
23maintainers             jeremyhu larryv
24
25if {${subport} eq "llvm-${llvm_version}"} {
26    homepage            http://llvm.org/
27    description         llvm is a next generation compiler infrastructure
28    long_description    The LLVM Core libraries provide a modern source- and \
29                        target-independent optimizer, along with code \
30                        generation support for many popular CPUs (as well as \
31                        some less common ones!) These libraries are built \
32                        around a well specified code representation known as \
33                        the LLVM intermediate representation ("LLVM IR").
34
35    depends_lib         port:libedit port:libffi port:ncurses port:zlib
36    depends_run         bin:perl:perl5 port:llvm_select
37
38    # 3.2.6's install_name_tool doesn't support load commands we might see with newer clang+ld64
39    # 4.3 is just a guess here and should be updated if there are additional reports with other Xcode versions
40    if {[vercmp $xcodeversion 4.3] < 0 && [string match "*macports*" ${configure.compiler}]} {
41        depends_build-append port:cctools
42    }
43} elseif {${subport} eq "clang-${llvm_version}"} {
44    homepage            http://clang.llvm.org/
45    description         C, C++, Objective C and Objective C++ compiler
46    long_description    Clang is an "LLVM native" C/C++/Objective-C compiler, \
47                        which aims to deliver amazingly fast compiles (e.g. \
48                        about 3x faster than GCC when compiling Objective-C \
49                        code in a debug configuration), extremely useful error \
50                        and warning messages and to provide a platform for \
51                        building great source level tools. The included Clang \
52                        Static Analyzer is a tool that automatically finds bugs in \
53                        your code, and is a great example of the sort of tool \
54                        that can be built using the Clang frontend as a \
55                        library to parse C/C++ code.
56
57    depends_lib         port:libxml2 port:libomp port:llvm-${llvm_version} port:python27
58    depends_run         port:clang_select port:ld64
59    depends_extract     bin:svn:subversion
60    depends_build-append port:cctools
61    depends_skip_archcheck-append cctools ld64 subversion
62
63    # Clang doesn't actually use any of these, but the LLVM makefile
64    # system overlinks its binaries. Remove (or convert to build deps?)
65    # after #46040 is resolved.
66    depends_lib-append  port:libedit port:libffi port:ncurses port:zlib
67
68    default_variants    +analyzer
69}
70
71fetch.type              svn
72svn.revision            266579
73
74set compiler_rt_rev     ${svn.revision}
75set libcxx_rev          ${svn.revision}
76set clang-modernize_rev ${svn.revision}
77version                 ${llvm_version}-r${svn.revision}
78worksrcdir              trunk
79svn.url                 https://llvm.org/svn/llvm-project/llvm/trunk
80#worksrcdir              release_${llvm_version_no_dot}
81#svn.url                 https://llvm.org/svn/llvm-project/llvm/branches/release_${llvm_version_no_dot}
82default_variants-append +assertions
83default_variants-append +debug
84
85#version                 ${llvm_version}.0
86#epoch                   1
87#master_sites            http://llvm.org/releases/${version}
88#use_xz                  yes
89#extract.suffix          .tar.xz
90#distfiles               llvm-${version}.src${extract.suffix}
91#worksrcdir              llvm-${version}.src
92
93if {${distfiles} ne ""} {
94    if {${subport} eq "llvm-${llvm_version}"} {
95        if {[variant_isset polly]} {
96            distfiles-append     polly-${version}.src${extract.suffix}
97        }
98    } elseif {${subport} eq "clang-${llvm_version}"} {
99        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}
100    }
101}
102
103patch.pre_args  -p1
104patchfiles \
105        0001-Set-the-Mach-O-CPU-Subtype-to-ppc7400-when-targeting.patch \
106        0002-Define-EXC_MASK_CRASH-and-MACH_EXCEPTION_CODES-if-th.patch \
107        0003-MacPorts-Only-Don-t-embed-the-deployment-target-in-t.patch \
108        0004-Remove-override-of-raise-abort-and-__assert_rtn.patch
109
110if {${subport} eq "clang-${llvm_version}"} {
111    patchfiles-append \
112        1001-MacPorts-Only-Prepare-clang-format-for-replacement-w.patch \
113        1002-MacPorts-Only-Fix-name-of-scan-view-executable-insid.patch \
114        1003-Default-to-ppc7400-for-OSX-10.5.patch \
115        1004-Only-call-setpriority-PRIO_DARWIN_THREAD-0-PRIO_DARW.patch \
116        1005-Default-to-fragile-ObjC-runtime-when-targeting-darwi.patch \
117        2001-MacPorts-Only-Comment-out-SL-cctools-workaround.patch \
118        2002-Update-CheckArches-to-fallback-on-Intel-ppc-if-ld-v-.patch \
119        2003-Fall-back-on-xcodebuild-sdk-when-xcrun-sdk-is-not-su.patch \
120        2004-On-darwin-build-ppc-slices-of-the-compiler-runtime-i.patch \
121        2005-MacPorts-Only-Don-t-build-x86_64h-slice-of-compiler-.patch \
122        2006-MacPorts-Only-Fix-regression-introduced-when-fixing-.patch \
123        2007-MacPorts-Only-Don-t-check-for-the-macosx.internal-SD.patch \
124        3001-buildit-build-fix-for-Leopard.patch \
125        3002-buildit-Set-compatibility-version-to-RC_ProjectSourc.patch \
126        3003-Fix-local-and-iterator-when-building-with-Lion-and-n.patch \
127        3004-Fix-missing-long-long-math-prototypes-when-using-the.patch \
128        3005-implement-atomic-using-mutex-lock_guard-for-64b-ops-.patch \
129        compiler_rt-toolchain.patch \
130        openmp-locations.patch
131
132    # https://llvm.org/bugs/show_bug.cgi?id=25681
133    if {${worksrcdir} eq "trunk" || ${worksrcdir} eq "release_${llvm_version_no_dot}"} {
134        # Cannot set cppflags due to https://cmake.org/Bug/view.php?id=12928
135        # Cannot set cxxflags due to https://llvm.org/bugs/show_bug.cgi?id=25904
136        #configure.cxxflags-append -DSVN_REVISION='"${svn.revision}"'
137
138        post-patch {
139            reinplace "1 i \\                             
140                #define SVN_REVISION \"${svn.revision}\"
141            " ${worksrcpath}/tools/clang/lib/Basic/Version.cpp
142        }
143    }
144}
145
146configure.post_args         ../${worksrcdir}
147default configure.dir       {${workpath}/build}
148default build.dir           {${workpath}/build}
149
150# https://llvm.org/bugs/show_bug.cgi?id=25664
151configure.ldflags-append    -Wl,-rpath,@loader_path
152
153configure.args-append \
154    -DLLVM_LINK_LLVM_DYLIB=ON \
155    -DCMAKE_INSTALL_PREFIX="${sub_prefix}" \
156    -DLLVM_ENABLE_ASSERTIONS=OFF \
157    -DLLVM_ENABLE_RTTI=ON \
158    -DLLVM_INCLUDE_TESTS=OFF \
159    -DLLVM_INCLUDE_EXAMPLES=OFF \
160    -DLLVM_ENABLE_FFI=ON \
161    -DLLVM_BINDINGS_LIST=none \
162    -DFFI_INCLUDE_DIR=${prefix}/include \
163    -DFFI_LIBRARY_DIR=${prefix}/lib
164
165if {${subport} eq "llvm-${llvm_version}"} {
166    select.group        llvm
167    select.file         ${filespath}/mp-${subport}
168} elseif {${subport} eq "clang-${llvm_version}"} {
169    select.group        clang
170    select.file         ${filespath}/mp-${subport}
171
172    configure.args-append \
173        -DCLANG_INCLUDE_TESTS=OFF \
174        -DCLANG_ENABLE_STATIC_ANALYZER=OFF \
175        -DLLVM_BUILD_RUNTIME=ON \
176        -DLIBCXX_INSTALL_LIBRARY=OFF
177}
178
179# llvm-3.5 and later requires a C++11 runtime
180# XCode 4.3's clang (318.x) fails per https://trac.macports.org/ticket/44161
181# XCode 4.5's clang (421.11.66) fails due to http://llvm.org/bugs/show_bug.cgi?id=20184
182# Xcode 4.6.3's clang (425.0.28) fails due to http://trac.macports.org/ticket/46897
183# Xcode 5.1.0's clang (503.0.35) fails due to https://llvm.org/bugs/show_bug.cgi?id=25673
184# Xcode 6.2's clang (600.0.57) fails due to https://llvm.org/bugs/show_bug.cgi?id=25753
185# clang older than 3.5 fail due to https://llvm.org/bugs/show_bug.cgi?id=25753
186compiler.blacklist *gcc* {clang < 602} macports-clang-3.3 macports-clang-3.4
187
188# Remove this when loosening the blacklist above or when a newer base is released
189compiler.fallback-append macports-clang-3.7 macports-clang-3.6 macports-clang-3.5
190
191if {${subport} eq "clang-${llvm_version}"} {
192    # Don't self-host.  We may have issues if we have a slightly newer llvm version that
193    # is not binary compatible with the older clang version we're trying to use.
194
195    compiler.blacklist-append macports-clang-${llvm_version}
196}
197
198# blacklist current and future versions if they're not available in order to
199# help break potential dependency cycles.
200foreach ver {3.8} {
201    if {![file exists ${prefix}/bin/clang-mp-${ver}]} {
202        compiler.blacklist-append macports-clang-${ver}
203    }
204}
205
206platform darwin {
207    # Note that we are forcing this choice.  This means that anything linking
208    # against llvm-3.5 needs to also be using libc++.  This is possibly
209    # problematic, but luckily there is just a limited set of such dependents.
210
211    configure.cxx_stdlib libc++
212    depends_lib-append port:libcxx
213    supported_archs i386 x86_64
214
215    pre-fetch {
216        if {![file exists /usr/lib/libc++.dylib]} {
217            ui_error "$name requires a C++11 runtime, which your configuration does not allow"
218            error "unsupported configuration"
219        }
220    }
221}
222
223variant universal {
224    post-extract {
225        # workaround a bug in Apple's shipped gcc driver-driver, patched in
226        # ours with driverdriver-num_infiles.patch
227        if {${configure.compiler} eq "gcc-4.0" ||
228            ${configure.compiler} eq "gcc-4.2" ||
229            ${configure.compiler} eq "llvm-gcc-4.2"} {
230            system "echo \"static int ___ignoreme;\" > ${worksrcpath}/tools/llvm-shlib/ignore.c"
231        }
232    }
233}
234
235variant assertions description "Enable assertions for error detection (has performance impacts, especially on JIT)" {
236    configure.args-delete -DLLVM_ENABLE_ASSERTIONS=OFF
237    configure.args-append -DLLVM_ENABLE_ASSERTIONS=ON
238}
239
240platform darwin {
241    if {[string match "*ppc*" [get_canonical_archs]]} {
242        # http://trac.macports.org/ticket/33987
243        configure.optflags    -Os
244    }
245
246    if {${subport} eq "clang-${llvm_version}" && [vercmp $xcodeversion 5.0] < 0} {
247        # https://llvm.org/bugs/show_bug.cgi?id=13671
248        patchfiles-append leopard-no-asan.patch
249        configure.args-append -DCOMPILER_RT_HAS_SANITIZER_COMMON=NO
250    }
251
252    if {${subport} eq "clang-${llvm_version}" && ${os.major} <= 9} {
253        patchfiles-append leopard-no-blocks.patch
254    }
255
256    if {${os.major} < 11} {
257        # Proxy for eliminating the dependency on native TLS
258        # http://trac.macports.org/ticket/46887
259        configure.args-append -DLLVM_ENABLE_BACKTRACES=OFF
260
261        # https://llvm.org/bugs/show_bug.cgi?id=25680
262        configure.cxxflags-append -U__STRICT_ANSI__
263    }
264
265    # https://llvm.org/bugs/show_bug.cgi?id=25674
266    configure.cxxflags-append -std=c++11
267}
268
269post-extract {
270    # Get HTTP proxy arguments if required, assuming we can use the same proxy for all repositories
271    set proxy_args [portfetch::svn_proxy_args http://llvm.org/svn/llvm-project/cfe/trunk]
272    if {${subport} eq "llvm-${llvm_version}"} {
273        if {[variant_isset polly]} {
274            if {${worksrcdir} eq "trunk"} {
275                system -W ${worksrcpath}/tools "svn ${proxy_args} co -r ${svn.revision} http://llvm.org/svn/llvm-project/polly/trunk polly"
276            } elseif {${worksrcdir} eq "release_${llvm_version_no_dot}" } {
277                system -W ${worksrcpath}/tools "svn ${proxy_args} co -r ${svn.revision} http://llvm.org/svn/llvm-project/polly/branches/release_${llvm_version_no_dot} polly"
278            } else {
279                file rename ${workpath}/polly-${version}.src ${worksrcpath}/tools/polly
280            }
281        }
282    } elseif {${subport} eq "clang-${llvm_version}"} {
283        if {${worksrcdir} eq "trunk"} {
284            system -W ${worksrcpath}/tools "svn ${proxy_args} co -r ${svn.revision} http://llvm.org/svn/llvm-project/cfe/trunk clang"
285            system -W ${worksrcpath}/projects "svn ${proxy_args} co -r ${compiler_rt_rev} http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt"
286            system -W ${worksrcpath}/projects "svn ${proxy_args} co -r ${libcxx_rev} http://llvm.org/svn/llvm-project/libcxx/trunk libcxx"
287            system -W ${worksrcpath}/tools/clang/tools "svn ${proxy_args} co -r ${clang-modernize_rev} http://llvm.org/svn/llvm-project/clang-tools-extra/trunk extra"
288        } elseif {${worksrcdir} eq "release_${llvm_version_no_dot}" } {
289            system -W ${worksrcpath}/tools "svn ${proxy_args} co -r ${svn.revision} http://llvm.org/svn/llvm-project/cfe/branches/release_${llvm_version_no_dot} clang"
290            system -W ${worksrcpath}/projects "svn ${proxy_args} co -r ${compiler_rt_rev} http://llvm.org/svn/llvm-project/compiler-rt/branches/release_${llvm_version_no_dot} compiler-rt"
291            system -W ${worksrcpath}/projects "svn ${proxy_args} co -r ${libcxx_rev} http://llvm.org/svn/llvm-project/libcxx/branches/release_${llvm_version_no_dot} libcxx"
292            system -W ${worksrcpath}/tools/clang/tools "svn ${proxy_args} co -r ${clang-modernize_rev} http://llvm.org/svn/llvm-project/clang-tools-extra/branches/release_${llvm_version_no_dot} extra"
293        } else {
294            file rename ${workpath}/cfe-${version}.src ${worksrcpath}/tools/clang
295            file rename ${workpath}/compiler-rt-${version}.src ${worksrcpath}/projects/compiler-rt
296            file rename ${workpath}/libcxx-${version}.src ${worksrcpath}/projects/libcxx
297            file rename ${workpath}/clang-tools-extra-${version}.src ${worksrcpath}/tools/clang/tools/extra
298        }
299    }
300}
301
302if {${subport} eq "clang-${llvm_version}"} {
303    destroot {
304        system "cd ${destroot.dir}/tools/clang && ${destroot.cmd} ${destroot.pre_args} ${destroot.target} ${destroot.post_args}"
305        system "cd ${destroot.dir}/projects/compiler-rt && ${destroot.cmd} ${destroot.pre_args} ${destroot.target} ${destroot.post_args}"
306        system "cd ${destroot.dir}/projects/libcxx && ${destroot.cmd} ${destroot.pre_args} ${destroot.target} ${destroot.post_args}"
307
308        delete ${destroot}${sub_prefix}/bin/clang
309        file rename ${destroot}${sub_prefix}/bin/clang-${llvm_version} ${destroot}${sub_prefix}/bin/clang
310    }
311}
312
313post-destroot {
314    foreach bin [glob ${destroot}${sub_prefix}/bin/*] {
315        set bin_filename [string map "${sub_prefix} ${prefix}" ${bin}]-${suffix}
316        set exec_path [string map "${destroot}${sub_prefix} ${sub_prefix}" ${bin}]
317
318        xinstall -m 755 "${filespath}/llvm-bin" "${bin_filename}"
319        reinplace "s:EXEC_PATH:${exec_path}:" "${bin_filename}"
320    }
321
322    if {${subport} eq "llvm-${llvm_version}"} {
323        # r156389 (a5d2435409858728970202226d0bbbee508fe408) temporarilary removed llvm man pages
324        #foreach man [glob ${destroot}${sub_prefix}/share/man/man1/*.1] {
325        #    set basename [string map "${destroot}${sub_prefix}/share/man/man1/ {}" ${man}]
326        #    file rename ${man} ${destroot}${prefix}/share/man/man1/[string map ".1 -${suffix}.1" ${basename}]
327        #}
328
329        # https://llvm.org/bugs/show_bug.cgi?id=19465
330        if {[variant_isset polly]} {
331            ln -s LLVMPolly.so ${destroot}${sub_prefix}/lib/LLVMPolly.dylib
332        }
333    } elseif {${subport} eq "clang-${llvm_version}"} {
334        system "ditto ${worksrcpath}/projects/libcxx/include ${destroot}${sub_prefix}/lib/c++/v1"
335
336        # http://trac.macports.org/ticket/33207
337        ln -s ${prefix}/libexec/ld64/ld ${destroot}${sub_prefix}/bin/ld
338    }
339}
340
341if {${subport} eq "llvm-${llvm_version}"} {
342    variant polly description {Provide the polly polyhedral optimizer} {}
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 -DLLVM_BINDINGS_LIST=none
350        configure.args-append -DLLVM_BINDINGS_LIST=ocaml
351
352        destroot.args-append  OVERRIDE_libdir=${sub_prefix}/lib
353    }
354} elseif {${subport} eq "clang-${llvm_version}"} {
355    if {[variant_isset assertions]} {
356        # Need to match llvm +-assertions
357        require_active_variants port:llvm-${llvm_version} assertions
358    } else {
359        # Need to match llvm +-assertions
360        require_active_variants port:llvm-${llvm_version} {} assertions
361    }
362
363    variant analyzer description {Install clang static analyzer} {
364        configure.args-delete \
365            -DCLANG_ENABLE_STATIC_ANALYZER=OFF
366        configure.args-append \
367            -DCLANG_ENABLE_STATIC_ANALYZER=ON
368
369        depends_run-append port:perl5
370
371        post-patch {
372            reinplace "s|/usr/bin/env perl|${prefix}/bin/perl5|g" \
373                ${worksrcpath}/tools/clang/tools/scan-build/libexec/ccc-analyzer \
374                ${worksrcpath}/tools/clang/tools/scan-build/libexec/c++-analyzer \
375                ${worksrcpath}/tools/clang/tools/scan-build/bin/scan-build
376            reinplace "s|/usr/bin/env python|${prefix}/bin/python2.7|g" \
377                ${worksrcpath}/tools/clang/tools/scan-build/bin/set-xcode-analyzer \
378                ${worksrcpath}/tools/clang/tools/scan-view/bin/scan-view
379        }
380    }
381
382    post-patch {
383        reinplace "s|@@PREFIX@@|${prefix}|" \
384            ${worksrcpath}/tools/clang/lib/Driver/Tools.cpp
385
386        reinplace "s|@CLANG_FORMAT_PATH@|${prefix}/bin/clang-format-${suffix}|g" \
387            ${worksrcpath}/tools/clang/tools/clang-format/clang-format-bbedit.applescript \
388            ${worksrcpath}/tools/clang/tools/clang-format/clang-format-diff.py            \
389            ${worksrcpath}/tools/clang/tools/clang-format/clang-format-sublime.py         \
390            ${worksrcpath}/tools/clang/tools/clang-format/clang-format.el                 \
391            ${worksrcpath}/tools/clang/tools/clang-format/clang-format.py
392    }
393
394    post-destroot {
395        file mkdir ${destroot}${sub_prefix}/libexec
396        file copy ${worksrcpath}/tools/clang/tools/clang-format ${destroot}${sub_prefix}/libexec/clang-format
397
398        file delete -force ${destroot}${sub_prefix}/libexec/clang-format/.svn
399        file delete -force ${destroot}${sub_prefix}/libexec/clang-format/Makefile
400        file delete -force ${destroot}${sub_prefix}/libexec/clang-format/Release+Debug+Asserts
401        file delete -force ${destroot}${sub_prefix}/libexec/clang-format/CMakeLists.txt
402        file delete -force ${destroot}${sub_prefix}/libexec/clang-format/ClangFormat.cpp
403    }
404}
405
406livecheck.type          none
Note: See TracBrowser for help on using the repository browser.