#!/bin/sh -e #=============================================================== # Filename : bootstrap # Purpose : Builds a GCC toolchain and robust development tools # Authors : Zach van Rijn # License : MIT # Revision : 20260205 #=============================================================== ## # This software is currently considered experimental, pre-alpha, # and may not work in new or ill-configured environments. Please # report any issues you encounter (email is fine) and attach the # build log (or relevant portions) and files referenced therein. # # Log files are located adjacent to the build directories, named # -.log.{err,out}. Please compress # before submitting logs. #=============================================================== # README #=============================================================== # # overview # -------- # # This script builds a GCC toolchain and other utilities for any # supported unix-like platform (Solaris, AIX, Linux, BSD, macOS) # where the resulting tooling provides a consistent environment # in which "musl-cross-make" can be built. Windows platforms are # currently under testing (Cygwin, MSYS2, WSL). Your particular # system may call for adjustments to certain build parameters. # # No arguments are passed to this script. Edit the parameters in # the subsequent sections. Reasonable defaults are listed. # # The user's system is assumed to have limited functionality, in # that it lacks tooling which obeys any reasonable standards, so # all necessary tools are built from source prior to GCC. # # Output of this script is a "system" directory containing built # tools, a "host toolchain" directory containing a native albeit # modern GNU Compiler Collection (GCC) toolchain and binutils, # and "musl toolchain" directory containing a cross-compilation # toolchain targeting musl libc (https://musl.libc.org) if it is # supported by your system's architecture. # # When operating in "bootstrap" mode, all utilities are rebuilt # statically using the musl toolchain from the first step. This # provides a reliable set of static, but not relocatable, tools. # # All user-facing options are found in the "Build Configuration" # section, though it is trivial to customize other sections. # # # source code # ----------- # # The latest version of this script and corresponding notes may # be found at the following location (which may be git-cloned): # # https://git.zv.io/toolchains/bootstrap # # # features # -------- # # * Platform compatibility (Solaris, AIX, Linux, BSD, macOS); # # * Caching of source and build artifacts reduces time wasted # waiting for builds and rebuilds if the script is modified # or in the event of a component failing to build; # # * Build artifacts are cached even if the whole bootstrapping # tree is destroyed (stored in '$HOME/.ccache' by default); # # * Wide array of tools available and a framework conducive to # the brick-simple addition of new tools, and unwanted tools # can be disabled trivially with "if-false" barriers; # # * Modern GCC includes the best freely-available optimization # support for your applications; # # * Once installed, the necessary 'PATH' variable is shown and # may be used immediately; # # # requirements # ------------ # # You'll need a working internet connection and all of the tools # listed in the "Baseline System" section below. If the build is # unsuccessful, you may consider verifying these tools are up to # date and reporting the issue to me for documentation updates. # # Either 'curl' (preferred) or 'wget' will be used; they must be # configured to support TLS connections and to use any necessary # proxy settings for your company firewall, if applicable. You # do not need to specify which to use; this script auto-detects. # # If a file fails to download, you may need to remove a sentinel # indicating (erroneously) that the download was completed. At a # future point, a retry mechanim may be implemented. # # You will need the 'which' command before proceeding. The early # stages (environment sanity checking and preparation) may not # print the friendliest error messages. Use 'set -x' to debug. # # Broadly speaking, you'll also need (and be told if missing): # # * bash # * coreutils # * diffutils # * flex # * gcc, g++ # * m4 # * make # * perl # * xz, bzip2, gzip # # Few minimum utility versions are needed during bootstrap only: # # * GNU m4 1.4.6 or greater, necessary to build autotools and # bootstrap a newer 'gnulib' and 'm4' on platforms that the # current 'm4' doesn't support. This will be simplified upon # the next 'm4' release. # # * curl newer than ~7.40.0, unless you host all of the source # tarballs yourself and use a single mirror supported by the # available encryption protocols. The OpenCSW version is OK # if you're a Solaris user without a support contract. # # # usage # ----- # # The following example demonstrates building a musl-cross-make # toolchain from scratch using the bootstrapped compiler and one # directory as its pristine PATH: # # $ /path/to/bootstrap # (this script) # $ export PATH="" # $ bash # $ git clone https://git.zv.io/toolchains/musl-cross-make.git # $ cd musl-cross-make # $ curl -so config.mak https://conf.musl.cc/... # $ make ... # # where 'make ...' refers to the standard musl-cross-make build # command. See https://git.zv.io/toolchains/musl-cross-make for # more information. Don't forget to specify TARGET and OUTPUT. # # # supported platforms # ------------------- # # The following list is not exhaustive. These are platforms on # which this script is known to work without errors or kludges, # though this list may be out of date and may use settings that # are not currently presented in this version. Adjust as needed. # # * AIX (POWER7) -- very difficult to get working! # * Linux glibc (x86[_64], powerpc64[le], SPARC64) # * Linux musl (x86[_64], powerpc64[le]) # * macOS (x86_64) -- still a work-in-progress # * Solaris 10 (SPARC64) -- use OpenCSW tools when possible! # * Solaris 11 (SPARC64) -- use OpenCSW tools when possible! # # # multilib support # ---------------- # # Many systems are configured with "multilib" support, in that a # handful of libraries are built several times, each with slight # differences in their configuration. There is no "portable" way # to ensure this script runs correctly on every system, and you # will likely need to modify the build flags under the "Platform # Adjustments" section. Non-Linux platforms are less-friendly. # # This "multilib" support primarily applies to GNU binutils and # GCC; it has little or no relation to the other dependencies. A # system configured to explicitly disable "multilib" support is # detected by this script and the same convention is followed. # # If your system is configured with explicit "multilib" support, # your distribution vendor may have omitted necessary libraries, # which will cause this build (also auto-detected) to fail. # # As a quick example, on x86_64 Debian, you may need to do: # # $ sudo apt-get install libc6-dev{,-i386,-x32} # # which implies additional packages may be required depending on # how your distribution configured its GCC. This script detects # most of the relevant multilib-related configuration flags. The # key here is: we'll try to model your system's GCC as closely # as possible, and this varies widely by distribution. # # On SPARC64 Debian, you may need to do: # # $ sudo apt-get install libc6-dev{,-sparc} # # In some cases, you may wish to change compiler, assembler, and # linker flags. You should delete and rebuild the entire output # directory unless you absolutely know what you are doing. Why? # Because this script uses the same flags for all packages/libs, # and changes to these flags can cause difficult-to-debug bugs. # # You are responsible for ensuring you have a working setup and # flags appropriate for your system. Do not contact me for this # unless you are willing to help and for documentation purposes. # # # design # ------ # # At startup, this script symlinks a number of "essential" tools # from your system into a single directory, which replaces PATH. # # Each tool is built and installed into a common directory which # is already prepended to the PATH environment variable. Thus, a # tool is built using any available tools built prior to it, and # only falls back to the system-provided tools if they cannot be # found. The minimum list of build-time dependencies is defined # in the "Baseline System" section. Many of these utilities are # built from source (newer versions or differing configuration). # # Built tools are only guaranteed to run on the machine on which # they are built. Portability in terms of machine and directory # location (i.e., the output directory is moved) and the ability # to cross-compile these tools is possible, but not guaranteed. # # Some programs are built differently on each platform and their # usage may not be compatible with other system utilities. # # Once this script finishes executing, "musl-cross-make" tooling # can be reproduced using only the output directories as PATH. # # The PATH variable is comprised of "utilities" and "toolchain" # directories, as there may be several toolchains (host-libc and # musl-libc). PATH is therefore ("glue" is not strictly needed): # # PATH=/{host,sys,glue}/bin # # * "host" is a (modern) host-libc-to-host-libc toolchain # # * "musl" only exists if your system supports musl (optional) # # * "sys" is a directory containing all the fresh tooling # # * "glue" is a directory containing symlinks to old tooling # and should not be needed for "musl-cross-make" # # # planned items # ------------- # # * Verify end-to-end production of "musl-cross-make" tooling # on all existing "supported" platforms, fix any issues, and # continue adding more; # # * Investigate whether 'rbash' (restricted bash) can be used # as a bulletproof command whitelisting mechanism, otherwise # consider writing one in C -- the goal is to eliminate all # possible sources of contamination during build -- include # also the verification of functionality and/or versions; # # * Support hash/checksum verification for all source packages # and allow user-override in cases where the user explicitly # requests to use a custom version. Downloads which fail to # verify will be retried N times before we give up; # # # script execution # ---------------- # # Package installation order is important. This configuration is # routinely tested on a number of diverse platforms. You may run # into silent breakage if you reorder the dependencies. # # Some dependencies are only necessary for building others, and # may become obsolete as new packages are released. Do not rely # on the availability of any tool except those that are required # for building "musl-cross-make". That list is subject to change # as well, so interpret this as "use these at your own risk". # # Each platform may have additional build-time dependencies; for # example, macOS requires the 'lipo' utility. It's not necessary # to build this for all platforms, so we "whitelist" access to # the host system's copy and allow it to be used only during the # bootstrap process. It is not included in the final output. # # This script relies heavily on the fact that 'configure' script # or other tools which accept command-line arguments, allow the # override of previously-specified arguments. Care must be taken # modifying the order or values of any such parameter sequence. # # # troubleshooting # --------------- # # (1) In the event of a failed source tarball download, you will # see errors relating to "invalid file format". To remedy, a # (broken) source tarball file must be deleted, e.g.: # # $HOME/mcmtools/sys/._curl-7.69.1.tar.xz.bin # # (2) In the event of changing a package's configuration after a # package has been installed (i.e., to trigger a rebuild), # a sentinel file must be deleted (this is an empty file): # # $HOME/mcmtools/sys/._curl-7.69.1.tar.xz # # # other remarks # ------------- # # Platform-specific notes (and some of my debugging madness) can # be found in the 'README.' file(s). No guarantees on # the accuracy or helpfulness of these files, but it's possible. #=============================================================== # Dependency Versions #=============================================================== ## # Ordering is consistent with installation. Please maintain it. # # Not all software here may be pulled from canonical mirrors; it # is important to verify mirror availability before changing the # version of any component below. Some versions may refer to git # tags or commit hashes and may not be official releases. Check # the mirroring section ("Dependency Mirrors") for information. # # Items commented with an asterisk ('*') in the rightmost column # anticipate major changes in the next-released version. # See the comments below ("Special Cases"). # # Items commented with the letter ('X') in the rightmost column # cannot be upgraded without investigation into incompatibility. # See the comments below ("Special Cases"). # # Items commented with a plus sign ('+') in the rightmost column # may require some additional setup or may not be portable. # See the comments below ("Special Cases"). ## # Phase 0 # V_CAB=2023-05-30; # curl CA bundle ## # Phase 1 (dependencies for reliable build). # V_CFG=a2287c3; # config V_MAK=4.3 ; # make V_GLB=475eac6; # gnulib X V_CCA=3.7.12 ; # ccache X V_PAT=2.7.6 ; # patch V_GBS=5.3 ; # bash V_SED=4.8 ; # sed V_CNF=1.7.3 ; # pkgconf V_GAC=2.69 ; # autoconf X V_GAA=2021.02.19; # autoconf-archive V_GAM=1.16.5 ; # automake V_TEX=7.2 ; # texinfo V_GPF=3.1 ; # gperf V_GM4=1.4.18 ; # m4 * V_AWK=5.1.1 ; # gawk V_GLT=2.4.6 ; # libtool V_GET=0.21 ; # gettext V_H2M=1.48.5 ; # help2man V_ML2=ec6e3ef; # libxml2 V_SLT=b0074ee; # libxslt V_GIN=2.2.12 ; # indent V_CUT=9.0 ; # coreutils V_BIS=3.8.2 ; # bison V_FLX=04c5b7c; # flex V_PR2=10.39 ; # pcre2 V_GRP=3.7 ; # grep ## # Phase 2a (preparation for combined GCC build). # V_GMP=6.2.1 ; # GMP V_MPF=4.1.0 ; # MPFR V_MPC=1.2.1 ; # MPC V_ISL=0.24 ; # ISL ## # Phase 2b (host-native toolchain). # V_BUT=2.43 ; # binutils V_GCC=13.3.0 ; # GCC ## # Phase 3a (dependencies for upstream "musl-cross-make"). # V_FUT=4.8.0 ; # findutils V_RSY=3.2.3 ; # rsync V_TAR=1.34 ; # tar V_BZ2=1.0.8 ; # bzip2 V_XZU=5.2.5 ; # xz V_GZP=1.11 ; # gzip V_DUT=3.8 ; # diffutils V_ZIP=30 ; # zip (infozip) V_WHC=2.21 ; # which ## # Phase 3b (dependencies for my fork of "musl-cross-make"). # V_ZLB=1.3.2 ; # zlib V_SSL=b2ec203; # bearssl V_CRL=7.80.0 ; # curl V_GDB=11.1 ; # gdb (optional, but useful) + V_XPT=ee695c7; # libexpat V_GIT=2.33.0 ; # git ## # Phase 4 (optional miscellaneous utilities). # V_HBC=7f6a907d; # bc (for kernel builds) V_PAR=20211022; # parallel V_PRL=5.36.0 ; # perl V_PCR=1.4 ; # perl-cross ## # Phase 5 (host-libc-linked proper "musl-cross-make" toolchain) # V_MLC=v1.2.5 ; # musl V_MCM=musl.cc; # musl-cross-make V_KRN=6.1.36 ; # kernel headers #=============================================================== # Special Cases #=============================================================== # # * m4 1.4.18 does not build on at least SPARC64 and requires # manually upgrading its internal 'gnulib'. This kludge will # hopefully become obsolete in the next release. A similar # issue occurs with the previous version of 'coreutils'. The # upgrade is performed on all platforms indiscriminately. # # * m4 1.4.19 fails to build from source. # # * autoconf 2.69 /exactly/ is required for GCC 10.3.0 # # * gdb (any version) likely requires Linux kernel headers to # be made available in the toolchain's preprocessor search # path; this is not done by default so it is left disabled. #=============================================================== # Dependency Mirrors #=============================================================== ## # This section of mirrors consolidates common download locations # across multiple packages by the same vendor, or choosing exact # mirrors best suited for your geographic location or firewall. # # Order is approximately "as used" but this is not enforced, and # no distinction is made between "sections" because mirrors may # be reused across sections. The question becomes where to put? # M_CAB=https://curl.haxx.se/ca; M_GNU=https://ftp.gnu.org/gnu; M_SVG=https://gitweb.git.savannah.gnu.org/gitweb; M_CCA=https://github.com/ccache/ccache/releases/download; M_DRF=https://distfiles.dereferenced.org; M_FLX=https://github.com/westes/flex/archive; M_PR2=https://github.com/PhilipHazel/pcre2/releases/download; M_GNO=https://gitlab.gnome.org/GNOME; M_ISL=https://downloads.sourceforge.net/project/libisl/; M_RSY=https://download.samba.org/pub/rsync/src; M_SRW=https://sourceware.org/pub; M_TUK=https://tukaani.org; M_SFN=https://downloads.sourceforge.net; M_ZLB=https://www.zlib.net; M_SSL="https://bearssl.org/gitweb/?p=BearSSL;a=snapshot;sf=tgz" M_CRL=https://curl.haxx.se/download; M_XPT=https://github.com/libexpat/libexpat/archive; M_GIT=https://mirrors.edge.kernel.org/pub/software/scm/git; M_HBC=https://github.com/gavinhoward/bc/archive; M_PRL=https://www.cpan.org/src; M_MLC=https://git.musl-libc.org/cgit/musl/snapshot; M_MCM=https://git.zv.io/toolchains/musl-cross-make/-/archive; #=============================================================== # Platform Adjustments #=============================================================== ## # The following global variables are declared empty by default. # Unless adjusted below, they are prepended to the corresponding # environment variable(s) during dependency builds. For example, # a variable '_KALE' here becomes 'export KALE="${_KALE} ...";' # where additional build- but not platform- specific changes may # be made. An example of that is 'CFLAGS= ... -I/custom/path;'. # _SYSTEM="$(uname -s)"; # abort on failure; we need this # _PATH=/dev/null; # if modified, don't prepend ':' _CPPFLAGS=; # _CFLAGS=; _CXXFLAGS=; _FFLAGS=; # _AR=; _ARFLAGS=; # _LD=; _LDFLAGS=; # _M4=; _MAKEINFO=; _ACLOCAL_PATH=; ## # These must be nonempty by default (i.e. they must be populated # by the logic either directly or further below). # _NPROC=; _SHELL=; _BUILD=; _TOOLS=; ## # # Some features (packages) may be skipped if not supported by the # build platform. This is a global flag and may be used anywhere. # _CHECK=; ## # Each supported platform is split into a 'case' below. Certain # adjustments are made based on my own testing, and shouldn't be # considered a requirement or best practice. # # Variables prefixed by a double-underscore ('__') are not to be # used elsewhere in this script; they are used for intermediate # local computations. Please unset them immediately! # # Commented values are left in-place as "potentially useful" for # folks experiencing build-time issues. Please report successful # flags and system information to me (failures, too). # case "${_SYSTEM}" in AIX) # _CPPFLAGS="-maix64"; # _CFLAGS="-maix64"; # _CXXFLAGS="-maix64"; # _LDFLAGS="-maix64 -lpthread"; _LDFLAGS="-lpthread"; _AR="ar rcs"; # TODO: https://github.com/openssl/openssl/pull/5386 # _ARFLAGS="-X64"; __core=$(lparstat -i | grep Online.\*CPUs \ | awk '{print $5}'); __nsmt=$(lparstat -i | grep SMT \ | awk -F'[-:]' '{print $4}'); _NPROC=$((${__core} * ${__nsmt})); _SHELL=$(command -v bash); unset __core __nsmt; ;; Darwin) # FIXME: may require fiddling # _CFLAGS="-arch x86_64 -m64"; # _CXXFLAGS="-arch x86_64 -m64"; # TODO: https://github.com/rust-lang/rust/pull/10013 # _LDFLAGS="-Wl,-no_compact_unwind"; # _LDFLAGS="-m64"; _NPROC=$(sysctl hw.logicalcpu \ | awk '{print $2}'); _SHELL=$(command -v bash); _TOOLS="lipo ranlib cpio"; ;; FreeBSD|OpenBSD) _NPROC=$(sysctl hw.ncpu | awk '{print $2}'); _SHELL=$(command -v bash); ;; Linux) _NPROC=$(nproc); _SHELL=$(command -v bash); ;; SunOS) # FIXME: only 64-bit supported _CPPFLAGS="-D_XPG6 -D_STDC_C99="; # _CPPFLAGS="-D_XPG6 -D_STDC_C99= -mcpu=v9 -m64"; # _CPPFLAGS="-D_XPG6 -mcpu=v9 -m64"; # _CFLAGS="-mcpu=v9 -m64"; # _CXXFLAGS="-mcpu=v9 -m64"; # _LDFLAGS="-m64"; _NPROC=$(2>/dev/null nproc || psrinfo | wc -l \ | awk '{print $1}'); _SHELL=$(command -v bash); ;; CYGWIN_NT*) # FIXME: close to working __gccd=$(gcc -print-search-dirs | grep install \ | cut -d' ' -f2); __gccl=$(find "${__gccd}" -type f -name "*.dll"); _PATH="/usr/bin:${__gccd}"; _NPROC=$(nproc); _SHELL=$(command -v bash); _TOOLS="${__gccl}"; unset __gccd __gccl; ;; MSYS_NT*|MINGW*_NT*) # FIXME: probably very difficult __gccd=$(gcc -print-search-dirs | grep install \ | cut -d' ' -f2); __gccl=$(find "${__gccd}" -type f -name "*.dll"); _PATH="/c/Windows/system32:/usr/bin:${__gccd}"; _NPROC=$(nproc); _SHELL=$(command -v bash); _TOOLS="${__gccl}"; unset __gccd __gccl; ;; *) # FIXME: please consider helping printf "Unsupported platform: '%s'\n" "${_SYSTEM}"; exit 1; ;; esac #=============================================================== # Baseline System #=============================================================== ## # The baseline list of system-provided tools that are necessary # to ensure a correct bootstrap process. Lexicographic order. # # Consider this a "whitelist" of utilities to allow (they are to # be symlinked to a directory in the PATH environment variable), # and the existing value of PATH is replaced exclusively by this # list in addition to a "system root" (--prefix=) constructed as # this script proceeds to build and install each component. # # Items prefixed by a hyphen ('-') indicate shell builtins that # may require additional processing to locate a full path to the # equivalent utility. For now, the 'which' command is called, as # 'command -v' does not appear to locate these correctly. # # This list is a superset of the utilities required in order to # build "musl-cross-make"; some of these are only needed for the # bootstrap process. # tool=$(grep -v ^# < '/host/native/gmake'. # # It's possible that some platforms require shared libraries to # be present adjacent to the system tools, since we destroy PATH # (e.g., Cygwin DLLs are no longer accessible). In this case the # '_TOOLS' variable is populated with a list of required DLLs # specified by absolute path. When we create a symlink for these # we need to take the effective basename. g=g; # few systems have g-pref. tools h=-; # character designating builtins mkdir -p "${sdir}/bin"; mkdir -p "${bin1}"; mkdir -p "${bin2}"; mkdir -p "${bin3}"; for k in ${tool}; do case "${k}" in /*) # absolute paths handled first ln -s "${k}" "${bin1}/${k##*/}" || true; continue; ;; esac k=${k##*/}; # effective basename case "${k}" in "${h}"*) k=${k#*${h}}; # remove the builtin designation skip=1; # skip normal link; search fails ;; *) # otherwise proceed as normal skip=0; # the 'command' utility works ;; esac test ! -f "${bin1}/${k}" || continue; p=$(command -v "${g}${k}" 2> /dev/null || true); if test "x${p}" = "x"; then # prefixed version not found p=$(command -v "${k}" 2> /dev/null || true); if test "x${p}" = "x"; then printf 1>&2 "ERROR: '%s' not found!\n" "${k}"; exit 1; # fatal: neither version found else # found normal r="${p}"; # name is unmodified fi else # found prefixed r="${p#${g}*}"; # name is stripped of prefix fi case "${r##*/}" in gperl) r=${r%/*}/perl; # SPECIAL: unrelated to perl esac if test ${skip} -eq 0; then # we have a non-builtin utility ln -s "${r}" "${bin1}/${k}" 2>/dev/null || true; else # we need to search for builtin ln -s "$(which ${r})" "${bin1}/${k}" 2>/dev/null || true; fi done ## # Download mechanism. Adjust names or add conditions if using # custom software or passing additional flags. # __curl=curl; # name in case of non-standard __wget=wget; # name in case of non-standard # if test "x$(command -v ${__curl} 2>/dev/null)" != "x"; then test -f "${bin1}/curl" \ || ln -s "$(command -v ${__curl})" "${bin1}/curl"; DRSO="curl -sL"; elif test "x$(command -v ${__wget} 2>/dev/null)" != "x"; then test -f "${bin1}/wget" \ || ln -s "$(command -v ${__wget})" "${bin1}/wget"; DRSO="wget -qO-"; else printf 1>&2 "ERROR: Could not find 'curl' or 'wget'\n"; exit 1; fi unset __curl __wget; #=============================================================== # PATH-related #=============================================================== export PATH="${bin1}:${_PATH}"; # here forward, whitelist only ## # Locates and prints the correct value for '--sysroot=' on POSIX # systems having GCC. Tested on Linux, macOS, Solaris, and AIX. # gsys () { d=usr/include; # directory pattern for search f=stdio.h; # name of one file expected here ${CC-gcc} -E -Wp,-v -&1 \ | awk '{if($1~/^\//)print $1;}' | while read k; do if test -f "${k%${d}*}${d}/${f}"; then printf "%s\n" "${k%${d}*}"; fi done 2>/dev/null | head -n 1; } _SYSROOT=$(gsys); # for GCC and binutils only #=============================================================== # Supporting Routines #=============================================================== _BASE=; _NAME=; _CONF=; ## # Skips a recipe step, permitting e.g. '_PREPARE=skip;' # skip () { :; # no-op } ## # Marks a package as installed. Internal use only, please, which # means do not use this outside of 'prep' or 'bake'. # mark () { touch "${sdir}/._${_BASE}"; } ## # State variables with global scope. # _SPECIAL=; _MACHINE=; _PATCHES=; _AUTOFOO=; _PREPARE=; _COMPILE=; _INSTALL=; ## # Extract a file specified by the first parameter into whichever # directory from which this routine is called. Internal only. # # Note: due to '-e' some 'tar' implementations (e.g. libarchive # bsdtar) can return nonzero for "warnings" like failing to set # permissions on symlinks. Any real errors will cause failures # during build, so this is an acceptable workaround. # tarx () { tar --strip-components="${_str}" -xv"${_tar}"f "${1}" || true; } ## # Downloads, extracts, and prepares for build a given software # package of this syntax, caching or overwriting as needed: # # Usage: # # prep [ ...] # # It is typically expected that URLs are direct links to source # tarballs of the form: "https://source.to/mypkg-1.0.0.tar.xz". # # This is easily parsed into "mypkg" (name of package) and the # file is downloaded as expected. Text after the hyphen ('-') is # assumed to be unique to that package's version, but version is # not taken into account when packages are built -- we cache the # extracted source files and build trees by this identifier. # # NOTE: URL can be provided as a string with two words; e.g., an # unusual tarball URL "foo https://source.to/?what_is&this=tgz". # This will be parsed as "foo" (name of package) and the file is # downloaded as expected (otherwise '?what...tgz' is the name). # # Recommended, but not required, is to use "foo-${V_FOO} ", # which re-enables the versioning functionality. # prep () { _tar="${1}"; shift; _str="${1}"; shift; _url="${1}"; shift; conf=${@}; mkdir -p "${bdir}"; # user may delete to clear space ## # This implements the two-word URL format for overriding the # package name. It does not account for package versioning! # if test "${_url}" != "${_url%\ *}"; then _pkg="${_url%\ *}"; # word 1 (package name) _url="${_url#*\ }"; # word 2 (download URL) base="${_pkg}"; # BUG? does not assign otherwise else # default case: one-word URL base=${_url##*/}; # effective basename fi printf " * %s\n" "${base%.tar.*}"; name=${base%-*}; # name of project w/o version ## # Populate globals (postcondition: these are nonempty). # _BASE=${base}; # package base w/ version info. _NAME=${name}; # package name _CONF=${conf}; # set user-provided conf. flags ## # Reset globals (postcondition: these are empty). # _SPECIAL=; _MACHINE=; _PATCHES=; _AUTOFOO=; _PREPARE=; _COMPILE=; _INSTALL=; _IGNB=; _IGNI=; ## # Create the system installation directory if not exist. # mkdir -p "${sdir}"; ## # The package has already been built and installed; done. # test ! -f "${sdir}/._${base}" || return 0; ## # Unpack a fresh tree (and download tarball if needed). # rm -f "${bdir}/${name}.log.*"; rm -fr "${bdir}/${name}/${tdir}"; mkdir -p "${bdir}/${name}/${tdir}"; ( # subshell for capturing logs cd "${bdir}/${name}"; # enter source tree if test ! -f "${sdir}/._${base}.bin"; then ${DRSO} "${_url}" \ | tee "${sdir}/._${base}.bin" | tarx -; else tarx "${sdir}/._${base}.bin"; fi ) \ 1>> "${bdir}/${name}.log.out" \ 2>> "${bdir}/${name}.log.err" \ ; } ## # Execute a series of pre-populated command sequences (e.g., for # manual configuration, build, and/or installation of packages), # defaulting to a standardized recipe if none is provided. This # routine executes in a subshell with a custom environment, so a # call to 'return' is insufficient; you must use 'exit'. # # The following global variables are recognized, all optional: # # * _SPECIAL # # Given the syntax 'PLAT:OPTS', applies extra (overriding) # configure-time options, appending to arguments to 'prep'. # # The 'PLAT' (PLATFORM) is e.g. { Darwin, Linux, ... }. # # Setting 'PLAT' to an asterisk ('*') indicates the options # are appended unconditionally to all platforms. # # # * _MACHINE # # Given the syntax 'MACH:OPTS', applies extra (overriding) # configure-time options, appending to arguments to 'prep'. # # The 'MACH' (MACHINE) is e.g. { powerpc64, riscv32, ... } # and comes from the first part of the target tuple. # # Setting 'MACH' to an asterisk ('*') indicates the options # are appended unconditionally to all platforms. # # # * _PATCHES # # If you intend to "patch" unmodified source files, please # specify these commands here. Syntax is: one entry per line # where each line is 'PLAT:URL'; the URL is fetched and sent # to the 'patch' command only if the architecture matches. # # The 'PLAT' (PLATFORM) is e.g. { Darwin, Linux, ... }. # # Setting 'PLAT' to an asterisk ('*') indicates the patches # are applied unconditionally to all platforms. # # The linked file should contain a trailing newline. This is # NOT aware of package versions; verify patches before bump. # Patches are filtered by platform and applied in order. # # TODO: Accept platform list 'SunOS,AIX:https://foo.com...'. # # # * _AUTOFOO # # If the source package *DOES NOT* have a 'configure' script # and you wish to either skip or override this step, you are # required to specify this variable appropriately. # # # * _PREPARE # # This variable is to manually override a default invocation # of 'configure' and can, for example, simply change current # working directories. # # # * _COMPILE # # This variable overrides the default 'make' command. Use it # to override 'make' if the source package does not need to # be compiled, or if you need to compile it differently. # # # * _INSTALL # # Some source packages are not installed via 'make install' # and require some additional (or less) processing. This is # an easy way to override the default. Use this if you must # specify a prefix, copy or delete certain files, or in any # other way deviate from standard behavior. # bake () { ( # subshell for capturing logs ## # The package has already been built and installed; done. If # you wish to rebuild the package, delete the file manually. # test ! -f "${sdir}/._${base}" || exit 0; ## # Set environment variables within this subshell only. They # must be exported; please do not remove that! # export PATH="${sdir}/bin:$PATH"; # export SHELL="${_SHELL}"; export CONFIG_SHELL="${_SHELL}"; # export CPPFLAGS="${CPPFLAGS-${_CPPFLAGS}}"; export CPATH="${sdir}/include"; # export CFLAGS="${CFLAGS-${_CFLAGS}} ${flag}"; # OVERRIDE export CXXFLAGS="${CXXFLAGS-${_CXXFLAGS}} ${flag}"; # OVERRIDE export FFLAGS="${FFLAGS-${_FFLAGS}} ${flag}"; # OVERRIDE # export AR="${AR-${_AR}}"; export ARFLAGS="${ARFLAGS-${_ARFLAGS}}"; # export LD="${LD-${_LD}}"; export LDFLAGS="${LDFLAGS-${_LDFLAGS}}"; export LIBRARY_PATH="${sdir}/lib"; # export M4="${M4-${_M4}}"; export MAKEINFO="${MAKEINFO-${_MAKEINFO}}"; export ACLOCAL_PATH="${ACLOCAL_PATH-${_ACLOCAL_PATH}}"; ## # Enter source tree. This may or may not be the build tree. # cd "${bdir}/${name}"; ## # (0) _SPECIAL or default recipe (no-op) is at top-level. # if test ! -z "${_SPECIAL}"; then printf "%s\n" "${_SPECIAL}" | while read k; do __plat=${k%%:*}; __opts=${k#*:}; if test "x${__plat}" = "x${_SYSTEM}" \ || test "x${__plat}" = "x*"; then _CONF="${_CONF} ${__opts}"; fi unset __plat __opts; done fi ## # (1) _MACHINE or default recipe (no-op) is at top-level. # if test ! -z "${_MACHINE}"; then printf "%s\n" "${_MACHINE}" | while read k; do __mach=${k%%:*}; __opts=${k#*:}; if test "x${__mach}" = "x${ARCH%%-*}" \ || test "x${__mach}" = "x*"; then _CONF="${_CONF} ${__opts}"; fi unset __mach __opts; done fi ## # (2) _PATCHES or default recipe (no-op) is at top-level. # if test ! -z "${_PATCHES}"; then printf "%s\n" "${_PATCHES}" | while read k; do __plat=${k%%:*}; __file=${k#*:}; if test "x${__plat}" = "x${_SYSTEM}" \ || test "x${__plat}" = "x*"; then ${DRSO} "${__file}" | patch -p1; fi unset __plat __file; done fi ## # If we have a new 'config.sub' and 'config.guess', use it. # for ext in guess sub; do case "${_NAME}" in musl-cross-make) continue; ;; esac if test -f "${sdir}/bin/config.${ext}"; then find . -name config.${ext} | while read k; do cp "${sdir}/bin/config.${ext}" "${k}"; done fi done ## # (3) _AUTOFOO or default recipe. # if test -z "${_AUTOFOO}"; then if test ! -f ./configure; then autoreconf --install --force || true; fi else eval "${_AUTOFOO}"; fi ## # Some packages may not support out-of-tree builds. In those # cases, remain in the top-level source directory and not an # ephemeral build directory. The '__dotty' variable must be # empty for non-standard packages and will otherwise contain # a single period ('.'). This is prepended to another period # producing either '.' or '..' for this or parent directory. # __dotty=; case "${_NAME}" in git) # what a special cookie ;; bearssl) # bears don't like cookies ;; zip) # zip it with the terrible puns? ;; bzip2) # can't think of one ;; musl-cross-make) # TODO: involves 'cowpatch' ;; perl) # rotten oyster of software ;; *) __dotty=.; cd "${tdir}"; ;; esac ## # (4) _PREPARE or default recipe. # if test -z "${_PREPARE}"; then ac_cv_func_statx=no \ ${__dotty}./configure \ --cache-file="${bdir}/${name}.cache" \ --prefix="${sdir}" \ --build="${_BUILD}" \ --host="${_BUILD}" \ --target="${_BUILD}" \ ${_CONF} \ ; else eval "${_PREPARE}"; fi unset __dotty; ## # (5) _COMPILE or default recipe. # if test -z "${_COMPILE}"; then make ${_OUTSYNC} ${_IGNB} -j"${_NPROC}"; else eval "${_COMPILE}"; fi ## # (6) _INSTALL or default recipe. # if test -z "${_INSTALL}"; then make ${_OUTSYNC} ${_IGNI} install; else eval "${_INSTALL}"; fi ## # Installation completed successfully; mark completed. # mark; ) \ 1>> "${bdir}/${name}.log.out" \ 2>> "${bdir}/${name}.log.err" \ ; } #=============================================================== # Stage 0: Prerequisites #=============================================================== if ! test -f "${sdir}/cacert.pem"; then ${DRSO} ${M_CAB}/cacert-${V_CAB}.pem > "${sdir}/cacert.pem"; fi export CURL_CA_BUNDLE="${sdir}/cacert.pem"; #=============================================================== # Stage 1: Bootstrap Environment #=============================================================== #--------------------------------------------------------------- # (GLOBAL) cat </dev/null); __tget2=$("${sdir}/bin/config.sub" $(gcc -dumpmachine)); if test "${__tget1}" != "${__tget2}"; then __build="${__tget2}"; # assume the compiler is right printf "WARN: config.guess ('%s') != compiler ('%s')\n" \ "${__tget1}" "${__tget2}"; else __build="${__tget1}"; # config.guess & compiler agree fi unset __tget1 __tget2; __parts=$(printf "%s\n" "${__build}" \ | sed -e 's/-/ /g' | wc -w | awk '{print $1}'); case "${__parts}" in 3) _BUILD=$(printf "${__build}" \ | awk -F'[-]' '{print $1"-local-"$2"-"$3}'); ;; 4) _BUILD=$(printf "${__build}" \ | awk -F'[-]' '{print $1"-local-"$3"-"$4}'); ;; *) printf 1>&2 "ERROR: '%s' not supported!\n" "${__build}"; exit 1; ;; esac unset __parts __build; #--------------------------------------------------------------- # make prep z 1 ${M_GNU}/make/make-${V_MAK}.tar.gz \ --disable-nls \ --disable-dependency-tracking \ ; bake; #--------------------------------------------------------------- # (GLOBAL) # FIXME: This is disabled until 'make' is patched (4.1 works but # fails to build on musl; 4.2 introduces the bug, so it will be # best to patch in 4.3 and beyond). #_OUTSYNC="-O"; # build output is easier to read #--------------------------------------------------------------- # gnulib prep z 1 "${M_SVG}/?p=gnulib.git;a=snapshot;h=${V_GLB};sf=tgz" \ --disable-nls \ ; _AUTOFOO=skip; _PREPARE=skip; _COMPILE=skip; _INSTALL=$(cat <<'EOF' ln -sf "$(pwd)/../gnulib-tool" "${bin1}/gnulib-tool"; EOF ); bake; #--------------------------------------------------------------- # ccache prep J 1 ${M_CCA}/v${V_CCA}/ccache-${V_CCA}.tar.xz \ ; bake; ( cd "${sdir}/bin"; # ccache will find correct GCC for k in g++ gcc; do test -f ${k} || ln -s ccache ${k}; done ) #--------------------------------------------------------------- # patch prep J 1 ${M_GNU}/patch/patch-${V_PAT}.tar.xz \ --disable-nls \ ; bake; #--------------------------------------------------------------- # bash prep z 1 ${M_GNU}/bash/bash-${V_GBS}.tar.gz \ --disable-nls \ --without-bash-malloc \ --without-curses \ ; _PATCHES=$(grep -v ^# <<'EOF' #5.1*:https://gitweb.gentoo.org/repo/gentoo.git/plain/app-shells/bash/files/bash-5.1-parallel_make.patch?id=4c2ebbf4b8bc660beb98cc2d845c73375d6e4f50 Darwin:https://raw.githubusercontent.com/Homebrew/formula-patches/cda4fced/bash/bash.patch EOF ); bake; ( cd "${sdir}/bin"; test -f sh || ln -s bash sh; ) #--------------------------------------------------------------- # (GLOBAL) _SHELL="${sdir}/bin/sh"; #--------------------------------------------------------------- # sed prep J 1 ${M_GNU}/sed/sed-${V_SED}.tar.xz \ --disable-nls \ ; bake; #--------------------------------------------------------------- # pkgconf prep J 1 ${M_DRF}/pkgconf/pkgconf-${V_CNF}.tar.xz \ --disable-shared \ --enable-static \ ; bake; #--------------------------------------------------------------- # autoconf prep J 1 ${M_GNU}/autoconf/autoconf-${V_GAC}.tar.xz \ M4="${bin1}/m4" \ ; bake; #--------------------------------------------------------------- # autoconf-archive prep J 1 \ ${M_GNU}/autoconf-archive/autoconf-archive-${V_GAA}.tar.xz \ ; bake; #--------------------------------------------------------------- # automake prep J 1 ${M_GNU}/automake/automake-${V_GAM}.tar.xz \ ; bake; #--------------------------------------------------------------- # texinfo prep J 1 ${M_GNU}/texinfo/texinfo-${V_TEX}.tar.xz \ --disable-nls \ ; # required for 'bison' to build in some cases bake; #--------------------------------------------------------------- # gperf prep z 1 ${M_GNU}/gperf/gperf-${V_GPF}.tar.gz \ ; # required for 'm4' to build in some cases bake; #--------------------------------------------------------------- # m4 ## NOTES # # This patch is required only because we update 'gnulib': # https://www.mail-archive.com/bug-m4@gnu.org/msg03225.html # https://lists.gnu.org/archive/html/bug-m4/2020-07/msg00000.html # https://lists.gnu.org/archive/html/bug-m4/2020-07/msg00001.html # prep J 1 ${M_GNU}/m4/m4-${V_GM4}.tar.xz \ --without-libiconv-prefix \ --without-libintl-prefix \ MAKEINFO=true \ ; _AUTOFOO=$(cat <<'EOF' __old='1\.15'; __new=$(printf "%s\n" "${V_GAM}" | cut -d'.' -f1,2); sed -i configure.ac \ -e "/AC_PREREQ/c\\AC_PREREQ\(\[${V_GAC}\]\)" \ ; gnulib-tool --add-import; grep -rl ${__old} . | while read k; do sed -i "${k}" \ -e "s/${__old}/${__new}/g" \ ; done unset __old __new; EOF ); _PATCHES=$(grep -v ^# <<'EOF' *:https://git.zv.io/snippets/49/raw EOF ); bake; #--------------------------------------------------------------- # gawk prep J 1 ${M_GNU}/gawk/gawk-${V_AWK}.tar.xz \ --disable-mpfr \ --disable-nls \ ; bake; #--------------------------------------------------------------- # libtool prep J 1 ${M_GNU}/libtool/libtool-${V_GLT}.tar.xz \ --disable-shared \ --enable-static \ --disable-nls \ ; bake; #--------------------------------------------------------------- # gettext # FIXME: Can examples be disabled? This slows down the build. prep J 1 ${M_GNU}/gettext/gettext-${V_GET}.tar.xz \ --disable-shared \ --enable-static \ --disable-nls \ ; # required for 'texinfo' on Darwin _IGNB="-ik"; # shared libraries are disabled _IGNI="-ik"; # so they fail to install :( bake; #--------------------------------------------------------------- # help2man prep J 1 ${M_GNU}/help2man/help2man-${V_H2M}.tar.xz \ --disable-nls \ ; bake; #--------------------------------------------------------------- # libxml2 prep j 1 ${M_GNO}/libxml2/-\ /archive/${V_ML2}/libxml2-${V_ML2}.tar.bz2 \ --disable-shared \ --enable-static \ --without-python \ --without-zlib \ ; _AUTOFOO=$(cat <<'EOF' autoreconf -i; EOF ); bake; #--------------------------------------------------------------- # libxslt prep j 1 ${M_GNO}/libxslt/-\ /archive/${V_SLT}/libxslt-${V_SLT}.tar.bz2 \ --disable-shared \ --enable-static \ --with-python=no \ ; bake; #--------------------------------------------------------------- # indent ## NOTES # # This patch removes a broken conditional header in/exclusion. A # second issue is that out-of-tree builds are not supported by a # directory called 'regression' (needs symlink to build dir, the # removal of 'regression' from any Makefile, or ignore errors). # prep J 1 ${M_GNU}/indent/indent-${V_GIN}.tar.xz \ --disable-nls \ CFLAGS="-Wno-error=unused-value" \ MAKEINFO=true \ ; _PATCHES=$(grep -v ^# <<'EOF' *:https://git.zv.io/snippets/46/raw EOF ); _IGNB="-i"; # ignore missing 'regression/' _IGNI="-i"; # ignore missing 'regression/' bake; #--------------------------------------------------------------- # coreutils prep J 1 ${M_GNU}/coreutils/coreutils-${V_CUT}.tar.xz \ --disable-nls \ --without-selinux \ FORCE_UNSAFE_CONFIGURE=1 \ TIME_T_32_BIT_OK=yes \ ; # 32-bit time only needed on some AIX systems bake; #--------------------------------------------------------------- # bison prep J 1 ${M_GNU}/bison/bison-${V_BIS}.tar.xz \ --disable-nls \ M4="${sdir}/bin/m4" \ ; bake; #--------------------------------------------------------------- # flex ## NOTES # # The state of the master branch of 'flex' is quite poor. There # are many issues, including broken parallel build support and a # nasty bug I don't have time to fix involving stage1 and normal # '*-scan.o' either containing or missing some symbols. # # Current observations: # # * new dependency on glue 'ranlib' # * custom autofoo step below # * disable parallel build # #V_FLX=bb9f458; # flex good with current kludge #V_FLX=30d0e5f; # flex good (last w/o patching) # # FIXME: Clean up this package. # prep z 1 "flex-${V_FLX} ${M_FLX}/${V_FLX}.tar.gz" \ --disable-shared \ --enable-static \ --disable-nls \ MAKEINFO=true \ M4=m4 \ ac_cv_func_malloc_0_nonnull=yes \ ac_cv_func_realloc_0_nonnull=yes \ ; _AUTOFOO=$(cat <<'EOF' ./autogen.sh; sed -e '/nodist_flex_OBJECTS/s/flex-stage1//' -i src/Makefile.in; EOF ); _COMPILE=$(cat <<'EOF' make ${_OUTSYNC} -j1; EOF ); bake; #--------------------------------------------------------------- # pcre2 prep z 1 ${M_PR2}/pcre2-${V_PR2}/pcre2-${V_PR2}.tar.gz \ --disable-shared \ --enable-static \ ; bake; #--------------------------------------------------------------- # grep prep J 1 ${M_GNU}/grep/grep-${V_GRP}.tar.xz \ --disable-perl-regexp \ ; _PATCHES=$(grep -v ^# <<'EOF' *:https://git.zv.io/-/snippets/68/raw/main/ppc.patch EOF ); bake; #=============================================================== # Stage 2a: Libraries Required by Compiler #=============================================================== #--------------------------------------------------------------- # gmp prep J 1 ${M_GNU}/gmp/gmp-${V_GMP}.tar.xz \ --disable-shared \ --enable-static \ --enable-cxx \ --disable-assembly \ ; bake; #--------------------------------------------------------------- # mpfr prep J 1 ${M_GNU}/mpfr/mpfr-${V_MPF}.tar.xz \ --disable-shared \ --enable-static \ --with-gmp="${sdir}" \ ; bake; #--------------------------------------------------------------- # mpc prep z 1 ${M_GNU}/mpc/mpc-${V_MPC}.tar.gz \ --disable-shared \ --enable-static \ --with-gmp="${sdir}" \ ; bake; #--------------------------------------------------------------- # isl prep z 1 ${M_ISL}/isl-${V_ISL}.tar.gz \ --disable-shared \ --enable-static \ --with-gmp-prefix="${sdir}" \ ; bake; #=============================================================== # Stage 2b: Compiler and Required Utilities #=============================================================== export PATH="${bin2}:${PATH}"; # for local new toolchain only #--------------------------------------------------------------- # binutils ## NOTES # # The "multilib" option does not behave the same way as for GCC; # it is explicitly enabled for consistency. # # --enable-64-bit-bfd : be consistent on all platforms # --enable-targets=all : be consistent on all platforms # prep J 1 ${M_GNU}/binutils/binutils-${V_BUT}.tar.xz \ --prefix="${gen2}" \ --disable-shared \ --enable-static \ --disable-nls \ --disable-gprofng \ --enable-multilib \ --with-sysroot="${_SYSROOT}" \ --enable-64-bit-bfd \ --enable-targets=all \ ; _PATCHES=$(grep -v ^# <<'EOF' SunOS:https://buildfarm.opencsw.org/source/raw/opencsw/csw/mgar/pkg/binutils/trunk/files/0001-Remove-existing-definition-of-SHARED-from-Solaris.patch EOF ); case "${_SYSTEM}" in Darwin) # use system utilities mark; ;; esac bake; #--------------------------------------------------------------- # gcc ## NOTES # # It is not yet known whether the '--with-{as,ld}=...' flags are # beneficial or not; only appears to be needed on Solaris but it # may reduce portability of the toolchain. # # --disable-multilib : non-default; __conf2 overrides # --disable-libsanitizer : may fail to build; not needed # --enable-obsolete : required for old Solaris etc. # --disable-comdat : required for any Solaris (?) # --{build,host,target}= : Solaris override (see README) # __conf1=$(gcc -v 2>&1 | grep Configure \ | "${sdir}/bin/pcre2grep" -io \ -e '--with-[a-z0-9_-]*=[a-z0-9_,-]*(\s|$)' || true); __conf2=$(gcc -v 2>&1 | grep Configure \ | "${sdir}/bin/pcre2grep" -io \ -e '--(en|dis)able-multi(arch|lib)' || true); __conf3=; case ${_BUILD} in p*pc64*-*linux-*) __conf3="--without-long-double-128"; ;; esac prep J 1 ${M_GNU}/gcc/gcc-${V_GCC}/gcc-${V_GCC}.tar.xz \ ${__conf1} \ --disable-multiarch \ --disable-multilib \ ${__conf2} \ --prefix="${gen2}" \ --disable-nls \ --with-gmp="${sdir}" \ --with-mpfr="${sdir}" \ --with-mpc="${sdir}" \ --with-isl="${sdir}" \ --enable-languages=c,c++,fortran \ --disable-bootstrap \ --disable-libsanitizer \ --with-sysroot="${_SYSROOT}" \ --with-as="${bin2}/as" \ --with-ld="${bin2}/ld" \ ${__conf3} \ ; _SPECIAL=$(grep -v ^# <<'EOF' SunOS:--disable-comdat --enable-obsolete --build= --host= --target= EOF ); _MACHINE=$(grep -v ^# <<'EOF' powerpc64:--with-abi=elfv2 EOF ); _PATCHES=$(grep -v ^# <<'EOF' SunOS:https://git.zv.io/snippets/42/raw #SunOS:https://git.zv.io/snippets/43/raw #SunOS:https://gcc.gnu.org/bugzilla/attachment.cgi?id=44083 EOF ); _AUTOFOO=$(cat <<'EOF' autoreconf -i; EOF ); _IGNB="-ik"; # texinfo-related? case "${_SYSTEM}" in Darwin) # use system utilities ( cd "${bin2}"; test -f "${bin2}/cc" || ln -s "${bin1}/gcc" cc ; test -f "${bin2}/c++" || ln -s "${bin1}/gcc" c++; ) mark; ;; esac bake; unset __conf1 __conf2; ( cd "${bin2}"; # create missing aliases test -f cc || ln -s gcc cc ; test -f c++ || ln -s g++ c++; ) #=============================================================== # Stage 3a: Dependencies for "musl-cross-make" (upstream) #=============================================================== #--------------------------------------------------------------- # findutils prep J 1 ${M_GNU}/findutils/findutils-${V_FUT}.tar.xz \ --disable-nls \ ; bake; #--------------------------------------------------------------- # rsync ## NOTES # # The xxhash dependency is a recent "enhancement" and conftests # currently do not catch (un)availability for graceful handling. # prep z 1 ${M_RSY}/rsync-${V_RSY}.tar.gz \ --disable-asm \ --disable-xxhash \ --disable-zstd \ --disable-lz4 \ --disable-simd \ --disable-openssl \ --disable-acl-support \ ; _IGNI="-i"; bake; #--------------------------------------------------------------- # tar prep J 1 ${M_GNU}/tar/tar-${V_TAR}.tar.xz \ --disable-nls \ FORCE_UNSAFE_CONFIGURE=1 \ ; # if someone wishes to build as root (not my problem) bake; #--------------------------------------------------------------- # bzip2 prep z 1 ${M_SRW}/bzip2/bzip2-${V_BZ2}.tar.gz \ ; _AUTOFOO=skip; _PREPARE=skip; _INSTALL=$(cat <<'EOF' make ${_OUTSYNC} ${_IGNI} install PREFIX="${sdir}"; EOF ); bake; #--------------------------------------------------------------- # xz export AR="ar rcs"; prep J 1 ${M_TUK}/xz/xz-${V_XZU}.tar.xz \ --disable-shared \ --enable-static \ --disable-nls \ ; bake; export AR=; #--------------------------------------------------------------- # gzip prep J 1 ${M_GNU}/gzip/gzip-${V_GZP}.tar.xz \ ; bake; #--------------------------------------------------------------- # diffutils prep J 1 ${M_GNU}/diffutils/diffutils-${V_DUT}.tar.xz \ --disable-nls \ ; _PATCHES=$(grep -v ^# <<'EOF' *:https://git.zv.io/-/snippets/68/raw/main/ppc.patch EOF ); bake; #--------------------------------------------------------------- # zip prep z 1 "zip-${V_ZIP} ${M_SFN}/infozip/zip${V_ZIP}.tar.gz" \ ; # (optional; feel free to comment this one out) _PATCHES=$(grep -v ^# <<'EOF' *:https://git.alpinelinux.org/aports/plain/main/zip/format-security.patch?id=c81c40f0291807a76db414fb4d8ccacd4ff33292 *:https://git.alpinelinux.org/aports/plain/main/zip/configure-gcc14.patch?id=14226268fa7d58f8faa74d8971ce1503959b8345 EOF ); _AUTOFOO=skip; _PREPARE=skip; _COMPILE=$(cat <<'EOF' make ${_OUTSYNC} ${_IGNB} -j"${_NPROC}" \ -f unix/Makefile generic \ ; EOF ); _INSTALL=$(cat <<'EOF' make ${_OUTSYNC} ${_IGNI} install prefix="${sdir}" \ -f unix/Makefile \ ; EOF ); case "${_SYSTEM}" in Darwin) # FIXME: unsupported (bad port?) mark; ;; esac bake; #--------------------------------------------------------------- # which prep z 1 ${M_GNU}/which/which-${V_WHC}.tar.gz \ --disable-nls \ ; bake; #=============================================================== # Stage 3b: Dependencies for "musl-cross-make" (my fork) #=============================================================== #--------------------------------------------------------------- # zlib export AR="ar rcs"; prep z 1 ${M_ZLB}/zlib-${V_ZLB}.tar.gz \ ; _PREPARE=$(cat <<'EOF' ../configure --prefix="${sdir}" --static; EOF ); bake; export AR=; #--------------------------------------------------------------- # bearssl prep z 1 "bearssl-${V_SSL} ${M_SSL};h=${V_SSL}" \ ; _AUTOFOO=skip; _PREPARE=skip; _INSTALL=$(cat <<'EOF' mkdir -p ${sdir}/bin; mkdir -p ${sdir}/include; mkdir -p ${sdir}/lib; cp $(find build -mindepth 1 -maxdepth 1 \ -type f ! -name "*.*") ${sdir}/bin; cp $(find build -mindepth 1 -maxdepth 1 \ -type f -name "*.a") ${sdir}/lib; cp $(find inc -mindepth 1 -maxdepth 1 \ -type f ) ${sdir}/include; EOF ); _IGNB="-ik"; # client/server not necessary bake; #--------------------------------------------------------------- # curl ## NOTES # # The forced early failure of 'getifaddrs' is to prevent the # 'configure' check from running; it hangs in some environments. # This "feature" is not currently used for anything we need. # # See also: # # * https://git.adelielinux.org/adelie/bootstrap/-/issues/11 # * https://gitlab.com/qemu-project/qemu/-/issues/2485 # prep J 1 ${M_CRL}/curl-${V_CRL}.tar.xz \ ; _PREPARE=$(cat <<'EOF' sed -i ../configure -e 's/return getifaddrs/return NX_FUNCTION/g'; ../configure \ --prefix="${sdir}" \ --disable-shared \ --enable-static \ --disable-nls \ --without-ssl \ --with-bearssl \ ; EOF ); bake; #--------------------------------------------------------------- # gdb ## NOTES # # Temporarily disabled due to insufficient platform support. # if false; then prep J 1 ${M_GNU}/gdb/gdb-${V_GDB}.tar.xz \ --disable-shared \ --enable-static \ --disable-nls \ ; bake; fi #--------------------------------------------------------------- # libexpat ## NOTES # # We strip two (2) levels here instead of changing into 'expat/' # in the top level for convenience and simplicity. This is also # a dependency for Git. # prep z 2 "libexpat-${V_XPT} ${M_XPT}/${V_XPT}.tar.gz" \ --disable-shared \ --enable-static \ ; bake; #--------------------------------------------------------------- # git ## NOTES # # Normally, one might elect to use 'configure' and pass along: # # --with-curl={,yes,/path/to/curl/root} # # except the Autotools-related files appear to be defective. Use # of 'autoreconf -i' and recent Autotools does not resolve this. # # The solution is therefore: trust that {CPP,C,LD}FLAGS are used # correctly and just build. Installation requires 'prefix' to be # specified as this is not populated without a 'configure'. # prep J 1 ${M_GIT}/git-${V_GIT}.tar.xz \ ; _AUTOFOO=skip; _PREPARE=skip; _COMPILE=skip; _INSTALL=$(cat <<'EOF' make ${_OUTSYNC} ${_IGNI} -j${_NPROC} prefix="${sdir}" install \ NO_GETTEXT=1 \ NO_OPENSSL=1 \ NO_REGEX=NeedsStartEnd \ INSTALL=install \ TAR=tar \ ; EOF ); bake; #=============================================================== # Stage 4: Optional Useful Utilities #=============================================================== #--------------------------------------------------------------- # bc ## NOTES # # For now, this 'bc' does not support out-of-tree builds. # The C compiler defaults to literal 'c99' and we must override. # It does not ignore unrecognized options, either. # prep z 1 "bc-${V_HBC} ${M_HBC}/${V_HBC}.tar.gz" \ ; _PREPARE=$(cat <<'EOF' CC=gcc ../configure --prefix="${sdir}"; EOF ); bake; #--------------------------------------------------------------- # parallel prep j 1 ${M_GNU}/parallel/parallel-${V_PAR}.tar.bz2 \ ; bake; #--------------------------------------------------------------- # perl ## NOTES # # The reason for 'perl-cross' is to better support an autotools- # style build environment. Without it, I experienced difficulty # in building Perl on numerous platforms but can't recall how. # prep z 1 ${M_PRL}/${V_PRL%%.*}.0/perl-${V_PRL}.tar.gz \ ; _AUTOFOO=skip; _PREPARE=$(cat <<'EOF' ${DRSO} https://github.com/arsv/perl-cross/releases/download\ /${V_PCR}/perl-cross-${V_PCR}.tar.gz \ | tar --strip-components=1 -xzf - \ ; # https://www.openwall.com/lists/musl/2012/03/09/18 CFLAGS="-D_GNU_SOURCE" \ ./configure --prefix="${sdir}"; EOF ); bake; #--------------------------------------------------------------- # hostname ## # In lieu of the 'net-tools' package, we approximate 'hostname' # using a very simple C program by Michael Kerrisk. # test -f "${sdir}/bin/hostname" || ${DRSO} https://man7.org/tlpi\ /code/online/dist/namespaces/hostname.c \ | gcc -o "${sdir}/bin/hostname" -x c - \ 2>/dev/null 1>/dev/null; #--------------------------------------------------------------- # ldd ## # Do not depend on this to exist on the build system. Instead, a # super basic wrapper is made; 'objdump -p' could be used, too. # test -f "${sdir}/bin/ldd" || cat > "${sdir}/bin/ldd" </dev/null -- musl; then "${gen2}/lib/libc.so" --list "\${@}"; else for k in "\${@}"; do LD_TRACE_LOADED_OBJECTS=1 "\${k}"; done fi EOF chmod +x "${sdir}/bin/ldd"; #--------------------------------------------------------------- # soggy ## # This makes it possible to 'chroot' into 'sys/' directory, but # needs to be run each time the 'sys/' directory is updated. We # install a new "utility" called 'soggy'. # # TODO: test this on other platforms. # FIXME: make this recursive (or find a better solution). # test -f "${sdir}/bin/soggy" || cat > "${sdir}/bin/soggy" </dev/null \ | "${sdir}/bin/grep" -oE '/.*\ ' \ | sort \ | uniq \ | while read k; do "${sdir}/bin/cp" -n --parents "\${k}" "${sdir}"; list="\${list} \${k}"; done # level 2 "${sdir}/bin/ldd" \${list} 2>/dev/null \ | "${sdir}/bin/grep" -oE '/.*\ ' \ | sort \ | uniq \ | while read k; do "${sdir}/bin/cp" -n --parents "\${k}" "${sdir}"; list="\${list} \${k}"; done # level 3 "${sdir}/bin/ldd" \${list} 2>/dev/null \ | "${sdir}/bin/grep" -oE '/.*\ ' \ | sort \ | uniq \ | while read k; do "${sdir}/bin/cp" -n --parents "\${k}" "${sdir}"; list="\${list} \${k}"; done EOF chmod +x "${sdir}/bin/soggy"; #--------------------------------------------------------------- # (GLOBAL) ## # Create a '.bashrc' for the 'chroot'. Unused otherwise. # if ! test -d "${sdir}/root"; then mkdir -p "${sdir}/root"; test -f "${sdir}/root/.bashrc" || cat > "${sdir}/root/.bashrc" < int main (void) { printf("hello\n"); return 0; } EOF if ! test -f "${sdir}/bin/hello" \ || test "$(${sdir}/bin/hello)" != "hello"; then if ! test -n "${ARCH}"; then cat < config.mak "%s\n" "${__conf}"; sed -i "config.mak" \ -e "s@__USER__@${_BUILD}@" \ -e "s@__HOST__@${_BUILD}@" \ -e "s@__TARG__@${ARCH}@" \ \ -e "s@__GCC_VER__@${V_GCC}@" \ -e "s@__BINUTILS_VER__@${V_BUT}@" \ -e "s@__MUSL_VER__@git-${V_MLC}@" \ -e "s@__GMP_VER__@${V_GMP}@" \ -e "s@__MPC_VER__@${V_MPC}@" \ -e "s@__MPFR_VER__@${V_MPF}@" \ -e "s@__LINUX_VER__@${V_KRN}@" \ ; EOF ); _COMPILE=$(cat <<'EOF' make TARGET=${ARCH} ${_OUTSYNC} -j"${_NPROC}"; EOF ); _INSTALL=$(cat <<'EOF' make TARGET=${ARCH} OUTPUT="${gen3}" install; EOF ); bake; unset __conf; ( cd "${bin3}"; for k in $("${sdir}/bin/find" . -type f -printf '%P\n'); do __link=${k#${ARCH}-*}; test -f ${__link} || ln -s ${k} ${__link}; done test -h cc || ln -s ${ARCH}-cc cc; ) cat <