mrrl

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

musl-cross-make (5714B)


      1 #!/usr/bin/env pthbs-build
      2 #+musl-cross-make.473310ee8dd6c0b20a1b81598700e61a0e38dcfe0b8503bd5cdbb9bf4f9af4fc
      3 #+gnu-make.47af7543e52e6b72ac25e13223e2ce78703c58993166ba25c56cba245e48dbfa
      4 #+busybox.cac0b85e179203f44ac2f1b50281f7cbe992094d779d6a2fc326b02d4a8461b5
      5 #@sha256:ab66fc2d1c3ec0359b8e08843c9f33b63e8707efdff5e4cc5c200eae24722cbf:musl-cross-make/sources/binutils-2.33.1.tar.xz
      6 #@sha256:75d5d255a2a273b6e651f82eecfabf6cbcd8eaeae70e86b417384c8f4a58d8d3:musl-cross-make/sources/config.sub
      7 #@sha256:d08edc536b54c372a1010ff6619dd274c0f1603aa49212ba20f7aa2cda36fa8b:musl-cross-make/sources/gcc-11.2.0.tar.xz
      8 #@sha256:5275bb04f4863a13516b2f39392ac5e272f5e1bb8057b18aec1c9b79d73d8fb2:musl-cross-make/sources/gmp-6.1.2.tar.bz2
      9 #@sha256:bdf76c15229b241e578046b8486106f09534d754ea4cbf105e0660e551fb1669:musl-cross-make/sources/linux-6.5.4.tar.xz
     10 #@sha256:6985c538143c1208dcb1ac42cedad6ff52e267b47e5f970183a3e75125b43c2e:musl-cross-make/sources/mpc-1.1.0.tar.gz
     11 #@sha256:c05e3f02d09e0e9019384cdd58e0f19c64e6db1fd6f5ecf77b4b1c61ca253acc:musl-cross-make/sources/mpfr-4.0.2.tar.bz2
     12 #@sha256:a9a118bbe84d8764da0ea0d28b3ab3fae8477fc7e4085d90102b8596fc7c75e4:musl-cross-make/sources/musl-1.2.5.tar.gz
     13 #@sha256:4213e75809588e3f32ae0fde8fb11df2dfd6e0e013762ff5ee951c3aadb7ffc0:musl-cross-make/patches/linux-6.5.4/0001-no-rsync-headers.diff
     14 #@sha256:68140a82582ede938159630bca0fb13a93b4bf1cb2e85b08943c26242cf8f3a6:zpipe.c
     15 #@git:6f3701d08137496d5aac479e3a3977b5ae993c1f:musl-cross-make
     16 
     17 
     18 # - build script start -
     19 
     20 prefix=/versions/$pthbs_package
     21 dest=${pthbs_destdir%/}${prefix}
     22 cd '.'
     23 
     24 # For validating the compiler
     25 printf '%s\n' 'int main(void) { return 0; }' >true.c
     26 
     27 printf '%s\n' >musl-cross-make/config.mak \
     28 	"OUTPUT=${pthbs_destdir%/}/versions/$pthbs_package" \
     29 	"TARGET=x86_64-linux-musl" \
     30 	'GCC_VER=11.2.0' \
     31 	'LINUX_VER=6.5.4' \
     32 	'st=-static --static' \
     33 	'fl=-g0 -O2' \
     34 	'COMMON_CONFIG += CFLAGS="${fl} ${st}" CXXFLAGS="${fl} ${st}" FFLAGS="${fl}" LDFLAGS="-s ${st}"' \
     35 	'COMMON_CONFIG += CC="x86_64-linux-musl-gcc ${st}" CXX="x86_64-linux-musl-g++ ${st}"'
     36 
     37 printf '%s  %s\n' >musl-cross-make/hashes/linux-6.5.4.tar.xz.sha1 \
     38 	24ffca128d47b6c8e5c15efaa2b1c9ebe546c13c  linux-6.5.4.tar.xz
     39 
     40 touch musl-cross-make/sources/*
     41 
     42 
     43 # Patch linker path for dynamic executables
     44 make -C musl-cross-make gcc-11.2.0
     45 sed -i -e 's|/lib/ld-musl-|/versions/'"$pthbs_package"'/x86_64-linux-musl/lib/ld-musl-|' musl-cross-make/gcc-11.2.0/gcc/config/*/linux*.h
     46 make -j${JOBS:-1} -l$((1+${JOBS:-1})) -C musl-cross-make || exit $?
     47 make -C musl-cross-make install || exit $?
     48 
     49 dd=$pthbs_destdir//versions/$pthbs_package
     50 
     51 # Override linker symlink
     52 for linkname in "$dd"'/x86_64-linux-musl/lib/'ld-musl-*so*; do
     53 	ln -s -f libc.so "$linkname"
     54 done
     55 
     56 # Validate the compiler
     57 "$dd"'/bin/x86_64-linux-musl-gcc' --version
     58 "$dd"'/bin/x86_64-linux-musl-gcc' -o true true.c
     59 "$dd"'/bin/x86_64-linux-musl-readelf' --string-dump=.interp true >true.linker
     60 grep -F "$pthbs_package" true.linker
     61 
     62 pkgs="gmp intl mpc mpfr zlib"
     63 #pkgs="$pkgs libbacktrace libcc1 libcpp libdecnumber libiberty lto-plugin"
     64 
     65 for pkg in $pkgs; do
     66 	make -C musl-cross-make/build/local/x86_64-linux-musl/obj_gcc/$pkg prefix=/ DESTDIR="$dd" install
     67 done
     68 cp -va musl-cross-make/gcc-*.orig/zlib/zconf.h musl-cross-make/gcc-*.orig/zlib/zlib.h "$dd/include/"
     69 mkdir -p "$dd/library/pkgconfig"
     70 printf '%s\n' > "$dd/library/pkgconfig/zlib.pc" \
     71 	"prefix=/versions/$pthbs_package" \
     72 	'exec_prefix=${prefix}' \
     73 	'includedir=${prefix}/include' \
     74 	'libdir=${exec_prefix}/library' \
     75 	'' \
     76 	'Name: zlib' \
     77 	'Description: zlib compression library' \
     78 	'Version: 1.2.11' \
     79 	'' \
     80 	'Requires:' \
     81 	'Libs: -L${libdir} -lz' \
     82 	'Cflags: -I${includedir}'
     83 
     84 
     85 # validate zlib
     86 "$dd"'/bin/x86_64-linux-musl-gcc' -I"$dd/include" -L"$dd/lib" -static -o zpipe zpipe.c -lz
     87 ./zpipe <true.c >true.c.gz
     88 ./zpipe -d <true.c.gz >true.c.2
     89 cmp -s true.c true.c.2
     90 
     91 
     92 
     93 cd "$pthbs_destdir/versions/$pthbs_package"
     94 find -type d -o -print | awk -F/ '
     95 BEGIN {
     96 	x["./bin/x86_64-linux-musl-g++"]=1
     97 	x["./bin/x86_64-linux-musl-gcc"]=1
     98 	x["./lib/libgmp.a"]=1
     99 	x["./lib/libmpc.a"]=1
    100 	x["./lib/libmpfr.a"]=1
    101 	x["./lib/libz.a"]=1
    102 
    103 	x["./include/gmp.h"]=1
    104 	x["./include/mpc.h"]=1
    105 	x["./include/mpf2mpfr.h"]=1
    106 	x["./include/mpfr.h"]=1
    107 	x["./include/zlib.h"]=1
    108 	x["./include/zconf.h"]=1
    109 
    110 }
    111 
    112 function r1(s) {
    113 	sub("^[.]/[^/]*", ".", s)
    114 	return s
    115 }
    116 function s1(repl, s) {
    117 	sub("^[.]/[^/]*", "./"repl, s)
    118 	return s
    119 }
    120 function link(src) {
    121 	x[$0]=0
    122 	printf "%s\t%s\n", $0, src
    123 	printf "genlinks >>%s\t%s<<\n", $0, src >>"/dev/stderr"
    124 }
    125 $1!="."{exit 1}
    126 
    127 
    128 $2 == "bin" && $3 ~ /^x86_64-linux-musl-/ { target=$3; sub("x86_64-linux-musl-", "", target); link("./command/" target) }
    129 
    130 $2 == "config" { link($0); next }
    131 $2 == "keys" { link($0); next }
    132 $2 == "zsh" { link($0); next }
    133 $2 == "env" { link($0); next }
    134 $2 == "command" { link($0); next }
    135 $2 == "bin" { link(s1("command", $0)); next }
    136 
    137 $2 == "library.so" { link($0); next }
    138 $2 == "library" { link($0); next }
    139 $2 == "lib" && $NF ~ /\.l?a$/ { link(s1("library", $0)); next }
    140 $2 == "lib" && $NF ~ /\.so(\..*)?$/ { link(s1("library.so", $0)); next }
    141 
    142 $2 == "share" && $3 ~ /^(info|man|doc|icons|terminfo)$/ { link(r1($0)); next }
    143 
    144 $2 == "man" { link($0); next }
    145 $2 == "info" { link($0); next }
    146 $2 == "doc" { link($0); next }
    147 $2 == "icons" { link($0); next }
    148 $2 == "terminfo" { link($0); next }
    149 $2 == "data" { link($0); next }
    150 $2 == "include" { link($0); next }
    151 
    152 { printf "genlinks ##%s## skipped\n", $0 >>"/dev/stderr" }
    153 
    154 END {
    155 	for(fname in x) { printf "DEBUG: x[\"%s\"]=\"%s\"\n", fname, x[fname] >"/dev/stderr" }
    156 	for(fname in x) {
    157 		if(x[fname]) {
    158 			printf "ERROR: missing expected file \"%s\"\n", fname >"/dev/stderr"
    159 			exit 3
    160 		}
    161 	}
    162 }' >.install-links.new
    163 mv .install-links.new .install-links
    164