diff options
-rw-r--r-- | binsub.c | 50 | ||||
-rwxr-xr-x | bootstrap | 82 | ||||
-rwxr-xr-x | setup-abuild | 57 | ||||
-rwxr-xr-x | setup-packages | 4 |
4 files changed, 135 insertions, 58 deletions
@@ -1,7 +1,7 @@ /** - * binsub.c / 2022-12-09 + * binsub.c / 2025-02-23 * - * (C) 2022 Zach van Rijn <me@zv.io> + * (C) 2022-2025 Zach van Rijn <me@zv.io> * * MIT License * @@ -18,6 +18,8 @@ #include <stdio.h> #include <string.h> #include <stdlib.h> +#include <sys/types.h> +#include <sys/stat.h> /** * Basic memory structure. @@ -145,17 +147,40 @@ scanner (const char *file, const char *find, const char *repl) FILE *fp = NULL; size_t nb = 0; + struct stat st; + mode_t pold, pnew; + struct buffer buf; memset(&buf, 0, sizeof(struct buffer)); - fp = fopen(file, "rb+"); + if (stat(file, &st) == -1) + { + fprintf(stderr, + "E: Could not stat FILE '%s' at all!\n", + file + ); + return; + } + + pold = st.st_mode; /* don't want to modify this */ + pnew = pold | S_IWUSR; /* could be read-only file */ + + if (chmod(file, pnew) == -1) + { + fprintf(stderr, + "E: Could not chmod FILE '%s' for writing!\n", + file + ); + } + + fp = fopen(file, "rb"); if (!fp) { fprintf(stderr, "E: Could not open FILE '%s' for reading!\n", file ); - return; + goto restore; } fseek(fp, 0, SEEK_END); @@ -175,7 +200,7 @@ scanner (const char *file, const char *find, const char *repl) buf.len, file ); - return; + goto restore; } buf.data[buf.len] = 0; /* extra byte needs to be nil */ @@ -191,7 +216,7 @@ scanner (const char *file, const char *find, const char *repl) buf.len, file ); - return; + goto restore; } fclose(fp); @@ -205,7 +230,7 @@ scanner (const char *file, const char *find, const char *repl) "E: Could not open FILE '%s' for writing!\n", file ); - return; + goto restore; } nb = fwrite(buf.data, 1, buf.len, fp); @@ -220,11 +245,20 @@ scanner (const char *file, const char *find, const char *repl) buf.len, file ); - return; + goto restore; } fclose(fp); free(buf.data); + +restore: + if (chmod(file, pold) == -1) + { + fprintf(stderr, + "E: Could not restore FILE '%s' permissions!\n", + file + ); + } } @@ -5,7 +5,7 @@ # Purpose : Bootstraps Adélie from source for any architecture. # Authors : Zach van Rijn <me@zv.io> # License : MIT -# Revision : 20240807 +# Revision : 20250225 #=============================================================== #=============================================================== @@ -329,17 +329,23 @@ EOF case "${1}" in # adelie gcc qemu # ------ --- ---- - aarch64) m=aarch64: ; q=aarch64 ; ;; - armv7) m=armv7l:eabihf ; q=arm ; ;; - ppc) m=powerpc: ; q=ppc ; ;; - ppc64) m=powerpc64: ; q=ppc64 ; ;; - x86_64) m=x86_64: ; q=x86_64 ; ;; - pmmx) m=i586: ; q=i386 ; ;; - - m68k) m=m68k: ; q=m68k ; ;; - mips64) m=mips64: ; q=mips64 ; ;; - riscv64) m=riscv64: ; q=riscv64 ; ;; - s390x) m=s390x: ; q=s390x ; ;; + aarch64) m=aarch64: ; q=aarch64 ; ;; + armv7) m=armv7l:eabihf ; q=arm ; ;; + ppc) m=powerpc: ; q=ppc ; ;; + ppc64) m=powerpc64: ; q=ppc64 ; ;; + x86_64) m=x86_64: ; q=x86_64 ; ;; + pmmx) m=i586: ; q=i386 ; ;; + + loongarch64) m=loongarch64: ; q=loongarch64 ; ;; + m68k) m=m68k: ; q=m68k ; ;; + mips64) m=mips64: ; q=mips64 ; ;; + mips64el) m=mips64el: ; q=mips64el ; ;; + mips) m=mips: ; q=mips ; ;; + mipsel) m=mipsel: ; q=mipsel ; ;; + ppc64le) m=powerpc64le: ; q=ppc64le ; ;; + riscv64) m=riscv64: ; q=riscv64 ; ;; + riscv32) m=riscv32: ; q=riscv32 ; ;; + s390x) m=s390x: ; q=s390x ; ;; *) usage ;; esac @@ -409,7 +415,7 @@ if ! test -d "${MTOOLS}"/sys/emus/bin; then # FIXME: no hard code test -d bootstrap \ || git clone ${CHAINS}/bootstrap.git; cd bootstrap; - git checkout 320f914d93f6547e223d8efc5a59a968df3bd4ee; + git checkout 185a90045d8e6ac414971ae7729319ad1534295c; ## seed rootfs # @@ -444,6 +450,12 @@ if ! test -d "${MTOOLS}"/sys/emus/bin; then # FIXME: no hard code cat >> "${MTOOLS}"/config.mak <<"EOF" # __SENTINEL__ +# must be supported by musl-cross-make +CONFIG_SUB_REV = 00b159274960 + +# override musl-cross-make as necessary +GCC_CONFIG += --disable-default-pie + # supported targets ifneq ($(findstring aarch64-,$(TARGET)),) GCC_CONFIG += --with-arch=armv8-a --with-abi=lp64 --enable-fix-cortex-a53-835769 --enable-fix-cortex-a53-843419 @@ -470,8 +482,12 @@ GCC_CONFIG += --with-arch=i586 --with-tune=pentium2 --enable-cld --enable-mmx endif # experimental targets +ifneq ($(findstring loongarch64-,$(TARGET)),) +GCC_CONFIG += --with-arch=loongarch64 +endif + ifneq ($(findstring m68k-,$(TARGET)),) -GCC_CONFIG += --with-arch=m68k --with-cpu=m68020 --disable-default-pie +GCC_CONFIG += --with-arch=m68k --with-cpu=m68020 endif ifneq ($(findstring mips64-,$(TARGET)),) @@ -664,6 +680,7 @@ if ! test -d mcmtools-${TARGET}/sys/tc/musl/bin; then # FIXME: no hard code PROOT_NO_SECCOMP=1 \ PATH="/tc/native/bin:${DEF_PATH}" \ LD_LIBRARY_PATH=/tc/native/lib \ +LIBRARY_PATH=/tc/native/lib \ SHELL=/bin/sh \ BASE="${BASE}" \ DEST="${BASE}"/mcmtools-${TARGET} \ @@ -729,6 +746,13 @@ ${MTOOLS}/sys/emus/bin/proot \ # cd "${BASE}"; if ! test -f rootfs-${TARGET}.tgz; then + + find mcmtools-${TARGET}/sys \ + -mindepth 1 -maxdepth 1 -type f -name '._*' -delete \ + ; + + rm -fr mcmtools-${TARGET}/sys/tc; + tar -C mcmtools-${TARGET}/sys \ -pczf rootfs-${TARGET}.tgz \ . \ @@ -759,29 +783,19 @@ if ! test -f rootfs-${TARGET}-patched.tgz; then ; ## - # Replace needle with the empty string. + # Maintain needle length but canonically replace with '/'. + # Length requirement only seems to affect 'perl'; truncating + # appears to be sufficient for all other binaries and files. + # Please refer to #26 for more information. # - x="${BASE}"/mcmtools-${TARGET}/sys; - grep -rl "${x}" ${t} | while read k; do - # exceptions - - case "${k}" in - "${t}"/bin/perl) continue; ;; # @INC fuckery - esac - - # delete needle - ./binsub ${k} "${x}"; # alternatively use "/" - + for d in glue sys; do + a="${BASE}"/mcmtools-${TARGET}/${d}; + b=$(printf "%${#a}s" | tr ' ' '/'); + grep -rl "${a}" ${t} | while read k; do + ./binsub "${k}" "${a}" "${b}"; + done done - ## - # Create a compatibility symlink so that any tools excepted - # above can still find the file(s) they need. - # - mkdir -p "${t}/${x%/*}"; - ln -s / "${t}/${x}"; # compat symlink for exceptions - - tar -C "${t}" \ -pczf rootfs-${TARGET}-patched.tgz \ . \ diff --git a/setup-abuild b/setup-abuild index e59ec41..d57cb56 100755 --- a/setup-abuild +++ b/setup-abuild @@ -15,7 +15,7 @@ cd "${DEST}"; # this directory will already exist if correct # so that we do not have to force building static musl binaries. # nmus=musl; -vmus=1.2.3; +vmus=1.2.5; test ! -f ._${nmus}-${vmus} && \ ( test ! -d ${nmus}-${vmus} \ @@ -101,7 +101,6 @@ test ! -f ._${nbld}-${vbld} && \ cd abuild-${vbld}; git checkout ${vbld}; while read k; do curl -sL ${k} | patch -p1 || true; done <<EOF -http://ix.io/4ifN https://git.alpinelinux.org/abuild/patch/abuild.in?id=f263cb9f49f3861f3141c22a74360b06cec7b868 EOF rm -fr x; mkdir x; cd x; @@ -132,12 +131,12 @@ rm -fr ${nbld}-${vbld}; # util-linux (for 'getopt' used by 'abuild-keygen') # nutl=util-linux; -vutl=08431acdf5b3accd0887ab550bfa4efabed751d6; +vutl=139980a5969bf851feda873fe918f34bee8fc055; test ! -f ._${nutl}-${vutl} && \ ( test ! -d ${nutl}-${vutl} \ && mkdir ${nutl}-${vutl} \ - && git clone https://github.com/karelzak/${nutl}.git ${nutl}-${vutl} \ + && git clone https://github.com/util-linux/${nutl}.git ${nutl}-${vutl} \ ; cd ${nutl}-${vutl}; git checkout ${vutl}; @@ -148,6 +147,7 @@ test ! -f ._${nutl}-${vutl} && \ --host="$(${CC} -dumpmachine)" \ --enable-static \ --disable-shared \ + --disable-liblastlog2 \ ; sed -i Makefile \ -e 's/chgrp/-chgrp/g' \ @@ -192,16 +192,16 @@ rm -fr ${npkg}-${vpkg}; # samurai (ninja replacement) # nsam=samurai; -vsam=4cc8f4a3654b72c977e0e62367d1ab6d5b873def; +vsam=67b3dc5309142b06404eca8084b8c048bb69f0f4; test ! -f ._${nsam}-${vsam} && ( test ! -d ${nsam}-${vsam} \ && git clone https://github.com/michaelforney/${nsam}.git ${nsam}-${vsam} \ ; cd ${nsam}-${vsam}; + git checkout ${vsam}; make -j$(nproc) install \ PREFIX="" \ - LDFLAGS="-static" \ DESTDIR="${DEST}" \ ; @@ -219,7 +219,7 @@ rm -fr ${nsam}-${vsam}; # The requested URL returned error: 500 # nmun=muon; -vmun=834460da03dd4a0c5b4570ca905780ce191c2443; +vmun=f5000cc37912e9e1b97851f841cd9be0aa0ccb24; test ! -f ._${nmun}-${vmun} && ( test ! -d ${nmun}-${vmun} \ @@ -233,8 +233,7 @@ test ! -f ._${nmun}-${vmun} && ./bootstrap.sh \ bootstrap \ ; - bootstrap/muon setup \ - -Dstatic=true \ + bootstrap/muon-bootstrap setup \ build \ ; samu -C build; @@ -258,6 +257,7 @@ test ! -f ._${natl}-${vatl} && \ && git clone https://git.alpinelinux.org/${natl} ${natl}-${vatl} \ ; cd ${natl}-${vatl}; + git checkout ${vatl}; sed -i Make.rules \ -e '/targets += $(__shlibs) $(shobjs)/d' \ ; # disable shared libs @@ -308,7 +308,7 @@ rm -fr ${natl}-${vatl}; # pax-utils # npax=pax-utils; -vpax=974b9359c2f89d57e69598572aafcd8f920d79e2; +vpax=9ef54b472e42ba2c5479fbd86b8be2275724b064; test ! -f ._${npax}-${vpax} && \ ( test ! -d ${npax}-${vpax} \ @@ -345,6 +345,7 @@ https://git.alpinelinux.org/aports/plain/main/fakeroot/fakeroot-no64.patch?id=bb https://git.alpinelinux.org/aports/plain/main/fakeroot/fakeroot-stdint.patch?id=bb497eeb2155d0332284942105692bc05fec25a9 https://git.alpinelinux.org/aports/plain/main/fakeroot/fix-format.patch?id=bb497eeb2155d0332284942105692bc05fec25a9 https://git.alpinelinux.org/aports/plain/main/fakeroot/fix-shell-in-fakeroot.patch?id=bb497eeb2155d0332284942105692bc05fec25a9 +https://git.adelielinux.org/adelie/packages/-/raw/bc7fcd1b36a697ab8ce5fd6ace425a9143330dce/system/fakeroot/xstatjunk.patch EOF ./bootstrap; f=$(mktemp); # needed due to "error: unknown type name 'cap_user_header_t'" @@ -352,7 +353,8 @@ EOF cat libfakeroot.c >> ${f}; mv ${f} libfakeroot.c; rm -fr x; mkdir x; cd x; - CFLAGS="-static -D_STAT_VER=0 $CFLAGS" \ + # If CFLAGS has '-static', .so files are not installed! + CFLAGS="-D_STAT_VER=0 $CFLAGS" \ ../configure \ --prefix="${DEST}" \ --host="$(${CC} -dumpmachine)" \ @@ -370,7 +372,7 @@ rm -fr ${nfrt}-${vfrt}; # attr # natt=attr; -vatt=2979615e71fb53b3f2f9085eea516d4e2b3174ea; +vatt=8a80d895dfd779373363c3a4b62ecce5a549efb2; test ! -f ._${natt}-${vatt} && ( test ! -d ${natt}-${vatt} \ @@ -390,3 +392,34 @@ test ! -f ._${natt}-${vatt} && ) touch ._${natt}-${vatt}; rm -fr ${natt}-${vatt}; + + +## +# libarchive +# +nlar=libarchive; +vlar=0348e24bab24cc46642d29e3ceab64df22553298; # until autoconf 2.71 +test ! -f ._${nlar}-${vlar} && +( + test ! -d ${nlar}-${vlar} \ + && git clone https://github.com/libarchive/${nlar}.git ${nlar}-${vlar} \ + ; + cd ${nlar}-${vlar}; + git checkout ${vlar}; + autoreconf -fiv; + CFLAGS="-static" \ + ./configure \ + --prefix="${DEST}" \ + --host="$(${CC} -dumpmachine)" \ + --enable-static \ + --disable-shared \ + ; + make -j$(nproc) install; + # These are required by 'abuild' instead of GNU tar. + # Note that 'cat' will break the mcmtools 'bootstrap'. + for k in cpio tar; do + ln -sf bsd${k} "${DEST}"/bin/${k}; + done +) +touch ._${nlar}-${vlar}; +rm -fr ${nlar}-${vlar}; diff --git a/setup-packages b/setup-packages index 4206b58..bd6cdbf 100755 --- a/setup-packages +++ b/setup-packages @@ -7,7 +7,3 @@ pwd; git clone https://git.adelielinux.org/adelie/packages.git; cd packages; git checkout current; - -# FIXME: this script needs a lot of work -#./scripts/bootstrap.sh ${TARGET_ARCH}; -bash |