mrrl

Minimal Reliable Reproducible Linux
git clone https://ccx.te2000.cz/git/mrrl
Log | Files | Refs | Submodules | README

musl-cross-make (8652B)


      1 #!/usr/bin/env pthbs-build
      2 #@pragma:nofail_digest
      3 #+musl-cross-make.9be7a57aa0035ff26870115e69056e25445f3a96768a7d81251e7073630aadf9
      4 #+gnu-make.05bfcd168c0d3714ecba9e27d84e02bfd2ef8f754c26c162be357882390451fc
      5 #+busybox.23105cf3c52263661c44f7d855ae5dfc7287f5f8b60d6a026dedee24f4cf7a2e
      6 #+nawk.abe3790fd5e321ccd4e1ab7dab56339222e2eee686bc4b2241e7853104a4a500
      7 #@sha256:0cdd76777a0dfd3dd3a63f215f030208ddb91c2361d2bcc02acec0f1c16b6a2e:musl-cross-make/sources/binutils-2.44.tar.gz
      8 #@sha256:a3c2b80201b89e68616f4ad30bc66aee4927c3ce50e33929ca819d5c43538898:musl-cross-make/sources/gmp-6.3.0.tar.xz
      9 #@sha256:b67ba0383ef7e8a8563734e2e889ef5ec3c3b898a01d00fa0a6869ad81c6ce01:musl-cross-make/sources/mpfr-4.2.2.tar.xz
     10 #@sha256:9b607166a1c999d8326098121222feb080a20a3253975fcdfa2de96ba7f757a7:musl-cross-make/sources/linux-6.17.tar.xz
     11 #@sha256:ab642492f5cf882b74aa0cb730cd410a81edcdbec895183ce930e706c1c759b8:musl-cross-make/sources/mpc-1.3.1.tar.gz
     12 #@sha256:9c4ce6dbb040568fdc545588ac03c5cbc95a8dbf0c7aa490170843afb59ca8f5:musl-cross-make/sources/gcc-13.4.0.tar.xz
     13 #@sha256:a9a118bbe84d8764da0ea0d28b3ab3fae8477fc7e4085d90102b8596fc7c75e4:musl-cross-make/sources/musl-1.2.5.tar.gz
     14 #@sha256:75d5d255a2a273b6e651f82eecfabf6cbcd8eaeae70e86b417384c8f4a58d8d3:musl-cross-make/sources/config.sub
     15 #@sha256:4213e75809588e3f32ae0fde8fb11df2dfd6e0e013762ff5ee951c3aadb7ffc0:musl-cross-make/patches/linux-6.17/0001-no-rsync-headers.diff
     16 #@sha256:68140a82582ede938159630bca0fb13a93b4bf1cb2e85b08943c26242cf8f3a6:musl-cross-make/zpipe.c
     17 #@git:cf9b601eba1b8c4a3c0655ba25d7fc8cfa365cbc:musl-cross-make
     18 
     19 
     20 # - build script start -
     21 
     22 prefix=/home/ccx/versions/$pthbs_package
     23 dest=${pthbs_destdir%/}${prefix}
     24 cd 'musl-cross-make'
     25 
     26 env
     27 which 'x86_64-linux-musl-g++'
     28 'x86_64-linux-musl-g++' --version
     29 
     30 # silence unpacking of tarballs
     31 sed -i -e 's|tar \([zjJ]\)xvf |tar \1xf |' ./Makefile
     32 
     33 cat >./config.mak <<EOF
     34 OUTPUT=${pthbs_destdir%/}/home/ccx/versions/$pthbs_package
     35 TARGET=x86_64-linux-musl
     36 GCC_VER=13.4.0
     37 EOF
     38 
     39 CC="x86_64-linux-musl-gcc -std=gnu17"
     40 printf '%s\n' >>config.mak '
     41 LINUX_VER=6.17
     42 st=-static --static
     43 fl=-g0 -O2
     44 COMMON_CONFIG += CFLAGS="${fl} ${st}"
     45 COMMON_CONFIG += CXXFLAGS="${fl} ${st}"
     46 COMMON_CONFIG += FFLAGS="${fl}" LDFLAGS="-s ${st}"
     47 COMMON_CONFIG += CC="x86_64-linux-musl-gcc -std=gnu17"
     48 COMMON_CONFIG += CXX="x86_64-linux-musl-g++ -std=gnu++11"
     49 MUSL_CONFIG += --enable-debug
     50 '
     51 
     52 test -f ./hashes/"gcc-13.4.0.tar.xz.sha1" || (
     53 	cd sources 
     54 	sha1sum "gcc-13.4.0.tar.xz" >../hashes/"gcc-13.4.0.tar.xz.sha1"
     55 )
     56 
     57 # make sure sources are considered fresh by make
     58 touch ./sources/*
     59 
     60 ${CC:-gcc} --version
     61 ${CC:-gcc} -dumpmachine
     62 cat -n config.mak
     63 
     64 # Patch linker path for dynamic executables
     65 make gcc-'13.4.0'
     66 sed -i -e 's|/lib/ld-musl-|/home/ccx/versions/'"$pthbs_package"'/x86_64-linux-musl/lib/ld-musl-|' ./gcc-'13.4.0'/gcc/config/*/linux*.h
     67 make -j${JOBS:-1} -l$((1+${JOBS:-1})) || make -d || exit $?
     68 make install || exit $?
     69 
     70 # Override linker symlink
     71 for linkname in "$dest"'/x86_64-linux-musl/lib/'ld-musl-*so*; do
     72 	ln -s -f libc.so "$linkname"
     73 done
     74 
     75 # Validate the C compiler
     76 "$dest"/bin/x86_64-linux-musl-gcc --version
     77 printf '%s\n' 'int main(void) { return 0; }' >true.c
     78 "$dest"/bin/x86_64-linux-musl-gcc -o true-dl true.c
     79 "$dest"/bin/x86_64-linux-musl-readelf --string-dump=.interp true-dl >true.linker
     80 grep -F "$pthbs_package" true.linker
     81 "$dest"/bin/x86_64-linux-musl-gcc -static -o true-sl true.c
     82 ./true-sl
     83 
     84 # Validate the C++ compiler
     85 "$dest"/bin/x86_64-linux-musl-g++ --version
     86 printf '%s\n' >sort.cpp '
     87 #include <iostream>
     88 #include <vector>
     89 #include <algorithm>
     90 #include <iterator>
     91 int main() {
     92        using namespace std;
     93        istream_iterator<int> first(cin);
     94        istream_iterator<int> last;
     95        vector<int> vec(first, last);
     96        sort(vec.begin(), vec.end());
     97        cout << "Sorted:" << endl;
     98        copy(vec.begin(), vec.end(), ostream_iterator<int>(cout, "\n"));
     99        return 0;
    100 }
    101 '
    102 "$dest"/bin/x86_64-linux-musl-g++ -o sort-dl sort.cpp
    103 "$dest"/bin/x86_64-linux-musl-readelf --string-dump=.interp sort-dl >sort.linker
    104 grep -F "$pthbs_package" sort.linker
    105 "$dest"/bin/x86_64-linux-musl-g++ -static -o sort-sl sort.cpp
    106 ./sort-sl >sort.out <<EOF
    107 5
    108 3
    109 1
    110 2
    111 4
    112 EOF
    113 printf '%s\n' >sort.expected Sorted: 1 2 3 4 5
    114 cmp sort.out sort.expected
    115 
    116 if which dejagnu 2>/dev/null; then
    117 	make -j${JOBS:-1} -l$((1+${JOBS:-1})) -C build/local/x86_64-linux-musl/obj_gcc -k check-gcc
    118 	mkdir "$dest/test-results"
    119 	find build/local/x86_64-linux-musl/obj_gcc \
    120 		-name '*.sum' -exec mv -v '{}' "$dest/test-results/" \;
    121 fi
    122 
    123 
    124 
    125 mkdir -p "$dest/library.so"
    126 dynlib_to_top="$(printf "%s\n" 'library.so' | sed -Ee "s!^\./!!; s![^/]+!..!g")"
    127 printf >>"$pthbs_workdir/link_to_dynlib" '%s\n' 'ln -s "'$dynlib_to_top'${1#.}" ''library.so'/
    128 ( cd "$dest" && find "./lib" "./x86_64-linux-musl" \
    129 	\( -type f -o -type l \) \( -name '*.so' -o -name '*.so.*' \) \
    130 	-exec sh -xe "$pthbs_workdir/link_to_dynlib" '{}' ';'
    131 )
    132 
    133 pkgs="gmp mpc mpfr zlib"
    134 #pkgs="$pkgs libbacktrace libcc1 libcpp libdecnumber libiberty lto-plugin"
    135 
    136 for pkg in $pkgs; do
    137 	make -C ./build/local/x86_64-linux-musl/obj_gcc/$pkg prefix=/ DESTDIR="$dest" install
    138 done
    139 cp -va ./gcc-*.orig/zlib/zconf.h ./gcc-*.orig/zlib/zlib.h "$dest/include/"
    140 mkdir -p "$dest/library/pkgconfig"
    141 printf '%s\n' > "$dest/library/pkgconfig/zlib.pc" \
    142 	"prefix=/home/ccx/versions/$pthbs_package" \
    143 	'exec_prefix=${prefix}' \
    144 	'includedir=${prefix}/include' \
    145 	'libdir=${exec_prefix}/library' \
    146 	'' \
    147 	'Name: zlib' \
    148 	'Description: zlib compression library' \
    149 	'Version: 1.2.11' \
    150 	'' \
    151 	'Requires:' \
    152 	'Libs: -L${libdir} -lz' \
    153 	'Cflags: -I${includedir}'
    154 
    155 
    156 
    157 
    158 # validate zlib
    159 "$dest"'/bin/x86_64-linux-musl-gcc' -I"$dest/include" -L"$dest/lib" -static -o zpipe zpipe.c -lz
    160 ./zpipe <true.c >true.c.gz
    161 ./zpipe -d <true.c.gz >true.c.2
    162 cmp -s true.c true.c.2
    163 
    164 
    165 mkdir -p "$dest/.env-template"
    166 printf '%s' >"$dest/.env-template"/'CPPFLAGS'  '-isystem @ENVROOT@/include'
    167 printf '%s' >"$dest/.env-template"/'LD_LIBRARY_PATH'  '@ENVROOT@/library.so'
    168 printf '%s' >"$dest/.env-template"/'LIBRARY_PATH'  '@ENVROOT@/library'
    169 mkdir -p "$dest/env"
    170 printf '%s' >"$dest/env"/'CFLAGS'  '-Og -g'
    171 printf '%s' >"$dest/env"/'CXXFLAGS'  '-Og -g'
    172 
    173 cd "$pthbs_destdir/home/ccx/versions/$pthbs_package"
    174 find -type d -o -print | awk -F/ '
    175 BEGIN {
    176 	x["./bin/x86_64-linux-musl-g++"]=1
    177 	x["./bin/x86_64-linux-musl-gcc"]=1
    178 
    179 	x["./lib/libgmp.a"]=1
    180 	x["./lib/libmpc.a"]=1
    181 	x["./lib/libmpfr.a"]=1
    182 	x["./lib/libz.a"]=1
    183 
    184 	x["./library.so/libc.so"]=1
    185 	x["./library.so/libgcc_s.so"]=1
    186 	x["./library.so/libstdc++.so"]=1
    187 
    188 	x["./include/gmp.h"]=1
    189 	x["./include/mpc.h"]=1
    190 	x["./include/mpf2mpfr.h"]=1
    191 	x["./include/mpfr.h"]=1
    192 	x["./include/zlib.h"]=1
    193 	x["./include/zconf.h"]=1
    194 
    195 	x["./x86_64-linux-musl/include/linux/landlock.h"]=1
    196 }
    197 
    198 function r1(s) {
    199 	sub("^[.]/[^/]*", ".", s)
    200 	return s
    201 }
    202 function s1(repl, s) {
    203 	sub("^[.]/[^/]*", "./"repl, s)
    204 	return s
    205 }
    206 function link(src) {
    207 	x[$0]=0
    208 	printf "%s\t%s\n", $0, src
    209 	printf "genlinks >>%s\t%s<<\n", $0, src >>"/dev/stderr"
    210 }
    211 $1!="."{exit 1}
    212 $2 == "bin" && $3 ~ /^x86_64-linux-musl-/ { target=$3; sub("x86_64-linux-musl-", "", target); link("./command/" target) }
    213 $2 == "x86_64-linux-musl" && $3 == "include" { link(s1("include", r1($0))) }
    214 
    215 $2 == "env" { link($0); next }
    216 $2 == ".env-template" { link($0); next }
    217 
    218 $2 == "command" { link($0); next }
    219 $2 == "command" { link($0); next }
    220 $2 == "bin" { link(s1("command", $0)); next }
    221 $2 == "sbin" { link(s1("command", $0)); next }
    222 
    223 $2 == "library.so" { link($0); next }
    224 $2 == "library" { link($0); next }
    225 $2 == "lib" && $NF ~ /\.l?a$/ { link(s1("library", $0)); next }
    226 $2 == "lib" && $NF ~ /\.so(\..*)?$/ { link(s1("library.so", $0)); next }
    227 
    228 $2 == "share" && $3 == "info" { link(s1("info", r1($0))); next }
    229 $2 == "share" && $3 == "man" { link(s1("man", r1($0))); next }
    230 $2 == "share" && $3 == "doc" { link(s1("doc", r1($0))); next }
    231 
    232 $2 == "config" { link($0); next }
    233 $2 == "man" { link($0); next }
    234 $2 == "info" { link($0); next }
    235 $2 == "doc" { link($0); next }
    236 $2 == "data" { link($0); next }
    237 $2 == "include" { link($0); next }
    238 
    239 $2 == "share" && $3 ~ /^(icons|terminfo)$/ { link(r1($0)); next }
    240 
    241 $2 == "library.ocaml" { link($0); next }
    242 
    243 $2 == "keys" { link($0); next }
    244 $2 == "zsh" { link($0); next }
    245 $2 == "vimfiles" { link($0); next }
    246 $2 == "icons" { link($0); next }
    247 $2 == "terminfo" { link($0); next }
    248 
    249 
    250 { printf "genlinks ##%s## skipped\n", $0 >>"/dev/stderr" }
    251 
    252 END {
    253 	for(fname in x) { printf "DEBUG: x[\"%s\"]=\"%s\"\n", fname, x[fname] >"/dev/stderr" }
    254 	retcode = 0
    255 	for(fname in x) {
    256 		if(x[fname]) {
    257 			printf "ERROR: missing expected file \"%s\"\n", fname >"/dev/stderr"
    258 			retcode = 3
    259 		}
    260 	}
    261 	exit retcode
    262 }' >.install-links.new
    263 mv .install-links.new .install-links
    264