source: trunk/dports/devel/ld64/Portfile

Last change on this file was 153814, checked in by jeremyhu@…, 11 months ago

cctools, ld64: Default to +llvm34 on Lion (cf #46897)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 16.3 KB
Line 
1# $Id: Portfile 153814 2016-10-12 09:20:28Z ryandesign@macports.org $
2
3PortSystem              1.0
4PortGroup               compiler_blacklist_versions 1.0
5
6name                    ld64
7epoch                   2
8version                 2
9set dyld_version        360.18
10categories              devel
11platforms               darwin
12maintainers             jeremyhu
13homepage                http://opensource.apple.com/source/${name}/
14master_sites            http://opensource.apple.com/tarballs/${name} \
15                        http://opensource.apple.com/tarballs/dyld
16license                 APSL-2
17installs_libs           no
18description             ld64 is the new mach-o linker
19long_description        ld64 combines several object files and libraries, \
20                        resolves references, and produces an ouput file.
21
22checksums           ld64-97-standalone-libunwind-headers.patch \
23                    rmd160  f6da71e097aa61b1055b3fdc12cd39aafed5f492 \
24                    sha256  370d02757ea628b5dd145c099e42fc4eb88cc09cf459a59e32d14bbc9b4a105e \
25                    dyld-360.18.tar.gz \
26                    rmd160  aeb3144549ec276b028b979680f5056da4d63747 \
27                    sha256  a5bec8c2e3bded111aec7e447b35c110038e822f95e11e55b9a4d331fbaeff08 \
28                    ld64-97.17.tar.gz \
29                    rmd160  d52df7d7f741c8bedd29cbac73dbb9db992b4795 \
30                    sha256  02bd46af0809eaa415d096d7d41c3e8e7d80f7d8d181840866fb87f036b4e089 \
31                    ld64-127.2.tar.gz \
32                    rmd160  8ee709341549a1944732daef6ebab7ef1acfcc6e \
33                    sha256  97b75547b2bd761306ab3e15ae297f01e7ab9760b922bc657f4ef72e4e052142 \
34                    ld64-136.tar.gz \
35                    rmd160  4a2930ccdd398b63a108810e90293ab96dc154a0 \
36                    sha256  99d6c4acb6d4cdf45772951dd2308222aa966763170137459a9d276674645d9e \
37                    ld64-236.3.tar.gz \
38                    rmd160  6a3f44aa9ae57a60d2cff5b3d47be7972ad83029 \
39                    sha256  8ef36729b643201081ab45ebd8586ede8f9968bc17614b679a940faa82875ca6 \
40                    ld64-264.3.102.tar.gz \
41                    rmd160  c8169a8dd591989abdf45c0834397891ec72b458 \
42                    sha256  307f73678a3e5c9ed4d1bcf77da7399d84efac32916c5df6cd477c3b5c36f953
43
44
45subport ld64-97 {
46    # XCode 3.2.6
47    version             97.17
48    revision            5
49
50    set makefile        "Makefile-97"
51    set ld64_ver        97
52
53    compiler.blacklist-append *clang*
54
55    patchfiles \
56        ld64-version.patch \
57        ld64-97-no-LTO.patch \
58        ld64-97-ppc-branch-island.patch \
59        ld64-97-arm_types_PR38931.patch \
60        ld64-97-long-branch-warn.patch \
61        ld64-97-standalone-libunwind-headers.patch \
62        ld64-97-no-Availability.h.patch \
63        ld64-97-BaseAtomImplicitDecl.patch \
64        ld64-97-no-ppc-thread_status.patch
65
66    if {${os.major} >= 14} {
67        pre-fetch {
68            ui_error "$subport is not supported on Yosemite or later."
69            error "unsupported platform"
70        }
71    }
72}
73
74subport ld64-127 {
75    # XCode 4.2
76    # This was the last ld64 release that supported linking ppc executables.
77    version             127.2
78    revision            7
79
80    set makefile        "Makefile-127"
81    set ld64_ver        127
82
83    patchfiles-append \
84        ld64-version.patch \
85        ld64-134-missing-include.patch \
86        ld64-127-any-cctools.patch \
87        ld64-127-long-branch-warn.patch \
88        ld64-127-cxx_initializer_order_and_sim.patch \
89        ld64-127-ppc.patch \
90        ld64-97-no-Availability.h.patch \
91        PR-12249048.patch \
92        PR-12057707.patch \
93        PR-13282463.patch \
94        ld64-ppc-9610466.patch
95}
96
97subport ld64-136 {
98    # XCode 4.6
99    version             136
100    revision            7
101
102    set makefile        "Makefile-133"
103    set ld64_ver        136
104
105    patchfiles-append \
106        ld64-version.patch \
107        ld64-133-no-CrashReporterClient.h.patch \
108        ld64-134-missing-include.patch \
109        ld64-136-i386-badAddress.patch \
110        PR-13282463.patch \
111        ld64-ppc-9610466.patch
112
113    if {${configure.cxx_stdlib} eq "libstdc++"} {
114        patchfiles-append   ld64-136-hash_set.patch
115    }
116
117    if {${os.major} <= 9} {
118        pre-fetch {
119            ui_error "$subport is not supported on Leopard or earlier.  It requires the blocks runtime."
120            error "unsupported platform"
121        }
122    }
123}
124
125subport ld64-236 {
126    # XCode 5.1
127    version             236.3
128    revision            5
129
130    # http://trac.macports.org/ticket/43737
131    # < 100 is a guess.  Xcode 4.1 might work, so I'm leaving it as an option unless someone reports a failure.
132    compiler.blacklist-append *gcc* {clang < 100}
133
134    set makefile        "Makefile-133"
135    set ld64_ver        236
136
137    patchfiles-append \
138        ld64-version.patch \
139        ld64-133-no-CrashReporterClient.h.patch \
140        ld64-134-missing-include.patch \
141        ld64-136-i386-badAddress.patch \
142        PR-16935960.patch \
143        PR-16936488.patch \
144        ld64-ppc-9610466.patch
145
146    if {${configure.cxx_stdlib} eq "libstdc++"} {
147        patchfiles-append   ld64-236-hash_set.patch
148    }
149
150    if {${os.major} <= 9} {
151        pre-fetch {
152            ui_error "$subport is not supported on Leopard or earlier.  It requires the blocks runtime."
153            error "unsupported platform"
154        }
155    }
156}
157
158subport ld64-latest {
159    # XCode 7.3.1
160    version             264.3.102
161    revision            3
162
163    # https://trac.macports.org/ticket/43737
164    # https://trac.macports.org/ticket/50130
165    compiler.blacklist-append *gcc* {clang < 300}
166
167    set makefile        "Makefile-264"
168    set ld64_ver        latest
169
170    patchfiles-append \
171        ld64-version.patch \
172        ld64-133-no-CrashReporterClient.h.patch \
173        ld64-134-missing-include.patch \
174        ld64-136-i386-badAddress.patch \
175        ld64-ppc-9610466.patch \
176        PR-49393.patch
177
178    depends_lib-append port:libcxx
179    configure.cxx_stdlib libc++
180    configure.cxxflags-append -std=c++11
181
182    supported_archs i386 x86_64
183}
184
185subport ld64-xcode {
186    version             1
187}
188
189variant universal {}
190
191if {${subport} eq ${name}} {
192    distfiles
193    build {}
194    use_configure no
195
196    variant ld64_97 conflicts ld64_127 ld64_136 ld64_236 ld64_xcode description {Use ld64-97 as the default linker (last version that works on Tiger)} {}
197    variant ld64_127 conflicts ld64_97 ld64_136 ld64_236 ld64_xcode description {Use ld64-127 as the default linker (last version to support ppc)} {}
198    variant ld64_136 conflicts ld64_97 ld64_127 ld64_236 ld64_xcode description {Use ld64-136 as the default linker (last version that works on Leopard)} {}
199    variant ld64_236 conflicts ld64_97 ld64_127 ld64_136 ld64_xcode description {Use ld64-236 as the default linker (last version that builds against OS X's libstdc++)} {}
200    variant ld64_xcode conflicts ld64_97 ld64_127 ld64_136 ld64_236 description {Use ld64-xcode as the default linker (version provided by the selected Xcode.app toolchain)} {}
201
202    if {![variant_isset ld64_97] && ![variant_isset ld64_127] && ![variant_isset ld64_136]} {
203        if {${os.major} < 9} {
204            default_variants +ld64_97
205        } elseif {${os.major} < 10 || "ppc" in [get_canonical_archs]} {
206            default_variants +ld64_127
207        } elseif {${os.major} < 11} {
208            default_variants +ld64_136
209        }
210    }
211
212    if {[variant_isset ld64_97]} {
213        set ld64_ver 97
214    } elseif {[variant_isset ld64_127]} {
215        set ld64_ver 127
216    } elseif {[variant_isset ld64_136]} {
217        set ld64_ver 136
218    } elseif {[variant_isset ld64_236]} {
219        set ld64_ver 236
220    } elseif {[variant_isset ld64_xcode]} {
221        set ld64_ver xcode
222    } else {
223        set ld64_ver latest
224    }
225
226    depends_run         port:ld64-${ld64_ver}
227
228    destroot {
229        ln -s ld-${ld64_ver} ${destroot}${prefix}/bin/ld
230
231        file mkdir ${destroot}${prefix}/libexec/ld64
232        ln -s ld-${ld64_ver} ${destroot}${prefix}/libexec/ld64/ld
233
234        if {![variant_isset ld64_xcode]} {
235            ln -s dyldinfo-${ld64_ver} ${destroot}${prefix}/bin/dyldinfo
236            ln -s machocheck-${ld64_ver} ${destroot}${prefix}/bin/machocheck
237            ln -s ObjectDump-${ld64_ver} ${destroot}${prefix}/bin/ObjectDump
238            ln -s rebase-${ld64_ver} ${destroot}${prefix}/bin/rebase
239            ln -s unwinddump-${ld64_ver} ${destroot}${prefix}/bin/unwinddump
240        }
241    }
242} elseif {${subport} eq "${name}-xcode"} {
243    distfiles
244    use_configure no
245    build {}
246    destroot {
247        xinstall -m 755 ${filespath}/ld-xcode ${destroot}${prefix}/bin/ld-xcode
248    }
249} else {
250    distfiles           dyld-${dyld_version}.tar.gz ${name}-${version}.tar.gz
251
252    depends_build       path:include/mach-o/arm/reloc.h:libmacho-headers
253
254    if {[string match macports-clang-* ${configure.compiler}]} {
255        # For a new enough install_name_tool
256        depends_build-append port:cctools
257    }
258
259    set all_llvm_variants {llvm38 llvm39 llvmdev}
260    if {${os.major} < 10} {
261        lappend all_llvm_variants llvm33
262    }
263    if {${os.major} < 12} {
264        lappend all_llvm_variants llvm34
265    }
266    array set llvm_variant_version {llvm33 3.3 llvm34 3.4 llvm38 3.8 llvm39 3.9 llvmdev devel}
267    set llvm_version {}
268
269    foreach variantname $all_llvm_variants {
270        set this_llvm_version $llvm_variant_version($variantname)
271        variant $variantname conflicts {*}[ldelete $all_llvm_variants $variantname] description "Use llvm-${this_llvm_version} for libLTO" "
272            set llvm_version        $this_llvm_version
273            depends_lib-append      port:llvm-${this_llvm_version}
274        "
275    }
276
277    proc some_llvm_variant_set {} {
278        global all_llvm_variants
279        foreach variantname $all_llvm_variants {
280            if {[variant_isset $variantname]} {
281                return yes
282            }
283        }
284        return no
285    }
286
287    # We don't set llvmXX as the default variant on Tiger because it would introduce a
288    # dependency cycle as llvm requires apple-gcc42 and ld64 to build correctly.  Users
289    # wanting LTO support in ld64 on Tiger can install the +llvm variant after llvm
290    # has been installed.
291
292    if {![some_llvm_variant_set]} {
293        if {${os.major} == 10 || ${os.major} == 11} {
294            default_variants +llvm34
295        } elseif {${os.major} == 9} {
296            # Using llvm-3.3 to break dependency cycle (https://trac.macports.org/ticket/52091)
297            default_variants +llvm33
298        }
299
300        if {![some_llvm_variant_set] && ${os.major} >= 9} {
301            default_variants +llvm38
302        }
303
304        if {![some_llvm_variant_set] && ${os.major} >= 9} {
305            pre-fetch {
306                ui_error "Your platform cannot be configured without LTO support in ld64.  Please enable one of the llvmXX variants, and try again."
307                return -code error "Your platform cannot be configured without LTO support in ld64.  Please enable one of the llvmXX variants, and try again."
308            }
309        }
310    }
311
312    if {${os.major} < 10} {
313        # Leopard and earlier didn't have libunwind.h in the SDK
314        depends_build-append    path:include/libunwind.h:libunwind-headers
315    }
316
317    compiler.blacklist-append gcc-4.0
318
319    pre-fetch {
320        if {${os.major} < 9} {
321            if {${llvm_version} != ""} {
322                if {![file exists ${prefix}/bin/llvm-config-mp-${llvm_version}]} {
323                    ui_error "You must first install ld64 without llvm support to build llvm.  After llvm is installed, you can reinstall ld64 with the llvm variant."
324                    return -code error "You must first install ld64 without llvm support to build llvm.  After llvm is installed, you can reinstall ld64 with the llvm variant."
325                }
326            }
327        }
328    }
329
330    post-extract {
331        file copy ${filespath}/${makefile} ${worksrcpath}/Makefile
332    }
333
334    post-patch {
335        reinplace "s|@@VERSION@@|${version}|g" \
336            ${worksrcpath}/src/ld/Options.cpp
337
338        if {${os.major} < 9} {
339            # No CommonCrypto, use openssl
340            reinplace "s:<CommonCrypto/CommonDigest.h>:<openssl/md5.h>:" \
341                ${worksrcpath}/src/ld/MachOWriterExecutable.hpp
342            reinplace "s:CC_MD5:MD5:" \
343                ${worksrcpath}/src/ld/MachOWriterExecutable.hpp
344
345            reinplace "s:-Wl,-exported_symbol,__mh_execute_header::g" \
346                ${worksrcpath}/Makefile
347
348            foreach reg {cr ctr eax ebp ebx ecx edi edx eip esi esp lr mq r0 r1 r10 r11 r12 r13 r14 r15 r16 r17 r18 r19 r2 r20 r21 r22 r23 r24 r25 r26 r27 r28 r29 r3 r30 r31 r4 r5 r6 r7 r8 r9 rax rbp rbx rcx rdi rdx rip rsi rsp srr0 srr1 vrsave xer} {
349                reinplace "s|__${reg}|${reg}|g" ${worksrcpath}/src/ld/parsers/libunwind/Registers.hpp
350            }
351        }
352
353        foreach header [glob ${workpath}/dyld-${dyld_version}/include/{,*/}*.h] {
354            if {${os.major} < 9} {
355                reinplace "s|__MAC_10_5|__MAC_NA|g" ${header}
356                reinplace "s|AVAILABLE_MAC_OS_X_VERSION_10_\\(.\\)_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_5|AVAILABLE_MAC_OS_X_VERSION_10_\\1_AND_LATER|" ${header}
357                reinplace "s|AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER|__attribute__((unavailable))|g" ${header}
358
359                reinplace "s|Availability.h|AvailabilityMacros.h|g" ${header}
360                reinplace "s|__OSX_AVAILABLE_STARTING(__MAC_NA,.*)|__attribute__((unavailable))|g" ${header}
361                reinplace "s|__OSX_AVAILABLE_BUT_DEPRECATED(__MAC_NA,.*)|__attribute__((unavailable))|g" ${header}
362                reinplace "s|__OSX_AVAILABLE_STARTING(__MAC_10_\\(\[^,\]*\\),.*)|AVAILABLE_MAC_OS_X_VERSION_10_\\1_AND_LATER|g" ${header}
363                reinplace "s|__OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_\\(\[^,\]*\\),__MAC_NA,.*)|AVAILABLE_MAC_OS_X_VERSION_10_\\1_AND_LATER|g" ${header}
364                reinplace "s|__OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_\\(\[^,\]*\\),__MAC_10_\\(\[^,\]*\\),.*)|AVAILABLE_MAC_OS_X_VERSION_10_\\1_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_\\2|g" ${header}
365            }
366        }
367    }
368
369    configure {
370        system "cd ${worksrcpath} && ${build.cmd} src/ld/configure.h"
371    }
372
373    set cxx_stdlibflags {}
374    if {[string match *clang* ${configure.cxx}]} {
375        set cxx_stdlibflags -stdlib=${configure.cxx_stdlib}
376    }
377
378    configure.cppflags-append -I${workpath}/dyld-${dyld_version}/include
379
380    build.args \
381        CC="${configure.cc}" \
382        CXX="${configure.cxx}" \
383        OTHER_CPPFLAGS="${configure.cppflags}" \
384        OTHER_CFLAGS="${configure.cflags} [get_canonical_archflags cc]" \
385        OTHER_CXXFLAGS="${configure.cxxflags} ${cxx_stdlibflags} [get_canonical_archflags cxx]" \
386        OTHER_LDFLAGS="${configure.ldflags} ${cxx_stdlibflags} [get_canonical_archflags ld]"
387
388    if {${os.major} >= 11} {
389        build.args-append \
390            RC_SUPPORTED_ARCHS="armv6 armv7 i386 x86_64"
391    }
392
393    destroot.args \
394        PREFIX=${prefix}
395
396    pre-build {
397        if {${llvm_version} != ""} {
398            build.args-append LLVM_CONFIG=${prefix}/bin/llvm-config-mp-${llvm_version}
399        }
400
401        if {${os.major} < 9} {
402            build.args-append OTHER_LDFLAGS_LD64=-lcrypto
403        }
404    }
405
406    post-destroot {
407        # ${prefix}/bin/ld will always use the llvm we built against
408        # ${prefix}/libexec/ld64/ld uses relative linking for use with the llvm ports
409        file mkdir ${destroot}${prefix}/libexec/ld64
410        file copy ${destroot}${prefix}/bin/ld ${destroot}${prefix}/libexec/ld64/ld-${ld64_ver}
411
412        file rename ${destroot}${prefix}/bin/dyldinfo ${destroot}${prefix}/bin/dyldinfo-${ld64_ver}
413        file rename ${destroot}${prefix}/bin/ld ${destroot}${prefix}/bin/ld-${ld64_ver}
414        file rename ${destroot}${prefix}/bin/machocheck ${destroot}${prefix}/bin/machocheck-${ld64_ver}
415        file rename ${destroot}${prefix}/bin/ObjectDump ${destroot}${prefix}/bin/ObjectDump-${ld64_ver}
416        file rename ${destroot}${prefix}/bin/rebase ${destroot}${prefix}/bin/rebase-${ld64_ver}
417        file rename ${destroot}${prefix}/bin/unwinddump ${destroot}${prefix}/bin/unwinddump-${ld64_ver}
418
419        delete {*}[glob ${destroot}${prefix}/share/man/man1/*]
420
421        if {${llvm_version} != ""} {
422            system "install_name_tool -change ${prefix}/libexec/llvm-${llvm_version}/lib/libLTO.dylib \
423                    @executable_path/../lib/libLTO.dylib ${destroot}${prefix}/libexec/ld64/ld-${ld64_ver}"
424            system "install_name_tool -change @rpath/libLTO.dylib \
425                    @executable_path/../lib/libLTO.dylib ${destroot}${prefix}/libexec/ld64/ld-${ld64_ver}"
426        }
427    }
428}
429
430livecheck.type          none
Note: See TracBrowser for help on using the repository browser.