source: trunk/dports/devel/ld64/Portfile @ 135226

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

ld64: Fix a few Leopard link issues, and prefer llvm-3.3 for now on Leopard since 3.4 has issues compiling with Leopard's gcc-4.2

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 12.6 KB
Line 
1# $Id: Portfile 135226 2015-04-19 20:06:11Z jeremyhu@macports.org $
2
3PortSystem              1.0
4PortGroup               compiler_blacklist_versions 1.0
5
6name                    ld64
7epoch                   2
8version                 2
9categories              devel
10platforms               darwin
11maintainers             jeremyhu
12homepage                http://opensource.apple.com/source/${name}/
13master_sites            http://opensource.apple.com/tarballs/${name}/
14license                 APSL-2
15description             ld64 is the new mach-o linker
16long_description        ld64 combines several object files and libraries, \
17                        resolves references, and produces an ouput file.
18
19subport ld64-97 {
20    # XCode 3.2.6
21    version             97.17
22
23    checksums           ld64-97-standalone-libunwind-headers.patch \
24                        rmd160  f6da71e097aa61b1055b3fdc12cd39aafed5f492 \
25                        sha256  370d02757ea628b5dd145c099e42fc4eb88cc09cf459a59e32d14bbc9b4a105e \
26                        ld64-97.17.tar.gz \
27                        rmd160  d52df7d7f741c8bedd29cbac73dbb9db992b4795 \
28                        sha256  02bd46af0809eaa415d096d7d41c3e8e7d80f7d8d181840866fb87f036b4e089
29
30    set makefile        "Makefile-97"
31    set ld64_ver        97
32
33    compiler.blacklist-append *clang*
34
35    patchfiles \
36        ld64-version.patch \
37        ld64-97-no-LTO.patch \
38        ld64-97-ppc-branch-island.patch \
39        ld64-97-arm_types_PR38931.patch \
40        ld64-97-long-branch-warn.patch \
41        ld64-97-standalone-libunwind-headers.patch \
42        ld64-97-no-Availability.h.patch \
43        ld64-97-BaseAtomImplicitDecl.patch \
44        ld64-97-no-ppc-thread_status.patch
45
46    if {${os.major} >= 14} {
47        pre-fetch {
48            ui_error "$subport is not supported on Yosemite or later."
49            error "unsupported platform"
50        }
51    }
52}
53
54subport ld64-127 {
55    # XCode 4.2
56    # This was the last ld64 release that supported linking ppc executables.
57    version             127.2
58    revision            2
59
60    checksums           rmd160  8ee709341549a1944732daef6ebab7ef1acfcc6e \
61                        sha256  97b75547b2bd761306ab3e15ae297f01e7ab9760b922bc657f4ef72e4e052142
62
63    set makefile        "Makefile-127"
64    set ld64_ver        127
65
66    patchfiles-append \
67        ld64-version.patch \
68        ld64-134-missing-include.patch \
69        ld64-127-any-cctools.patch \
70        ld64-127-long-branch-warn.patch \
71        ld64-127-cxx_initializer_order_and_sim.patch \
72        ld64-127-ppc.patch \
73        ld64-97-no-Availability.h.patch \
74        PR-12249048.patch \
75        PR-12057707.patch \
76        PR-13282463.patch \
77        ld64-ppc-9610466.patch
78}
79
80subport ld64-136 {
81    # XCode 4.6
82    version             136
83    revision            2
84
85    checksums           rmd160  4a2930ccdd398b63a108810e90293ab96dc154a0 \
86                        sha256  99d6c4acb6d4cdf45772951dd2308222aa966763170137459a9d276674645d9e
87 
88    set makefile        "Makefile-133"
89    set ld64_ver        136
90
91    patchfiles-append \
92        ld64-version.patch \
93        ld64-133-no-CrashReporterClient.h.patch \
94        ld64-134-missing-include.patch \
95        ld64-136-i386-badAddress.patch \
96        PR-13282463.patch \
97        ld64-ppc-9610466.patch
98
99    if {${configure.cxx_stdlib} eq "libstdc++"} {
100        patchfiles-append   ld64-136-hash_set.patch
101    }
102
103    if {${os.major} <= 9} {
104        pre-fetch {
105            ui_error "$subport is not supported on Leopard or earlier.  It requires the blocks runtime."
106            error "unsupported platform"
107        }
108    }
109}
110
111subport ld64-latest {
112    # XCode 5.1
113    version             236.3
114    revision            1
115
116    checksums           rmd160  6a3f44aa9ae57a60d2cff5b3d47be7972ad83029 \
117                        sha256  8ef36729b643201081ab45ebd8586ede8f9968bc17614b679a940faa82875ca6
118
119    # http://trac.macports.org/ticket/43737
120    # < 100 is a guess.  Xcode 4.1 might work, so I'm leaving it as an option unless someone reports a failure.
121    compiler.blacklist-append *gcc* {clang < 100}
122
123    set makefile        "Makefile-133"
124    set ld64_ver        latest
125
126    patchfiles-append \
127        ld64-version.patch \
128        ld64-133-no-CrashReporterClient.h.patch \
129        ld64-134-missing-include.patch \
130        ld64-136-i386-badAddress.patch \
131        PR-16935960.patch \
132        PR-16936488.patch \
133        ld64-ppc-9610466.patch
134
135    if {${configure.cxx_stdlib} eq "libstdc++"} {
136        patchfiles-append   ld64-236-hash_set.patch
137    }
138
139    if {${os.major} <= 9} {
140        pre-fetch {
141            ui_error "$subport is not supported on Leopard or earlier.  It requires the blocks runtime."
142            error "unsupported platform"
143        }
144    }
145}
146
147variant universal {}
148
149if {${subport} eq ${name}} {
150    distfiles
151    build {}
152    use_configure no
153
154    variant ld64_97 conflicts ld64_127 ld64_136 description {Use ld64-97 as the default linker} {}
155    variant ld64_127 conflicts ld64_97 ld64_136 description {Use ld64-127 as the default linker (last version to support ppc)} {}
156    variant ld64_136 conflicts ld64_97 ld64_127 description {Use ld64-136 as the default linker} {}
157
158    if {![variant_isset ld64_97] && ![variant_isset ld64_127] && ![variant_isset ld64_136]} {
159        if {${os.major} < 9} {
160            default_variants +ld64_97
161        } elseif {${os.major} < 10 || "ppc" in [get_canonical_archs]} {
162            default_variants +ld64_127
163        } elseif {${os.major} < 11} {
164            default_variants +ld64_136
165        }
166    }
167
168    if {[variant_isset ld64_97]} {
169        set ld64_ver 97
170    } elseif {[variant_isset ld64_127]} {
171        set ld64_ver 127
172    } elseif {[variant_isset ld64_136]} {
173        set ld64_ver 136
174    } else {
175        set ld64_ver latest
176    }
177
178    depends_run         port:ld64-${ld64_ver}
179
180    destroot {
181        ln -s dyldinfo-${ld64_ver} ${destroot}${prefix}/bin/dyldinfo
182        ln -s ld-${ld64_ver} ${destroot}${prefix}/bin/ld
183        ln -s machocheck-${ld64_ver} ${destroot}${prefix}/bin/machocheck
184        ln -s ObjectDump-${ld64_ver} ${destroot}${prefix}/bin/ObjectDump
185        ln -s rebase-${ld64_ver} ${destroot}${prefix}/bin/rebase
186        ln -s unwinddump-${ld64_ver} ${destroot}${prefix}/bin/unwinddump
187
188        file mkdir ${destroot}${prefix}/libexec/ld64
189        ln -s ld-${ld64_ver} ${destroot}${prefix}/libexec/ld64/ld
190    }
191} else {
192    depends_build       path:include/mach-o/dyld_priv.h:dyld-headers \
193                        path:include/mach-o/arm/reloc.h:libmacho-headers
194
195    if {[string match macports-clang-* ${configure.compiler}]} {
196        # For a new enough install_name_tool
197        depends_build-append port:cctools
198    }
199
200    # We don't set llvmXX as the default variant on Tiger because it would introduce a
201    # dependency cycle as llvm requires apple-gcc42 and ld64 to build correctly.  Users
202    # wanting LTO support in ld64 on Tiger can install the +llvm variant after llvm
203    # has been installed.
204
205    if {![variant_isset llvm33] && ![variant_isset llvm34] && ![variant_isset llvm35] && ![variant_isset llvm36] && ![variant_isset llvm37]} {
206        if {${os.major} >= 13} {
207            default_variants +llvm35
208        } elseif {${os.major} >= 10} {
209            default_variants +llvm34
210        } elseif {${os.major} >= 9} {
211            default_variants +llvm33
212        }
213
214        if {![variant_isset llvm33] && ![variant_isset llvm34] && ![variant_isset llvm35] && ![variant_isset llvm36] && ![variant_isset llvm37] && ${os.major} >= 9} {
215            ui_error "Your platform cannot be configured without LTO support in ld64.  Please enable one of the llvmXX variants, and try again."
216            return -code error "Your platform cannot be configured without LTO support in ld64.  Please enable one of the llvmXX variants, and try again."
217        }
218    }
219
220    set llvm_version {}
221    variant llvm33 conflicts llvm34 llvm35 llvm36 llvm37 description {Use llvm-3.3 for libLTO} {
222        set llvm_version        3.3
223        depends_lib-append      port:llvm-${llvm_version}
224    }
225
226    variant llvm34 conflicts llvm33 llvm35 llvm36 llvm37 description {Use llvm-3.4 for libLTO} {
227        set llvm_version        3.4
228        depends_lib-append      port:llvm-${llvm_version}
229    }
230
231    variant llvm35 conflicts llvm33 llvm34 llvm36 llvm37 description {Use llvm-3.5 for libLTO} {
232        set llvm_version        3.5
233        depends_lib-append      port:llvm-${llvm_version}
234    }
235
236    variant llvm36 conflicts llvm33 llvm34 llvm35 llvm37 description {Use llvm-3.6 for libLTO} {
237        set llvm_version        3.6
238        depends_lib-append      port:llvm-${llvm_version}
239    }
240
241    variant llvm37 conflicts llvm33 llvm34 llvm35 llvm36 description {Use llvm-3.7 for libLTO} {
242        set llvm_version        3.7
243        depends_lib-append      port:llvm-${llvm_version}
244    }
245
246    if {${os.major} < 10} {
247        # Leopard and earlier didn't have libunwind.h in the SDK
248        depends_build-append    path:include/libunwind.h:libunwind-headers
249    }
250
251    compiler.blacklist-append gcc-4.0
252
253    pre-fetch {
254        if {${os.major} < 9} {
255            if {${llvm_version} != ""} {
256                if {![file exists ${prefix}/bin/llvm-config-mp-${llvm_version}]} {
257                    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."
258                    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."
259                }
260            }
261        }
262    }
263
264    post-extract {
265        file copy ${filespath}/${makefile} ${worksrcpath}/Makefile
266    }
267
268    post-patch {
269        reinplace "s|@@VERSION@@|${version}|g" \
270            ${worksrcpath}/src/ld/Options.cpp
271
272        if {${os.major} < 9} {
273            # No CommonCrypto, use openssl
274            reinplace "s:<CommonCrypto/CommonDigest.h>:<openssl/md5.h>:" \
275                ${worksrcpath}/src/ld/MachOWriterExecutable.hpp
276            reinplace "s:CC_MD5:MD5:" \
277                ${worksrcpath}/src/ld/MachOWriterExecutable.hpp
278
279            reinplace "s:-Wl,-exported_symbol,__mh_execute_header::g" \
280                ${worksrcpath}/Makefile
281
282            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} {
283                reinplace "s|__${reg}|${reg}|g" ${worksrcpath}/src/ld/parsers/libunwind/Registers.hpp
284            }
285        }
286    }
287
288    configure {
289        system "cd ${worksrcpath} && ${build.cmd} src/ld/configure.h"
290    }
291
292    set cxx_stdlibflags {}
293    if {[string match *clang* ${configure.cxx}]} {
294        set cxx_stdlibflags -stdlib=${configure.cxx_stdlib}
295    }
296
297    build.args \
298        CC="${configure.cc}" \
299        CXX="${configure.cxx}" \
300        OTHER_CPPFLAGS="${configure.cppflags}" \
301        OTHER_CFLAGS="${configure.cflags} [get_canonical_archflags cc]" \
302        OTHER_CXXFLAGS="${configure.cxxflags} ${cxx_stdlibflags} [get_canonical_archflags cxx]" \
303        OTHER_LDFLAGS="${configure.ldflags} ${cxx_stdlibflags} [get_canonical_archflags ld]"
304
305    if {${os.major} >= 11} {
306        build.args-append \
307            RC_SUPPORTED_ARCHS="armv6 armv7 i386 x86_64"
308    }
309
310    destroot.args \
311        PREFIX=${prefix}
312
313    pre-build {
314        if {${llvm_version} != ""} {
315            build.args-append LLVM_CONFIG=${prefix}/bin/llvm-config-mp-${llvm_version}
316        }
317
318        if {${os.major} < 9} {
319            build.args-append OTHER_LDFLAGS_LD64=-lcrypto
320        }
321    }
322
323    post-destroot {
324        # ${prefix}/bin/ld will always use the llvm we built against
325        # ${prefix}/libexec/ld64/ld uses relative linking for use with the llvm ports
326        file mkdir ${destroot}${prefix}/libexec/ld64
327        file copy ${destroot}${prefix}/bin/ld ${destroot}${prefix}/libexec/ld64/ld-${ld64_ver}
328
329        file rename ${destroot}${prefix}/bin/dyldinfo ${destroot}${prefix}/bin/dyldinfo-${ld64_ver}
330        file rename ${destroot}${prefix}/bin/ld ${destroot}${prefix}/bin/ld-${ld64_ver}
331        file rename ${destroot}${prefix}/bin/machocheck ${destroot}${prefix}/bin/machocheck-${ld64_ver}
332        file rename ${destroot}${prefix}/bin/ObjectDump ${destroot}${prefix}/bin/ObjectDump-${ld64_ver}
333        file rename ${destroot}${prefix}/bin/rebase ${destroot}${prefix}/bin/rebase-${ld64_ver}
334        file rename ${destroot}${prefix}/bin/unwinddump ${destroot}${prefix}/bin/unwinddump-${ld64_ver}
335
336        eval delete [glob ${destroot}${prefix}/share/man/man1/*]
337
338        if {${llvm_version} != ""} {
339            system "install_name_tool -change ${prefix}/libexec/llvm-${llvm_version}/lib/libLTO.dylib \
340                    @executable_path/../lib/libLTO.dylib ${destroot}${prefix}/libexec/ld64/ld-${ld64_ver}"
341        }
342    }
343}
344
345livecheck.type          none
Note: See TracBrowser for help on using the repository browser.