Ticket #69315: Portfile_fpc_wip_i386.txt

File Portfile_fpc_wip_i386.txt, 19.8 KB (added by barracuda156, 8 months ago)

This merely introduces basic support for i386, it will not build, as of now:

Line 
1# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
2
3PortSystem          1.0
4
5name                fpc
6version             3.2.2
7categories          lang pascal
8platforms           macosx
9license             {GPL-2 LGPL-2}
10maintainers         {@kamischi web.de:karl-michael.schindler} \
11                    {@barracuda156 gmail.com:vital.had} \
12                    openmaintainer
13description         Free Pascal, an open source Pascal and Object Pascal \
14                    compiler.
15long_description    Free Pascal is a 32, 64 and 16 bit professional Pascal \
16                    compiler. It can target many processor architectures: \
17                    Intel x86 (including 8086), AMD64/x86-64, PowerPC, \
18                    PowerPC64, SPARC, ARM, AArch64, MIPS and the JVM. \
19                    Supported operating systems include Linux, FreeBSD, \
20                    Mac OS X/iOS/iPhoneSimulator/Darwin, Win32, Win64, WinCE \
21                    and Android.
22homepage            https://www.freepascal.org
23
24# Bootstrap compiler version
25set boot_v          3.0.4
26
27master_sites        sourceforge:freepascal:main \
28                    https://downloads.freepascal.org/fpc/dist/${boot_v}/bootstrap/:bootstrap \
29                    https://downloads.freepascal.org/fpc/dist/${boot_v}/powerpc-macosx/:bootstrap \
30                    https://downloads.freepascal.org/fpc/dist/${boot_v}/i386-macosx/:bootstrap
31
32set src             ${name}build-${version}.tar.gz
33checksums           ${src} \
34                    rmd160  3106b4aff1adc4cd08dfdd39cc3ef4e800888255 \
35                    sha256  85ef993043bb83f999e2212f1bca766eb71f6f973d362e2290475dbaaf50161f \
36                    size    84195619
37# PowerPC compiler is only available as a dmg
38if {${configure.build_arch} in [list ppc ppc64]} {
39    set pp          fpc-${boot_v}.powerpc-macosx.dmg
40    checksums-append \
41                    ${pp} \
42                    rmd160  c1dbe7fb71382a69146023b2cdac768e05fea8e3 \
43                    sha256  587a6ae199d2fb992794c6b4ff9a7aa0c4646687ed5bbab5a6c96bdc322ba53c \
44                    size    98748823
45} elseif {${configure.build_arch} eq "i386"} {
46    set pp          fpc-${boot_v}a.intel-macosx.dmg
47    checksums-append \
48                    ${pp} \
49                    rmd160  1b838335467c0ab31f856031139e25954602b1ad \
50                    sha256  56b870fbce8dc9b098ecff3c585f366ad3e156ca32a6bf3b20091accfb252616 \
51                    size    108371671
52} else {
53    set pp          x86_64-macosx-10.9-ppcx64.tar.bz2
54    checksums-append \
55                    ${pp} \
56                    rmd160  7c5327aa6f4fd8616d78bc4f708463b9fb3e8844 \
57                    sha256  0515ad4251c51fa7e5c0ff9b1d90ea50f41530b56276cc72b73798fae437b3b4 \
58                    size    1556308
59}
60distfiles           ${src}:main ${pp}:bootstrap
61
62# doesn't install shared libraries
63installs_libs       no
64
65# parallel building is unreliable
66use_parallel_build  no
67
68extract.only        ${src}
69
70use_configure       no
71universal_variant   no
72
73set fpcbasepath     ${prefix}/libexec/${name}
74
75if {${os.platform} eq "darwin" && ${os.major} >= 22} {
76 # macOS 13, Ventura, fix obsolete linker options
77    patchfiles-append   t_darwin.pas.patch
78}
79
80subport "chmcmd-${name}" {
81    revision        0
82
83    description     The FPC Pascal htmlhelp (CHM) compiler
84    long_description \
85                    chmcmd is a cross-platform utility to generate compressed \
86                    HTML (.chm) documentation, written in Free Pascal.
87
88    depends_build-append \
89                    port:${name}
90    extract.post_args-append \
91                    ${name}build-${version}/fpcsrc/packages/chm \
92                    ${name}build-${version}/fpcsrc/packages/fcl-xml \
93                    ${name}build-${version}/fpcsrc/packages/fcl-base \
94                    ${name}build-${version}/fpcsrc/packages/fcl-process \
95                    ${name}build-${version}/fpcsrc/packages/fpmkunit \
96                    ${name}build-${version}/fpcsrc/packages/hash \
97                    ${name}build-${version}/fpcsrc/packages/iconvenc \
98                    ${name}build-${version}/fpcsrc/packages/libtar \
99                    ${name}build-${version}/fpcsrc/packages/paszlib \
100                    ${name}build-${version}/fpcsrc/packages/univint \
101                    ${name}build-${version}/fpcsrc/rtl
102    worksrcdir      ${name}build-${version}/fpcsrc/packages/chm
103    use_configure   yes
104    configure.cmd   ${fpcbasepath}/bin/fpcmake
105    configure.pre_args
106    configure.args  -r -v Makefile.fpc.fpcmake
107    configure.post_args
108
109    patchfiles-delete   t_darwin.pas.patch
110
111    build.env       PREFIX=${prefix}
112    build.target
113    build.post_args-append \
114                    V=1 VERBOSE=1
115    destroot {
116        xinstall -m 0755 ${build.dir}/chmcmd ${destroot}${prefix}/bin
117    }
118}
119
120subport "${name}-cross" {
121    revision        0
122
123    description     FreePascal common cross-compiler binaries
124    long_description \
125                    Crosscompilers serving as starting points \
126                    for specific operating system targets.    \
127                    OS runtime libraries are not yet ready.
128    depends_build-append \
129                    port:${name}
130
131    worksrcdir      ${name}build-${version}/fpcsrc/compiler
132    use_configure   no
133    patch.pre_args  -p1
134    build.args      OPT="-ap -v0"
135    build.target    aarch64 arm avr i386 i8086 jvm m68k mips mipsel \
136                    powerpc powerpc64 sparc x86_64
137    switch ${build_arch} {
138        x86_64 {
139            build.target-delete x86_64
140        }
141        arm64 {
142            build.target-delete aarch64
143        }
144    }
145    destroot {
146      # delete unwanted files
147        file delete -force ${worksrcpath}/ppcgen
148        file delete        {*}[glob ${worksrcpath}/ppc*.*]
149
150      # create dirs
151        xinstall -m 0755 -d ${destroot}${prefix}/bin
152        xinstall -m 0755 -d ${destroot}${prefix}/lib/fpc/${version}
153
154      # loop over installing all cross-compilers
155        foreach PPCCROSS [glob -tails -directory ${worksrcpath} ppc*] {
156            xinstall -m 0755 ${worksrcpath}/$PPCCROSS \
157                    ${destroot}${prefix}/lib/fpc/${version}
158            ln -sf ../lib/fpc/${version}/$PPCCROSS \
159                    ${destroot}${prefix}/bin/$PPCCROSS
160        }
161    }
162}
163
164subport "${name}-cross-arm-wince" {
165    revision                0
166    worksrcdir              fpcbuild-${version}/fpcsrc
167    use_parallel_build      no
168    use_configure           no
169    depends_build-append    port:${name} port:${name}-cross
170#    build.target            rtl packages
171#    destroot.target         rtl_install packages_install
172    build.target            rtl
173    destroot.target         rtl_install
174
175# target specifics
176    description     FPC cross-compiler for arm-wince
177    long_description \
178        This Pascal crosscompiler produces arm executables, \
179        which run natively on arm-wince systems. \n \
180        Get help with: \n \
181        fpc -h \n \
182        Compile and link a Pascal file with: \n \
183        \n \
184        fpc -Parm -Twince FILENAME
185
186    build.args      PP=ppcarm CPU_TARGET=arm OS_TARGET=wince OPT="-ap -v0"
187    destroot.args   CPU_TARGET=arm OS_TARGET=wince CROSSINSTALL=1 \
188                    INSTALL_PREFIX=${destroot}${prefix}
189
190# remove duplicate doc and bin files
191    post-destroot   {
192        file delete -force ${destroot}${prefix}/share
193        file delete -force ${destroot}${prefix}/bin
194    }
195}
196
197foreach ostarget {nativent win32 wince} {
198    subport "${name}-cross-i386-$ostarget" {
199        revision                0
200        worksrcdir              fpcbuild-${version}/fpcsrc
201        use_parallel_build      no
202        use_configure           no
203        depends_build-append    port:${name} port:${name}-cross
204#        build.target            rtl packages
205#        destroot.target         rtl_install packages_install
206        build.target            rtl
207        destroot.target         rtl_install
208
209# target specifics
210        description     FPC cross-compiler for i386-$ostarget
211        long_description \
212            This Pascal crosscompiler produces i386 executables, \
213            which run natively on i386-$ostarget systems. \n \
214            Get help with: \n \
215            fpc -h \n \
216            Compile and link a Pascal file with: \n \
217            \n \
218            fpc -Pi386 -T$ostarget FILENAME
219
220        build.args      PP=ppc386 CPU_TARGET=i386 OS_TARGET=$ostarget \
221                        OPT="-ap -v0"
222        destroot.args   CPU_TARGET=i386 OS_TARGET=$ostarget CROSSINSTALL=1 \
223                        INSTALL_PREFIX=${destroot}${prefix}
224
225# remove duplicate doc and bin files
226        post-destroot   {
227            file delete -force ${destroot}${prefix}/share
228            file delete -force ${destroot}${prefix}/bin
229        }
230    }
231}
232
233subport "${name}-cross-x86-64-win64" {
234    revision                0
235    worksrcdir              fpcbuild-${version}/fpcsrc
236    use_parallel_build      no
237    use_configure           no
238    depends_build-append    port:${name} port:${name}-cross
239#    build.target            rtl packages
240#    destroot.target         rtl_install packages_install
241    build.target            rtl
242    destroot.target         rtl_install
243
244# target specifics
245    description     FPC cross-compiler for x86_64-win64
246    long_description \
247        This Pascal crosscompiler produces x86_64 executables, \
248        which run natively on x86_64-win64 systems. \n \
249        Get help with: \n \
250        fpc -h \n \
251        Compile and link a Pascal file with: \n \
252        \n \
253        fpc -Px86_64 -Twin64 FILENAME
254
255    build.args      PP=ppcx64 CPU_TARGET=x86_64 OS_TARGET=win64 OPT="-ap -v0"
256    destroot.args   CPU_TARGET=x86_64 OS_TARGET=win64 CROSSINSTALL=1 \
257                    INSTALL_PREFIX=${destroot}${prefix}
258
259# remove duplicate doc and bin files
260    post-destroot   {
261        file delete -force ${destroot}${prefix}/share
262        file delete -force ${destroot}${prefix}/bin
263    }
264}
265
266if {${subport} eq "${name}"} {
267    revision            1
268
269    installs_libs       yes
270
271    if {${os.platform} eq "darwin" \
272        && ${configure.build_arch} in [list ppc ppc64]} {
273        post-extract {
274            xinstall -d ${workpath}/tmp/boot
275            system "hdiutil attach ${distpath}/${pp} -private -nobrowse \
276                    -mountpoint ${workpath}/tmp/boot"
277            copy ${workpath}/tmp/boot/${name}-${boot_v}.powerpc-macosx.pkg \
278                    ${workpath}/pkg
279            system "hdiutil detach ${workpath}/tmp/boot -force"
280            delete -force ${workpath}/tmp/boot
281            system -W ${workpath} "gunzip -d pkg/Contents/Archive.pax.gz"
282            system -W ${workpath}/pkg "pax -r < Contents/Archive.pax"
283            copy ${workpath}/pkg/usr/local/lib/${name}/${boot_v}/${bootstrapCompiler} \
284                    ${workpath}
285        }
286    } elseif {${os.platform} eq "darwin" \
287        && ${configure.build_arch} eq "i386"} {
288        depends_extract port:xar
289        post-extract {
290            xinstall -d ${workpath}/tmp/boot
291            system "hdiutil attach ${distpath}/${pp} -private -nobrowse \
292                    -mountpoint ${workpath}/tmp/boot"
293            xinstall -d ${workpath}/pkg
294            system -W ${workpath} "${prefix}/bin/xar -xf \
295                    ${workpath}/tmp/boot/${name}-${boot_v}a.intel-macosx.pkg \
296                    -C ${workpath}/pkg"
297            system "hdiutil detach ${workpath}/tmp/boot -force"
298            delete -force ${workpath}/tmp/boot
299            system -W ${workpath}/pkg/${name}-${boot_v}a.intel-macosx.pkg \
300                    "cat Payload | gunzip -dc | cpio -i"
301            system -W ${workpath}/pkg/${name}-${boot_v}a.intel-macosx.pkg \
302                    "cp ./usr/local/lib/${name}/${boot_v}/${bootstrapCompiler} \
303                    ${workpath}"
304        }
305    } else {
306        extract.only-append ${pp}
307    }
308
309    post-patch {
310        # adjust the path "codfilepath" for plex
311        # from /usr/local to MacPort's prefix.
312        reinplace "s|/usr/local|${prefix}|g" \
313            ${worksrcpath}/utils/tply/pyacc.y \
314            ${worksrcpath}/utils/tply/pyacc.pas \
315            ${worksrcpath}/utils/tply/plex.pas
316    }
317
318    switch ${build_arch} {
319        i386 {
320            set bootstrapCompiler ppc386
321            set cpuTarget i386
322            set compiler ppc386
323        }
324        x86_64 {
325            set bootstrapCompiler ppcx64
326            set cpuTarget x86_64
327            set compiler ppcx64
328        }
329        arm64 {
330            set bootstrapCompiler ppcx64
331            set cpuTarget aarch64
332            set compiler ppca64
333        }
334        ppc {
335            set bootstrapCompiler ppcppc
336            set cpuTarget powerpc
337            set compiler ppcppc
338        }
339        ppc64 {
340            set bootstrapCompiler ppcppc64
341            set cpuTarget powerpc64
342            set compiler ppcppc64
343        }
344        default {
345            set bootstrapCompiler unsupported
346            set cpuTarget unsupported
347            set compiler unsupported
348        }
349    }
350
351    if {${os.platform} eq "darwin"} {
352        if       {${os.major} >= 20} { # 11, Big Sur
353            set otherOptions "-WM11.0 -XR${configure.sdkroot}"
354        } elseif {${os.major} >= 13} { # 10.9, Mavericks
355            set otherOptions "-WM10.9"
356        } elseif {${configure.build_arch} eq "i386"} {
357            if {${os.major} == 8} {
358                set otherOptions "-WM10.4"
359            } elseif {${os.major} < 11} {
360                set otherOptions "-WM10.5 -Aas"
361            } else {
362                set otherOptions "-WM${macosx_deployment_target}"
363            }
364        } elseif {${configure.build_arch} in [list ppc ppc64]} {
365            # Relevant only for macOS PowerPC
366            patchfiles-append patch-powerpc.diff
367            # On Tiger building is trivial
368            if {${os.major} == 8} {
369                set otherOptions "-WM10.4"
370            } else {
371                # At the moment linking fails for pas2js on 10.5 and 10.6
372                # with the system or cctools ld. ld_classic works,
373                # but it does not link against 10.5+ SDK. Therefore,
374                # use 10.4 SDK for all PowerPC. See:
375                # https://gitlab.com/freepascal.org/fpc/source/-/issues/40625
376                macosx_deployment_target 10.4
377                set tiger_sdkpath ${developer_dir}/SDKs/MacOSX10.4u.sdk
378                if {![file exists $tiger_sdkpath]} {
379                    pre-fetch {ui_error "Building ${name} requires 10.4 SDK"}
380                }
381                # We use symlinks to needed tools, but make sure those
382                # have not been created already:
383                set binutils_path ${workpath}/bin
384                pre-build {
385                    if {![file exists $binutils_path]} {
386                        xinstall -m 0755 -d ${workpath}/bin
387                        ln -s /usr/bin/as ${workpath}/bin/as
388                        ln -s /usr/bin/ld_classic ${workpath}/bin/ld
389                    }
390                }
391                set otherOptions "-WM${macosx_deployment_target} \
392                        -XR${tiger_sdkpath} -Fl=/usr/lib -FD${binutils_path}"
393            }
394        } else   {
395            set otherOptions ""
396        }
397    }
398
399    worksrcdir          ${name}build-${version}/fpcsrc
400    build.env           PP=${workpath}/${bootstrapCompiler} \
401                        PREFIX=${destroot}${fpcbasepath}
402    build.args          OPT="-v0 -ap ${otherOptions}" CPU_TARGET=${cpuTarget} \
403                        UTILS=1
404
405    destroot.args       {*}${build.args}
406    destroot.env        {*}${build.env}
407
408    # codesign for older systems does not have a --remove-signature option
409    # work around: replace codesign by a dummy.
410    if {${os.platform} eq "darwin" && ${os.major} <= 15} { # 10.11, El Capitan
411        build.args-append   CODESIGN=/usr/bin/true
412    }
413
414    # build the compiler utilities msgdif and msg2inc
415    post-build {
416        system -W ${worksrcpath}/compiler/utils \
417               "../${compiler} -ap -v0 -Fu../../rtl/units/${cpuTarget}-darwin \
418                  ${otherOptions} msgdif.pp && \
419                ../${compiler} -ap -v0 -Fu../../rtl/units/${cpuTarget}-darwin \
420                  ${otherOptions} msg2inc.pp"
421    }
422
423    post-destroot {
424        # create a symlink to the architecture dependent executable
425        ln -s ${fpcbasepath}/lib/${name}/${version}/${compiler} \
426                ${destroot}${fpcbasepath}/bin
427        # target arm64 needs make utils_install explicitly
428        if {${build_arch} == "arm64"} {
429            system -W ${worksrcpath} \
430                "make utils_install FPC=${worksrcpath}/compiler/${compiler} \
431                    PREFIX=${destroot}${fpcbasepath} \
432                    OPT=\"-Furtl/units/${cpuTarget}-darwin -ap -v0 \
433                    ${otherOptions}\""
434        }
435        # generate a configuration file
436        xinstall -d ${destroot}${fpcbasepath}/etc
437        system -W ${destroot}${fpcbasepath} \
438            "bin/fpcmkcfg -d basepath=${fpcbasepath}/lib/${name}/${version} \
439                    -o etc/fpc.cfg"
440        ln -s ${fpcbasepath}/etc/fpc.cfg ${destroot}${prefix}/etc
441        system "patch ${destroot}${fpcbasepath}/etc/fpc.cfg \
442                    ${filespath}/fpc.cfg.patch"
443
444        # remove the -WM option for older systems or update it as needed
445        if {${os.platform} eq "darwin"} {
446            if {${configure.build_arch} in [list ppc ppc64]} { # macOS PowerPC
447                reinplace "s|-WM10.9|-WM10.4|g" \
448                    ${destroot}${fpcbasepath}/etc/fpc.cfg
449            } elseif {${configure.build_arch} eq "i386"}   { # macOS x86
450                reinplace "s|-WM10.9|-WM${macosx_deployment_target}|g" \
451                    ${destroot}${fpcbasepath}/etc/fpc.cfg
452            } elseif {${os.major} < 11}   { # 10.7, Lion
453                reinplace "s|-WM10.9||g" ${destroot}${fpcbasepath}/etc/fpc.cfg
454            } elseif {${os.major} >=  20} { # 11, Big Sur
455                reinplace "s|-WM10.9|-WM11.0|g" \
456                    ${destroot}${fpcbasepath}/etc/fpc.cfg
457            }
458            if {${os.major} < 13} {
459                reinplace "s|/Applications/Xcode.app/Contents/Developer||g" \
460                        ${destroot}${fpcbasepath}/etc/fpc.cfg
461            }
462        }
463
464        # set prefix of search path for qt4pas
465        reinplace "s|PREFIX|${prefix}|g" ${destroot}${fpcbasepath}/etc/fpc.cfg
466
467        # install man
468        xinstall -d ${destroot}${fpcbasepath}/man
469        foreach d {1 5} {
470            file copy ${workpath}/${name}build-${version}/install/man/man${d} \
471                ${destroot}${fpcbasepath}/man
472            foreach f [glob ${destroot}${fpcbasepath}/man/man${d}/*.${d}] {
473                system "/usr/bin/gzip ${f}"
474            }
475        }
476        ln -s ${fpcbasepath}/man/man1/fpc.1.gz \
477            ${destroot}${prefix}/share/man/man1
478        ln -s ${fpcbasepath}/man/man5/fpc.cfg.5.gz \
479            ${destroot}${prefix}/share/man/man5
480
481        # chmcmd will be installed by the chmcmd-fpc subport
482        file delete -force ${destroot}${fpcbasepath}/bin/chmcmd
483        foreach b [glob -nocomplain ${destroot}${fpcbasepath}/bin/*] {
484            set n [file tail ${b}]
485            ln -s ${fpcbasepath}/bin/${n} ${destroot}${prefix}/bin
486        }
487
488        # install the compiler utilities msgdif and msg2inc
489        xinstall -m 0755 -W ${worksrcpath}/compiler/utils msgdif msg2inc \
490                ${destroot}${prefix}/bin
491    }
492
493    notes "
494        The compiler fpc looks for the fpc.cfg file in the following places:
495        - The current directory.
496        - Home directory, looks for .fpc.cfg
497        - The directory specified in the environment variable PPC_CONFIG_PATH,\
498          and if it's not set under compilerdir/../etc.
499        - If it is not yet found: in /etc.
500
501        All the files of fpc are installed in ${fpcbasepath} and\
502        the executables are installed in ${fpcbasepath}/bin. The fpc.cfg\
503        is installed in ${fpcbasepath}/etc to make fpc find fpc.cfg.\
504        To customize, use ~/.fpc.cfg or /etc/fpc.cfg and call\
505        ${fpcbasepath}/bin/fpc directly.
506    "
507
508    livecheck.distname  ${name}
509} else {
510    livecheck.type      none
511}