galeb

Једноставна статичка дистрибуција заснована на musl-у
git clone https://git.sr.ht/~strahinja/galeb
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

01-cross.sh (31745B)


      1 #!/bin/sh
      2 
      3 . ./lib/env.sh
      4 . ./lib/fun.sh
      5 
      6 HOST_COREUTILS=1
      7 HOST_FIND=1
      8 HOST_SHASUM=1
      9 HOST_SED=1
     10 HOST_TAR=1
     11 export HOST_COREUTILS HOST_FIND HOST_SHASUM HOST_SED HOST_TAR
     12 
     13 mkdir -p ${G_LOG}
     14 :>${G_LOGFILE}
     15 :>${G_SHORTLOG}
     16 
     17 WD=${PWD}
     18 
     19 trap exit_cleanup HUP PIPE INT QUIT TERM EXIT
     20 
     21 totalsteps=3
     22 step=1
     23 
     24 cat art/galeb.ansi
     25 
     26 remove_file ${G_FIFO}
     27 
     28 begin_step cross-tools
     29 
     30 totalsubsteps=6
     31 substep=1
     32 
     33 check_dir ${CT}
     34 check_dir ${G_FIL}
     35 check_dir ${G_LGL}
     36 check_dir ${G_PAT}
     37 check_dir ${G_PKG}
     38 check_dir ${G_SRC}
     39 
     40 check_dir ${TL}
     41 check_dir ${TL}/bin
     42 check_dir ${TL}/lib
     43 
     44 check_dir ${G_SPKG}
     45 #check_dir ${G_SPKG}/X
     46 
     47 msg info "Creating directories"
     48 ./lib/createdirs 01-cross.sh || exit 1
     49 
     50 msg info "Creating symlinks"
     51 ./lib/createlinks 01-cross.sh || exit 1
     52 
     53 if [ ! -e /${CTD} ] && [ ! -e /${TLD} ]; then
     54 	msg info "Linking %s and %s to / (needs root)" ${CTD} ${TLD}
     55 	su -c 'ln -s '${CT}' /; ln -s '${TL}' /'
     56 fi
     57 
     58 cd_or_fail ${G_SRC}
     59 
     60 msg info "Copying additional files to %s" ${G_FIL}
     61 cp_or_fail -r ${WD}/${FLD}/* ${G_FIL}/
     62 
     63 msg info "Copying patches to %s" ${G_PAT}
     64 cp_or_fail -r ${WD}/${PTD}/* ${G_PAT}/
     65 
     66 msg info "Fetching packages and checking SHA sums"
     67 lineno=0
     68 totallines=$(wc -l ${WD}/lib/pkgs.tsv | cut -d ' ' -f1)
     69 totallines=$((totallines - 1))
     70 while read -r record
     71 do
     72 	perc=$((lineno * 100 / totallines))
     73 	printf "%3d%%\r" "${perc}"
     74 	[ ${lineno} -eq 0 ] || \
     75 	(
     76 	delay=2	# seconds between downloads; customize rate limiting
     77 	url=$(printf "${record}"   | cut -d  "$(printf '\t')" -f1)
     78 	dirtb=$(printf "${record}" | cut -sd "$(printf '\t')" -f2)
     79 	sha=$(printf "${record}"   | cut -sd "$(printf '\t')" -f3)
     80 
     81 	tarball=${url##*/}
     82 	if [ -n "${dirtb}" ]; then
     83 		tarball=${dirtb}
     84 	fi
     85 
     86 	case ${url} in
     87 		git:*|git+https:*)
     88 				git_clone "${dirtb}" ${url##git+} ${delay};;
     89 		ftp:*|http:*|https:*)
     90 				fetch_pkg ${url} "${dirtb}" ${delay};;
     91 		*)		;;
     92 	esac
     93 	if [ -n "${sha}" ]; then
     94 		if ! printf "%s  %s" "${sha}" "${G_PKG}/${tarball}" | \
     95 			sha512sum -c - >/dev/null 2>&1; then
     96 			msg err "SHA512 check failed on %s" ${tarball}
     97 			exit 1
     98 		fi
     99 	fi
    100 	) || exit 1
    101 	lineno=$((lineno+1))
    102 done <${WD}/lib/pkgs.tsv
    103 echo
    104 unset lineno totallines
    105 
    106 # msg info "Regenerating SHA sums"
    107 # (cd ${WD}; ${WD}/lib/gensums)
    108 
    109 begin_substep linux-6.2.10 "Linux headers"
    110 if [ -e ${CT}/${G_TARGET}/include/linux/stddef.h ]; then
    111 	msg info "%s exists, skipping %s" \
    112 		${CT}/${G_TARGET}/include/linux/stddef.h "${substepname}"
    113 else
    114 	extract_pkg ${G_SRC} ${pkg} ${pkg}.tar.xz
    115 	(
    116 		cd_or_fail ${G_SRC}/${pkg}
    117 		run_make ${JN} ARCH=${G_ARCH} headers
    118 		check_dir ${CT}/${G_TARGET}/include
    119 		cp_or_fail -r "usr/include/*" ${CT}/${G_TARGET}/include/
    120 		msg info "Removing *.cmd"
    121 		find ${CT}/${G_TARGET}/include -name '.*.cmd' -exec rm -f {} \;
    122 		rm ${CT}/${G_TARGET}/include/Makefile
    123 		#remove_dir ${G_SRC}/${pkg}
    124 	) || exit 1
    125 fi
    126 end_substep
    127 
    128 begin_substep binutils-2.40
    129 if [ -x ${CT}/${G_TARGET}/bin/ar ]; then
    130 	msg info "%s exists, skipping %s" "${CT}/${G_TARGET}/bin/ar" ${pkg}
    131 else
    132 	remove_dir ${G_SRC}/${pkg}
    133 	extract_pkg ${G_SRC} ${pkg} ${pkg}.tar.xz
    134 	(
    135 		cd_or_fail ${G_SRC}/${pkg}
    136 		remove_dir build
    137 		check_dir  build
    138 		cd_or_fail build
    139 		run_configure .. \
    140 			--prefix=${CT} \
    141 			--target=${G_TARGET} \
    142 			--with-sysroot=${CT}/${G_TARGET} \
    143 			--disable-nls \
    144 			--disable-multilib \
    145 			--disable-werror \
    146 			--enable-deterministic-archives \
    147 			--disable-compressed-debug-sections
    148 		run_make ${JN}
    149 		run_make install-strip
    150 	) || exit 1
    151 	#remove_dir ${G_SRC}/${pkg}
    152 fi
    153 end_substep
    154 
    155 begin_substep gcc-12.2.0 "static GCC"
    156 if [ -e ${CT}/gcc-static ]; then
    157 	msg info "%s exists, skipping %s" "${CT}/gcc-static" "${substepname}"
    158 else
    159 	:>${CT}/gcc-static
    160 remove_dir ${G_SRC}/${pkg}
    161 extract_pkg ${G_SRC} ${pkg} ${pkg}.tar.xz
    162 (
    163 	cd_or_fail ${G_SRC}/${pkg}
    164 
    165 	subpkg=libgmp-6.2.1
    166 	if [ -d gmp ]; then
    167 		msg info "Subpackage %s exists" "${subpkg}"
    168 	else
    169 		extract_pkg ${G_SRC}/${pkg} ${subpkg#lib} ${subpkg}.tar.xz gmp
    170 	fi
    171 
    172 	subpkg=libmpc-1.3.1
    173 	if [ -d mpc ]; then
    174 		msg info "Subpackage %s exists" "${subpkg}"
    175 	else
    176 		extract_pkg ${G_SRC}/${pkg} ${subpkg#lib} ${subpkg}.tar.gz mpc
    177 	fi
    178 
    179 	subpkg=libmpfr-4.2.0
    180 	if [ -d mpfr ]; then
    181 		msg info "Subpackage %s exists" "${subpkg}"
    182 	else
    183 		extract_pkg ${G_SRC}/${pkg} ${subpkg#lib} ${subpkg}.tar.xz mpfr
    184 	fi
    185 
    186 	remove_dir build
    187 	check_dir  build
    188 	cd_or_fail build
    189 
    190 	CFLAGS='-g0 -O0'
    191 	CXXFLAGS=${CFLAGS}
    192 	export CFLAGS CXXFLAGS
    193 
    194 	run_configure .. \
    195 		--prefix=/${CTD} \
    196 		--build=${G_HOST} \
    197 		--host=${G_HOST} \
    198 		--target=${G_TARGET} \
    199 		--with-sysroot=/${CTD}/${G_TARGET} \
    200 		--disable-nls \
    201 		--with-newlib \
    202 		--disable-libitm \
    203 		--disable-libvtv \
    204 		--disable-libssp \
    205 		--disable-shared \
    206 		--disable-libgomp \
    207 		--without-headers \
    208 		--disable-threads \
    209 		--disable-multilib \
    210 		--disable-libatomic \
    211 		--disable-libstdcxx \
    212 		--enable-languages=c \
    213 		--disable-libquadmath \
    214 		--disable-libsanitizer \
    215 		--with-arch=${G_ARCH_EXT} \
    216 		--disable-decimal-float \
    217 		--enable-clocale-generic
    218 
    219 	run_make ${JN} all-gcc all-target-libgcc
    220 	run_make install-gcc install-target-libgcc
    221 
    222 	unset CFLAGS CXXFLAGS
    223 ) || exit 1
    224 #remove_dir ${G_SRC}/${pkg}
    225 fi
    226 end_substep
    227 
    228 msg info "Setting environment"
    229 OLDPATH=${PATH}
    230 PATH=/${CTD}/bin:/${TLD}/bin:/bin:/usr/bin
    231 export PATH
    232 
    233 begin_substep musl-1.2.3
    234 if [ -e ${CT}/lib/ld-musl-${G_ARCH_EXT_ALT}.so.1 ]; then
    235 	msg info "%s exists, skipping %s" \
    236 		${CT}/lib/ld-musl-${G_ARCH_EXT_ALT}.so.1 ${pkg}
    237 else
    238 	extract_pkg ${G_SRC} ${pkg} ${pkg}.tar.gz
    239 	(
    240 		cd_or_fail ${G_SRC}/${pkg}
    241 		run_configure . \
    242 			CROSS_COMPILE=${G_TARGET}- \
    243 			--prefix=/ \
    244 			--target=${G_TARGET}
    245 		run_make ${JN}
    246 		DESTDIR=/${CTD}
    247 		export DESTDIR
    248 		run_make install
    249 		unset DESTDIR
    250 
    251 		check_dir ${CT}/usr
    252 		link_if_ne ../include ${CT}/usr/include
    253 
    254 		remove_file ${CT}/lib/ld-musl-${G_ARCH_EXT_ALT}.so.1
    255 		link_if_ne libc.so ${CT}/lib/ld-musl-${G_ARCH_EXT_ALT}.so.1
    256 
    257 		link_if_ne ../lib/ld-musl-${G_ARCH_EXT_ALT}.so.1 ${CT}/bin/ldd
    258 
    259 		check_dir ${CT}/etc
    260 		msg info "Generating %s" \
    261 			${CT}/etc/ld-musl-${G_ARCH_EXT_ALT}.path
    262 		cat <<! >${CT}/etc/ld-musl-${G_ARCH_EXT_ALT}.path
    263 /${CTD}/lib
    264 /${TLD}/lib
    265 !
    266 	) || exit 1
    267 fi
    268 end_substep
    269 
    270 begin_substep gcc-12.2.0 "final GCC"
    271 if [ -e ${CT}/gcc-final ]; then
    272 	msg info "%s exists, skipping %s" ${CT}/gcc-final "${substepname}"
    273 else
    274 	:>${CT}/gcc-final
    275 (
    276 	remove_dir ${G_SRC}/${pkg}
    277 	extract_pkg ${G_SRC} ${pkg} ${pkg}.tar.xz
    278 	cd_or_fail ${G_SRC}/${pkg}
    279 
    280 	msg info "Applying patches"
    281 	for n in 1 3 4 6 7 8 9 10 11 12 14 15 16 17 18 25 27 29 33 34 35 39
    282 	do
    283 		apply_patch gcc-final -Np1 -i \
    284 			${WD}/pat/gcc-alpine/$(printf "%04d" $n)-*.patch
    285 	done
    286 
    287 	check_dir  build
    288 	cd_or_fail build
    289 
    290 
    291 	printf "PATH=%s\n" "${PATH}"
    292 	printf "gcc=%s\n" $(which gcc)
    293 
    294 	AR=ar
    295 	LDFLAGS='-Wl,-rpath,/'${CTD}'/lib'
    296 	export AR LDFLAGS
    297 
    298 	run_configure .. \
    299 		--prefix=/${CTD} \
    300 		--build=${G_HOST} \
    301 		--host=${G_HOST} \
    302 		--target=${G_TARGET} \
    303 		--disable-multilib \
    304 		--with-sysroot=/${CTD} \
    305 		--disable-nls \
    306 		--enable-shared \
    307 		--enable-languages=c,c++ \
    308 		--enable-threads=posix \
    309 		--enable-clocale=generic \
    310 		--enable-libstdcxx-time \
    311 		--enable-fully-dynamic-string \
    312 		--disable-symvers \
    313 		--disable-libsanitizer \
    314 		--disable-lto-plugin \
    315 		--disable-libssp
    316 
    317 	run_make AS_FOR_TARGET=${G_TARGET}-as \
    318 		 LD_FOR_TARGET=${G_TARGET}-ld ${JN}
    319 	run_make install
    320 
    321 	unset AR LDFLAGS
    322 ) || exit 1
    323 fi
    324 end_substep
    325 
    326 LD_LIBRARY_PATH=/tools/lib:${LD_LIBRARY_PATH}
    327 export LD_LIBRARY_PATH
    328 
    329 begin_substep file-5.44
    330 if [ -x ${CT}/bin/file ]; then
    331 	msg info "%s exists, skipping %s" ${CT}/bin/file ${pkg}
    332 else
    333 	extract_pkg ${G_SRC} ${pkg} ${pkg}.tar.gz
    334 	(
    335 		cd_or_fail ${G_SRC}/${pkg}
    336 
    337 		run_configure . \
    338 			--prefix=/${CTD} --disable-libseccomp
    339 
    340 		run_make ${JN}
    341 		run_make install
    342 	) || exit 1
    343 	remove_dir ${G_SRC}/${pkg}
    344 fi
    345 end_substep
    346 
    347 end_step # cross-tools
    348 
    349 begin_step tools
    350 
    351 totalsubsteps=29
    352 substep=1
    353 
    354 begin_substep musl-1.2.3
    355 if [ -e ${TL}/lib/ld-musl-${G_ARCH_EXT_ALT}.so.1 ]; then
    356 	msg info "%s exists, skipping %s" \
    357 		${TL}/lib/ld-musl-${G_ARCH_EXT_ALT}.so.1 ${pkg}
    358 else
    359 	remove_dir ${G_SRC}/${pkg}
    360 	extract_pkg ${G_SRC} ${pkg} ${pkg}.tar.gz
    361 	(
    362 		cd_or_fail ${G_SRC}/${pkg}
    363 		run_configure . \
    364 			CROSS_COMPILE=${G_TARGET}- \
    365 			--prefix=/ \
    366 			--target=${G_TARGET}
    367 		run_make ${JN}
    368 		run_make DESTDIR=/${TLD} install
    369 
    370 		remove_file ${TL}/lib/ld-musl-${G_ARCH_EXT_ALT}.so.1
    371 		link_if_ne libc.so ${TL}/lib/ld-musl-${G_ARCH_EXT_ALT}.so.1
    372 
    373 		link_if_ne ../lib/ld-musl-${G_ARCH_EXT_ALT}.so.1 ${TL}/bin/ldd
    374 
    375 		check_dir ${TL}/etc
    376 		msg info "Generating %s" \
    377 			${TL}/etc/ld-musl-${G_ARCH_EXT_ALT}.path
    378 		cat <<! >${TL}/etc/ld-musl-${G_ARCH_EXT_ALT}.path
    379 /${TLD}/lib
    380 !
    381 	) || exit 1
    382 fi
    383 end_substep
    384 
    385 msg info "Adjusting cross-tools"
    386 SPECFILE=$(realpath $(dirname $(${G_TARGET}-gcc -print-libgcc-file-name)))/specs
    387 msg info "Specfile at %s" "${SPECFILE}"
    388 pwd
    389 ${G_TARGET}-gcc -dumpspecs > specs
    390 /bin/sed -i 's,:\(/lib/ld-musl-'${G_ARCH_EXT_ALT}'.so.1\),:/'${TLD}'\1,g' specs
    391 cat specs >>${G_LOGFILE}
    392 mv_or_fail specs ${SPECFILE}
    393 unset SPECFILE
    394 
    395 msg info "Test specs"
    396 echo 'int main(){}' > dummy.c
    397 ${G_TARGET}-gcc dummy.c
    398 interp=$(${G_TARGET}-readelf -l a.out | grep interpreter)
    399 remove_file a.out
    400 remove_file dummy.c
    401 if echo "${interp}" | grep "/${TLD}/lib/ld-musl-${G_ARCH_EXT_ALT}.so.1" \
    402 	>/dev/null 2>&1
    403 then
    404 	msg info "Specs look OK"
    405 else
    406 	msg err "Specs are not OK"
    407 	exit 1
    408 fi
    409 unset interp
    410 
    411 msg info "Setting environment (%s)" "${stepname}"
    412 CC=${G_TARGET}-gcc
    413 CXX=${G_TARGET}-g++
    414 AR=${G_TARGET}-ar
    415 AS=${G_TARGET}-as
    416 RANLIB=${G_TARGET}-ranlib
    417 LD=${G_TARGET}-ld
    418 STRIP=${G_TARGET}-strip
    419 export CC CXX AR AS RANLIB LD STRIP
    420 
    421 link_if_ne lib /${TLD}/lib64
    422 
    423 begin_substep binutils-2.40
    424 if [ -x ${TL}/${G_TARGET}/bin/ar ]; then
    425 	msg info "%s exists, skipping %s" ${TL}/${G_TARGET}/bin/ar ${pkg}
    426 else
    427 	remove_dir ${G_SRC}/${pkg}
    428 	extract_pkg ${G_SRC} ${pkg} ${pkg}.tar.xz
    429 	(
    430 		cd_or_fail ${G_SRC}/${pkg}
    431 		check_dir  build
    432 		cd_or_fail build
    433 		CFLAGS+=' -D__MUSL_LIBC '
    434 		export CFLAGS
    435 		run_configure .. \
    436 			--prefix=/${TLD} \
    437 			--with-lib-path=/${TLD}/lib \
    438 			--build=${G_HOST} \
    439 			--host=${G_TARGET} \
    440 			--target=${G_TARGET} \
    441 			--disable-nls \
    442 			--disable-werror \
    443 			--with-sysroot
    444 		run_make ${JN}  || exit 1
    445 		run_make install-strip || exit 1
    446 		run_make -C ld clean || exit 1
    447 		run_make -C ld ${JN} LIB_PATH=/usr/lib:/lib || exit 1
    448 		cp_or_fail ld/ld-new /${TLD}/bin
    449 	) || exit 1
    450 fi
    451 end_substep
    452 
    453 begin_substep gcc-12.2.0
    454 if [ -x /${TLD}/bin/gcc ]; then
    455 	msg info "%s exists, skipping %s" "/${TLD}/bin/gcc" ${pkg}
    456 else
    457 remove_dir ${G_SRC}/${pkg}
    458 extract_pkg ${G_SRC} ${pkg} ${pkg}.tar.xz
    459 (
    460 	cd_or_fail ${G_SRC}/${pkg}
    461 
    462 	subpkg=libgmp-6.2.1
    463 	if [ -d gmp ]; then
    464 		msg info "Subpackage %s exists" "${subpkg}"
    465 	else
    466 		extract_pkg ${G_SRC}/${pkg} ${subpkg#lib} ${subpkg}.tar.xz gmp
    467 	fi
    468 
    469 	subpkg=libmpc-1.3.1
    470 	if [ -d mpc ]; then
    471 		msg info "Subpackage %s exists" "${subpkg}"
    472 	else
    473 		extract_pkg ${G_SRC}/${pkg} ${subpkg#lib} ${subpkg}.tar.gz mpc
    474 	fi
    475 
    476 	subpkg=libmpfr-4.2.0
    477 	if [ -d mpfr ]; then
    478 		msg info "Subpackage %s exists" "${subpkg}"
    479 	else
    480 		extract_pkg ${G_SRC}/${pkg} ${subpkg#lib} ${subpkg}.tar.xz mpfr
    481 	fi
    482 
    483 	msg info "Applying patches"
    484 	for n in 1 3 4 6 7 8 9 10 11 12 14 15 16 17 18 25 27 29 33 34 35 39
    485 	do
    486 		apply_patch gcc-tools -Np1 -i \
    487 			${WD}/pat/gcc-alpine/$(printf "%04d" $n)-*.patch
    488 	done
    489 
    490 	apply_patch gcc-tools -Np1 -i ${WD}/pat/gcc-mlfs/fix_fenv_header.patch
    491 
    492 	msg info "Generating include-fixed/limits.h"
    493 	if ! cat gcc/limitx.h gcc/glimits.h gcc/limity.h > \
    494 		$(realpath $(dirname $(${G_TARGET}-gcc \
    495 			-print-libgcc-file-name)))/include-fixed/limits.h
    496 	then
    497 		msg err "Generating include-fixed/limits.h failed"
    498 		exit 1
    499 	fi
    500 
    501 	msg info "Modifying linux*.h"
    502 	for f in gcc/config/linux.h \
    503 		 gcc/config/i386/linux.h \
    504 		 gcc/config/i386/linux64.h
    505 	do
    506 		cp -u $f $f.orig
    507 		/bin/sed -e 's,/lib\(64\)\?\(32\)\?/ld,/'${TLD}'&,g' \
    508 		    -e 's,/usr,/'${TLD}',g' $f.orig > $f
    509 		cat <<'!' >>$f
    510 #undef STANDARD_STARTFILE_PREFIX_1
    511 #undef STANDARD_STARTFILE_PREFIX_2
    512 #define STANDARD_STARTFILE_PREFIX_1 "/${TLD}/lib/"
    513 #define STANDARD_STARTFILE_PREFIX_2 ""
    514 !
    515 		touch $f.orig
    516 	done
    517 
    518 	remove_dir build
    519 	check_dir  build
    520 	cd_or_fail build
    521 
    522 	CFLAGS='-g0 -O0'
    523 	CXXFLAGS=${CFLAGS}
    524 	export CFLAGS CXXFLAGS
    525 
    526 	run_configure .. \
    527 		--target=${G_TARGET} \
    528 		--build=${G_HOST} \
    529 		--host=${G_TARGET} \
    530 		--prefix=/${TLD} \
    531 		--with-local-prefix=/${TLD} \
    532 		--with-native-system-header-dir=/${TLD}/include \
    533 		--enable-languages=c,c++ \
    534 	        --disable-libstdcxx-pch \
    535 		--disable-multilib \
    536 		--disable-bootstrap \
    537 		--disable-libgomp \
    538 		--disable-libquadmath \
    539 		--disable-libssp \
    540 		--disable-libvtv \
    541 		--disable-symvers \
    542 		--disable-libitm \
    543 		--disable-libsanitizer
    544 
    545 	LOCALOLDPATH=${PATH}
    546 	PATH=/bin:/usr/bin:/${CTD}/bin:/${TLD}/bin
    547 	export PATH
    548 	run_make ${JN}
    549 	run_make install-strip
    550 
    551 	link_if_ne gcc /${TLD}/bin/cc
    552 
    553 	PATH=${LOCALOLDPATH}
    554 	export PATH
    555 	unset CFLAGS CXXFLAGS LOCALOLDPATH
    556 
    557 	msg info "Testing interpreter"
    558 	echo 'int main(){}' > dummy.c
    559 	gcc dummy.c
    560 	interp=$(readelf -l a.out | grep ': /'${TLD})
    561 	if echo "${interp}" | \
    562 		grep "/${TLD}/lib/ld-musl-${G_ARCH_EXT_ALT}.so.1" \
    563 			>/dev/null 2>&1
    564 	then
    565 		msg info "Specs look OK"
    566 	else
    567 		msg err "Specs are not OK: %s" "${interp}"
    568 		exit 1
    569 	fi
    570 	unset interp
    571 	remove_file a.out
    572 	remove_file dummy.c
    573 ) || exit 1
    574 #remove_dir ${G_SRC}/${pkg}
    575 fi
    576 end_substep
    577 
    578 begin_substep linux-6.2.10 "Linux headers"
    579 if [ -e /${TLD}/include/linux/stddef.h ]; then
    580 	msg info "%s exists, skipping %s" \
    581 		/${TLD}/include/linux/stddef.h "${substepname}"
    582 else
    583 	extract_pkg ${G_SRC} ${pkg} ${pkg}.tar.xz
    584 	(
    585 		cd_or_fail ${G_SRC}/${pkg}
    586 		run_make mrproper
    587 		run_make ARCH=${G_ARCH} headers
    588 		check_dir /${TLD}/include
    589 		cp_or_fail -r "usr/include/*" /${TLD}/include/
    590 		msg info "Removing *.cmd"
    591 		find /${TLD}/include -name '.*.cmd' -exec rm -f {} \;
    592 		rm /${TLD}/include/Makefile
    593 	) || exit 1
    594 fi
    595 end_substep
    596 
    597 PATH=/${TLD}/bin:/${CT}/bin:/usr/bin:/bin
    598 export PATH
    599 
    600 msg info "Adjusting tools"
    601 SPECFILE=$(realpath $(dirname $(${G_TARGET}-gcc -print-libgcc-file-name)))/specs
    602 msg info "Specfile at %s" "${SPECFILE}"
    603 ${G_TARGET}-gcc -dumpspecs > specs
    604 /bin/sed -i 's,:\(/lib/ld-musl-'${G_ARCH_EXT_ALT}'.so.1\),:/'${TLD}'\1,g' specs
    605 cat specs >>${G_LOGFILE}
    606 mv_or_fail specs ${SPECFILE}
    607 unset SPECFILE
    608 
    609 msg info "Test specs"
    610 echo 'int main(){}' > dummy.c
    611 ${G_TARGET}-gcc -B/tools/lib dummy.c
    612 interp=$(${G_TARGET}-readelf -l a.out | grep interpreter)
    613 remove_file a.out
    614 remove_file dummy.c
    615 if echo "${interp}" | grep "/${TLD}/lib/ld-musl-${G_ARCH_EXT_ALT}.so.1" \
    616 	>/dev/null 2>&1
    617 then
    618 	msg info "Specs look OK"
    619 else
    620 	msg err "Specs are not OK"
    621 	exit 1
    622 fi
    623 unset interp
    624 
    625 begin_substep gcc-12.2.0. libstdcxx
    626 if [ -e /${TLD}/share/gcc-12.2.0/python/libstdcxx ]; then
    627 	msg info "%s exists, skipping %s" \
    628 		"/${TLD}/share/gcc-12.2.0/python/libstdcxx" "${substepname}"
    629 else
    630 	(
    631 		#if ! tail -n1 /${TLD}/include/c++/12.2.0/fenv.h | \
    632 		#	grep '^#endif //fix error$' 2>/dev/null
    633 		#then
    634 		#	echo '#endif //fix error' \
    635 		#		>>/${TLD}/include/c++/12.2.0/fenv.h
    636 		#fi
    637 
    638 		cd_or_fail ${G_SRC}/${pkg}
    639 		remove_dir build
    640 		check_dir  build
    641 		cd_or_fail build
    642 
    643 		run_configure ../libstdc++-v3 \
    644 			--target=${G_TARGET} \
    645 			--build=${G_HOST} \
    646 			--host=${G_TARGET} \
    647 			--prefix=/${TLD} \
    648 			--disable-multilib \
    649 			--disable-nls \
    650 			--disable-libstdcxx-threads \
    651 			--disable-libstdcxx-pch \
    652 			--with-gxx-include-dir=/${TLD}/${G_TARGET}/include/c++/12.2.0
    653 
    654 		run_make ${JN}
    655 		run_make install
    656 	) || exit 1
    657 fi
    658 end_substep
    659 
    660 begin_substep make-4.4
    661 if [ -x ${TL}/bin/make ]; then
    662 	msg info "%s exists, skipping %s" ${TL}/bin/make ${pkg}
    663 else
    664 	extract_pkg ${G_SRC} ${pkg} ${pkg}.tar.gz
    665 	(
    666 		cd_or_fail ${G_SRC}/${pkg}
    667 		run_configure . \
    668 			--prefix=/${TLD} \
    669 			--build=${G_HOST} \
    670 			--host=${G_TARGET} \
    671 			--without-guile
    672 		run_make ${JN}
    673 		run_make install
    674 	) || exit 1
    675 	remove_dir ${pkg}
    676 fi
    677 end_substep
    678 
    679 begin_substep tcl8.6.13
    680 if [ -e ${TL}/lib/libtcl8.6.so ]; then
    681 	msg info "%s exists, skipping %s" ${TL}/lib/libtcl8.6.so ${pkg}
    682 else
    683 	extract_pkg ${G_SRC} ${pkg} ${pkg}-src.tar.gz
    684 	(
    685 		cd_or_fail ${G_SRC}/${pkg}
    686 		cd_or_fail unix
    687 
    688 		ac_cv_func_strtod=yes
    689 		tcl_cv_strtod_buggy=1
    690 		export ac_cv_func_strtod tcl_cv_strtod_buggy
    691 
    692 		run_configure . \
    693 			--build=${G_HOST} \
    694 			--host=${G_TARGET} \
    695 			--prefix=/${TLD}
    696 
    697 		run_make ${JN}
    698 		run_make install
    699 		chmod u+w ${TL}/lib/libtcl8.6.so
    700 		run_make install-private-headers
    701 		link_if_ne tclsh8.6 ${TL}/bin/tclsh
    702 
    703 		unset ac_cv_func_strtod tcl_cv_strtod_buggy
    704 	) || exit 1
    705 	remove_dir ${G_SRC}/${pkg}
    706 fi
    707 end_substep
    708 
    709 begin_substep m4-1.4.19
    710 if [ -x ${TL}/bin/m4 ]; then
    711 	msg info "%s exists, skipping %s" ${TL}/bin/m4 ${pkg}
    712 else
    713 	extract_pkg ${G_SRC} ${pkg} ${pkg}.tar.xz
    714 	(
    715 		cd_or_fail ${G_SRC}/${pkg}
    716 		run_configure . \
    717 			--prefix=/${TLD} \
    718 			--build=${G_HOST} \
    719 			--target=${G_TARGET}
    720 		run_make ${JN}
    721 		run_make install
    722 	) || exit 1
    723 	remove_dir ${G_SRC}/${pkg}
    724 fi
    725 end_substep
    726 
    727 begin_substep bzip2-1.0.8
    728 if [ -x ${TL}/bin/bzip2 ]; then
    729 	msg info "%s exists, skipping %s" ${TL}/bin/bzip2 ${pkg}
    730 else
    731 	extract_pkg ${G_SRC} ${pkg} ${pkg}.tar.gz
    732 	(
    733 		cd_or_fail ${G_SRC}/${pkg}
    734 		cp_or_fail Makefile Makefile.orig
    735 		/bin/sed '/^all:/s/ test//' Makefile.orig > Makefile
    736 		/bin/sed -i 's,\(ln -s -f \)$(PREFIX)/bin/,\1,' Makefile
    737 		/bin/sed -i 's,(PREFIX)/man,(PREFIX)/share/man,g' Makefile
    738 
    739 		run_make -f Makefile-libbz2_so CC=${CC} AR=${AR} \
    740 			RANLIB=${RANLIB} CFLAGS=-fPIC
    741 		run_make clean
    742 		run_make ${JN} CC=${CC} AR=${AR} RANLIB=${RANLIB} \
    743 			STRIP=${STRIP} CFLAGS=-fPIC
    744 		run_make PREFIX=/${TLD} install
    745 	) || exit 1
    746 	remove_dir ${G_SRC}/${pkg}
    747 fi
    748 end_substep
    749 
    750 # Sucky util-linux explicitly *requires* bison. And we need it for lsblk etc.
    751 # Sigh...
    752 
    753 # begin_substep byacc-20220128
    754 # if [ -x ${TL}/bin/yacc ]; then
    755 # 	msg info "%s exists, skipping %s" ${TL}/bin/yacc ${pkg}
    756 # else
    757 # 	extract_pkg ${G_SRC} ${pkg} ${pkg}.tgz
    758 # 	(
    759 # 		cd_or_fail ${G_SRC}/${pkg}
    760 # 		run_configure . \
    761 # 			--prefix=/${TLD} \
    762 # 			--build=${G_HOST} \
    763 # 			--host=${G_TARGET}
    764 # 		run_make ${JN}
    765 # 		run_make install
    766 # 	) || exit 1
    767 # 	remove_dir ${G_SRC}/${pkg}
    768 # fi
    769 # end_substep
    770 
    771 begin_substep bison-3.8.2
    772 if [ -x ${TL}/bin/yacc ]; then
    773 	msg info "%s exists, skipping %s" ${TL}/bin/yacc ${pkg}
    774 else
    775 	extract_pkg ${G_SRC} ${pkg} ${pkg}.tar.xz
    776 	(
    777 		cd_or_fail ${G_SRC}/${pkg}
    778 		run_configure . \
    779 			--prefix=/${TLD} \
    780 			--build=${G_HOST} \
    781 			--host=${G_TARGET}
    782 		run_make ${JN}
    783 		run_make install
    784 	) || exit 1
    785 	remove_dir ${G_SRC}/${pkg}
    786 fi
    787 end_substep
    788 
    789 begin_substep diffutils-3.9
    790 if [ -x ${TL}/bin/diff ]; then
    791 	msg info "%s exists, skipping %s" ${TL}/bin/diff ${pkg}
    792 else
    793 	extract_pkg ${G_SRC} ${pkg} ${pkg}.tar.xz
    794 	(
    795 		cd_or_fail ${G_SRC}/${pkg}
    796 		run_configure . \
    797 			--prefix=/${TLD} \
    798 			--build=${G_HOST} \
    799 			--host=${G_TARGET}
    800 		run_make ${JN}
    801 		run_make install
    802 	) || exit 1
    803 	remove_dir ${G_SRC}/${pkg}
    804 fi
    805 end_substep
    806 
    807 begin_substep file-5.44
    808 if [ -x ${TL}/bin/file ]; then
    809 	msg info "%s exists, skipping %s" ${TL}/bin/file ${pkg}
    810 else
    811 	extract_pkg ${G_SRC} ${pkg} ${pkg}.tar.gz
    812 	(
    813 		cd_or_fail ${G_SRC}/${pkg}
    814 
    815 		run_configure . \
    816 			--prefix=/${TLD} \
    817 			--build=${G_HOST} \
    818 			--host=${G_TARGET}
    819 
    820 		run_make ${JN}
    821 		run_make install
    822 	) || exit 1
    823 	remove_dir ${G_SRC}/${pkg}
    824 fi
    825 end_substep
    826 
    827 begin_substep findutils-4.9.0
    828 if [ -x ${TL}/bin/find ]; then
    829 	msg info "%s exists, skipping %s" ${TL}/bin/find ${pkg}
    830 else
    831 	extract_pkg ${G_SRC} ${pkg} ${pkg}.tar.xz
    832 	(
    833 		cd_or_fail ${G_SRC}/${pkg}
    834 		/bin/sed -i 's/IO_ftrylockfile/IO_EOF_SEEN/' gl/lib/*.c
    835 		/bin/sed -i '/unistd/a #include <sys/sysmacros.h>' \
    836 			gl/lib/mountlist.c
    837 		echo '#define _IO_IN_BACKUP 0x100' >>gl/lib/stdio-impl.h
    838 		run_configure . \
    839 			--prefix=/${TLD} \
    840 			--build=${G_HOST} \
    841 			--host=${G_TARGET}
    842 		run_make ${JN}
    843 		run_make install
    844 	) || exit 1
    845 	remove_dir ${G_SRC}/${pkg}
    846 fi
    847 end_substep
    848 
    849 HOST_FIND=0
    850 export HOST_FIND
    851 
    852 begin_substep gettext-tiny-0.3.2
    853 if [ -x ${TL}/bin/msgfmt ]; then
    854 	msg info "%s exists, skipping %s" ${TL}/bin/msgfmt ${pkg}
    855 else
    856 	extract_pkg ${G_SRC} ${pkg} ${pkg}.tar.xz
    857 	(
    858 		cd_or_fail ${G_SRC}/${pkg}
    859 		run_make ${JN} LIBINTL=MUSL prefix=/${TLD}
    860 		cp_or_fail msgfmt msgmerge xgettext ${TL}/bin
    861 	) || exit 1
    862 	remove_dir ${G_SRC}/${pkg}
    863 fi
    864 end_substep
    865 
    866 begin_substep grep-3.10
    867 if [ -x ${TL}/bin/fgrep ]; then
    868 	msg info "%s exists, skipping %s" ${TL}/bin/fgrep ${pkg}
    869 else
    870 	extract_pkg ${G_SRC} ${pkg} ${pkg}.tar.xz
    871 	(
    872 		cd_or_fail ${G_SRC}/${pkg}
    873 		run_configure . \
    874 			--prefix=/${TLD} \
    875 			--build=${G_HOST} \
    876 			--host=${G_TARGET}
    877 		run_make ${JN}
    878 		run_make install
    879 	) || exit 1
    880 	remove_dir ${G_SRC}/${pkg}
    881 fi
    882 end_substep
    883 
    884 begin_substep zlib-ng-2.0.7
    885 if [ -e /${TLD}/lib/libz.so.1.2.11.zlib-ng ]; then
    886 	msg info "%s exists, skipping %s" /${TLD}/lib/libz.so.1.2.11.zlib-ng \
    887 		${pkg}
    888 else
    889 	extract_pkg ${G_SRC} ${pkg} ${pkg}.tar.gz
    890 	(
    891 		cd_or_fail ${G_SRC}/${pkg}
    892 
    893 		apply_patch tools -Np1 -i \
    894 			${G_PAT}/zlib-ng-mlfs/configure-fix-interpreter.patch
    895 
    896 		AR=${G_TARGET}-ar \
    897 		CC=${G_TARGET}-gcc \
    898 		LD=${G_TARGET}-ld \
    899 		run_configure . --prefix=/${TLD} \
    900 			--libdir=/${TLD}/lib \
    901 			--zlib-compat \
    902 			--sharedlibdir=/${TLD}/lib
    903 		run_make ${JN}
    904 		run_make install
    905 		link_if_ne libz.so.1.2.11.zlib-ng /${TLD}/lib/libz.so.1.2.11
    906 	) || exit 1
    907 	#remove_dir ${G_SRC}/${pkg}
    908 fi
    909 end_substep
    910 
    911 begin_substep pigz-2.7
    912 if [ -x ${TL}/bin/gzip ]; then
    913 	msg info "%s exists, skipping %s" ${TL}/bin/gzip ${pkg}
    914 else
    915 	extract_pkg ${G_SRC} ${pkg} ${pkg}.tar.gz
    916 	(
    917 		cd_or_fail ${G_SRC}/${pkg}
    918 		AR=${G_TARGET}-ar
    919 		CC=${G_TARGET}-gcc
    920 		LD=${G_TARGET}-ld
    921 		run_make AR=${G_TARGET}-ar CC=${G_TARGET}-gcc \
    922 			LD=${G_TARGET}-ld ${JN}
    923 		cp pigz /${TLD}/bin
    924 		ln -s pigz /${TLD}/bin/unpigz
    925 		ln -s pigz /${TLD}/bin/gzip
    926 		ln -s pigz /${TLD}/bin/gunzip
    927 	) || exit 1
    928 	remove_dir ${G_SRC}/${pkg}
    929 fi
    930 end_substep
    931 
    932 begin_substep netbsd-curses-0.3.2
    933 if [ -e ${TL}/lib/libncurses.so ]; then
    934 	msg info "%s exists, skipping %s" ${TL}/lib/libncurses.so ${pkg}
    935 else
    936 	extract_pkg ${G_SRC} ${pkg} ${pkg}.tar.xz
    937 	(
    938 		cd_or_fail ${G_SRC}/${pkg}
    939 		run_make ${JN} PREFIX=/${TLD} all install
    940 	) || exit 1
    941 	remove_dir ${pkg}
    942 fi
    943 end_substep
    944  
    945 # begin_substep ncurses-6.2
    946 # if [ -e ${TL}/lib/libncurses.so ]; then
    947 #  	msg info "%s exists, skipping %s" ${TL}/lib/libncurses.so ${pkg}
    948 # else
    949 # 	fetch_pkg https://ftp.gnu.org/gnu/ncurses/${pkg}.tar.gz
    950 # 	extract_pkg ${G_SRC} ${pkg} ${pkg}.tar.gz
    951 # 	(
    952 # 		cd_or_fail ${G_SRC}/${pkg}
    953 # 
    954 # 		sed -i s/mawk// configure
    955 # 
    956 # 		TIC_PATH=/${TLD}/bin
    957 # 
    958 # 		run_configure . \
    959 # 			--prefix=/${TLD} \
    960 # 			--build=${G_HOST} \
    961 # 			--host=${G_TARGET} \
    962 # 			--with-shared \
    963 # 			--without-debug \
    964 # 			--without-ada \
    965 # 			--enable-widec \
    966 # 			--enable-overwrite
    967 # 
    968 # 		run_make ${JN}
    969 # 		run_make install
    970 # 	) || exit 1
    971 # 	remove_dir ${G_SRC}/${pkg}
    972 # fi
    973 # end_substep
    974 
    975 begin_substep bash-5.2.15
    976 if [ -x ${TL}/bin/bash ]; then
    977 	msg info "%s exists, skipping %s" ${TL}/bin/bash ${pkg}
    978 else
    979 	extract_pkg ${G_SRC} ${pkg} ${pkg}.tar.gz
    980 	(
    981 		cd_or_fail ${G_SRC}/${pkg}
    982 
    983 		cat <<! >config.cache
    984 ac_cv_func_mmap_fixed_mapped=yes
    985 ac_cv_func_strcoll_works=yes
    986 ac_cv_func_working_mktime=yes
    987 bash_cv_func_sigsetjmp=present
    988 bash_cv_getcwd_malloc=yes
    989 bash_cv_job_control_missing=present
    990 bash_cv_printf_a_format=yes
    991 bash_cv_sys_named_pipes=present
    992 bash_cv_ulimit_maxfds=yes
    993 bash_cv_under_sys_siglist=yes
    994 bash_cv_unusable_rtsigs=no
    995 gt_cv_int_divbyzero_sigfpe=yes
    996 !
    997 		run_configure . \
    998 			--prefix=/${TLD} \
    999 			--without-bash-malloc \
   1000 			--build=${G_HOST} \
   1001 			--host=${G_TARGET} \
   1002 			--cache-file=config.cache
   1003 
   1004 		run_make -j1
   1005 		run_make install
   1006 	) || exit 1
   1007 	remove_dir ${G_SRC}/${pkg}
   1008 fi
   1009 end_substep
   1010 
   1011 begin_substep bc-6.5.0
   1012 if [ -x ${TL}/bin/bc ]; then
   1013 	msg info "%s exists, skipping %s" ${TL}/bin/bc ${pkg}
   1014 else
   1015 	extract_pkg ${G_SRC} ${pkg} ${pkg}.tar.xz
   1016 	(
   1017 		cd_or_fail ${G_SRC}/${pkg}
   1018 		PREFIX=/ CC=${CC} CFLAGS="${CFLAGS} -std=c99" \
   1019 		DESTDIR=/${TLD} \
   1020 		./configure.sh -G -O3
   1021 		run_make ${JN}
   1022 		run_make install
   1023 	) || exit 1
   1024 	remove_dir ${G_SRC}/${pkg}
   1025 fi
   1026 end_substep
   1027 
   1028 
   1029 begin_substep patch-2.7.6
   1030 if [ -x ${TL}/bin/patch ]; then
   1031 	msg info "%s exists, skipping %s" ${TL}/bin/patch ${pkg}
   1032 else
   1033 	extract_pkg ${G_SRC} ${pkg} ${pkg}.tar.xz
   1034 	(
   1035 		cd_or_fail ${G_SRC}/${pkg}
   1036 		run_configure . \
   1037 			--prefix=/${TLD} \
   1038 			--build=${G_HOST} \
   1039 			--host=${G_TARGET}
   1040 		run_make ${JN}
   1041 		run_make install
   1042 	) || exit 1
   1043 	remove_dir ${G_SRC}/${pkg}
   1044 fi
   1045 end_substep
   1046 
   1047 # Sucky Linux doesn't support reflex and demands flex
   1048 # begin_substep reflex-20210808
   1049 # if [ -x ${TL}/bin/flex ]; then
   1050 # 	msg info "%s exists, skipping %s" ${TL}/bin/flex ${pkg}
   1051 # else
   1052 # 	extract_pkg ${G_SRC} ${pkg} ${pkg}.tgz
   1053 # 	(
   1054 # 		cd_or_fail ${G_SRC}/${pkg}
   1055 # 		run_configure . \
   1056 # 			--prefix=/${TLD} \
   1057 # 			--build=${G_HOST} \
   1058 # 			--host=${G_TARGET}
   1059 # 		run_make ${JN}
   1060 # 		run_make install
   1061 # 		link_if_ne reflex ${TL}/bin/flex
   1062 # 	) || exit 1
   1063 # 	remove_dir ${G_SRC}/${pkg}
   1064 # fi
   1065 # end_substep
   1066 
   1067 begin_substep flex-2.6.4
   1068 if [ -x ${TL}/bin/flex ]; then
   1069 	msg info "%s exists, skipping %s" ${TL}/bin/flex ${pkg}
   1070 else
   1071  	extract_pkg ${G_SRC} ${pkg} ${pkg}.tar.gz
   1072 	(
   1073 		cd_or_fail ${G_SRC}/${pkg}
   1074 
   1075 		ac_cv_func_malloc_0_nonnull=yes
   1076 		ac_cv_func_realloc_0_nonnull=yes
   1077 		HELP2MAN=/${TLD}/bin/true
   1078 		export ac_cv_func_malloc_0_nonnull ac_cv_func_realloc_0_nonnull
   1079 		export HELP2MAN
   1080 
   1081 		run_configure . \
   1082 			--prefix=/${TLD}   \
   1083 			--build=${G_HOST}  \
   1084 			--host=${G_TARGET}
   1085 		run_make ${JN}
   1086 		run_make install
   1087 	) || exit 1
   1088 fi
   1089 end_substep
   1090 
   1091 begin_substep awk-20230412
   1092 if [ -x ${TL}/bin/awk ]; then
   1093 	msg info "%s exists, skipping %s" ${TL}/bin/awk ${pkg}
   1094 else
   1095 	(
   1096 		cd_or_fail ${G_SRC}/${pkg}
   1097 		run_make
   1098 		mv_or_fail a.out ${TL}/bin/awk
   1099 	) || exit 1
   1100 fi
   1101 end_substep
   1102 
   1103 # Unfortunately needed for a lot of autohell stuff; keeping it in /tools though
   1104 begin_substep coreutils-9.2
   1105 if [ -x ${TL}/bin/ls ]; then
   1106 	msg info "%s exists, skipping %s" ${TL}/bin/ls ${pkg}
   1107 else
   1108 	extract_pkg ${G_SRC} ${pkg} ${pkg}.tar.xz
   1109 	(
   1110 		cd_or_fail ${G_SRC}/${pkg}
   1111 		autoreconf -vif
   1112 		cat <<! >config.cache
   1113 fu_cv_sys_stat_statfs2_bsize=no
   1114 ac_cv_func_syncfs=no
   1115 gl_cv_func_working_mkstemp=yes
   1116 gl_cv_func_working_acl_get_file=yes
   1117 !
   1118 		sed -i '/test.lock/s/^/#/' gnulib-tests/gnulib.mk
   1119 		run_configure . \
   1120 			--prefix=/${TLD} \
   1121 			--build=${G_HOST} \
   1122 			--target=${G_TARGET} \
   1123 			--enable-install-program=hostname \
   1124 			--cache-file=config.cache
   1125 		run_make ${JN}
   1126 		run_make install-strip
   1127 	) || exit 1
   1128 	remove_dir ${G_SRC}/${pkg}
   1129 fi
   1130 end_substep
   1131 
   1132 HOST_COREUTILS=0
   1133 export HOST_COREUTILS
   1134 
   1135 begin_substep sed-4.9
   1136 if [ -x ${TL}/bin/sed ]; then
   1137 	msg info "%s exists, skipping %s" ${TL}/bin/sed ${pkg}
   1138 else
   1139 	extract_pkg ${G_SRC} ${pkg} ${pkg}.tar.xz
   1140 	(
   1141 		cd_or_fail ${G_SRC}/${pkg}
   1142 		autoreconf -vif
   1143 		run_configure . \
   1144 			--prefix=/${TLD} \
   1145 			--build=${G_HOST} \
   1146 			--target=${G_TARGET}
   1147 		run_make ${JN}
   1148 		run_make install-strip
   1149 	) || exit 1
   1150 	remove_dir ${G_SRC}/${pkg}
   1151 fi
   1152 end_substep
   1153 
   1154 HOST_SED=0
   1155 export HOST_SED
   1156 
   1157 # begin_substep sbase-20220709
   1158 # if [ -x ${TL}/bin/ls ]; then
   1159 # 	msg info "%s exists, skipping %s" ${TL}/bin/ls ${pkg}
   1160 # else
   1161 # 	(
   1162 # 		CC=tcc
   1163 # 		export CC
   1164 # 		cd_or_fail ${G_SRC}/${pkg}
   1165 # 		/bin/sed -i -e 's,/usr/local,/'${TLD}',g;s, \<cc\>, '${CC}',g' \
   1166 # 		       -e 's, \<ar\>, '${AR}',g' \
   1167 # 		       -e 's,^CFLAGS\s\+= ,&-static -fcommon ,g' \
   1168 # 		       -e 's,^LDFLAGS\s\+= ,&-static -fcommon ,g' config.mk
   1169 # 		run_make ${JN} CC=${CC}
   1170 # 		run_make install
   1171 # 		#remove_dir ${G_SRC}/${pkg}
   1172 # 	) || exit 1
   1173 # fi
   1174 # end_substep
   1175 # 
   1176 begin_substep ubase-20230412
   1177 if [ -x ${TL}/bin/mount ]; then
   1178 	msg info "%s exists, skipping %s" ${TL}/bin/mount ${pkg}
   1179 else
   1180 	(
   1181 		cd_or_fail ${G_SRC}/${pkg}
   1182 
   1183 		cp util.h util.h.orig
   1184 		sed -i -z 's,"arg.h"\n,&#include <sys/sysmacros.h>\n,' util.h
   1185 
   1186 		cp config.mk config.mk.orig
   1187 		sed -i -e 's,/usr/local,,g;s, \\<cc\\>, ${CC},g' \
   1188 		       -e 's, \<ar\>, '${AR}',g' \
   1189 		       -e 's,^CFLAGS\s\+= ,&-static -fcommon ,g' \
   1190 		       -e 's,^LDFLAGS\s\+= ,&-static -fcommon ,g' \
   1191 		       -e 's,^LDLIBS\s\+= ,&-lc ,g' \
   1192 			config.mk
   1193 
   1194 		run_make ${JN} CC=${CC}
   1195 
   1196 		cp id mount umount /${TLD}/bin
   1197 		#run_make install
   1198 
   1199 		mv util.h.orig util.h
   1200 		mv config.mk.orig config.mk
   1201 		#remove_dir ${G_SRC}/${pkg}
   1202 	) || exit 1
   1203 fi
   1204 end_substep
   1205 
   1206 begin_substep tar-1.34
   1207 if [ -x ${TL}/bin/tar ]; then
   1208 	msg info "%s exists, skipping %s" ${TL}/bin/tar ${pkg}
   1209 else
   1210 	extract_pkg ${G_SRC} ${pkg} ${pkg}.tar.xz
   1211 	(
   1212 		cd_or_fail ${G_SRC}/${pkg}
   1213 		run_configure . \
   1214 			--prefix=/${TLD} \
   1215 			--build=${G_HOST} \
   1216 			--host=${G_TARGET}
   1217 		run_make ${JN}
   1218 		run_make install
   1219 	) || exit 1
   1220 	remove_dir ${G_SRC}/${pkg}
   1221 fi
   1222 end_substep
   1223 
   1224 HOST_TAR=0
   1225 export HOST_TAR
   1226 
   1227 begin_substep xz-5.4.2
   1228 if [ -x ${TL}/bin/xz ]; then
   1229 	msg info "%s exists, skipping %s" ${TL}/bin/xz ${pkg}
   1230 else
   1231 	extract_pkg ${G_SRC} ${pkg} ${pkg}.tar.xz
   1232 	(
   1233 		cd_or_fail ${G_SRC}/${pkg}
   1234 		run_configure . \
   1235 			--prefix=/${TLD} \
   1236 			--build=${G_HOST} \
   1237 			--host=${G_TARGET}
   1238 		run_make ${JN}
   1239 		run_make install
   1240 	) || exit 1
   1241 	remove_dir ${G_SRC}/${pkg}
   1242 fi
   1243 end_substep
   1244 
   1245 # 5.32.1 is deliberate, can't get 5.36.0 nor 5.34.1 to compile _at this stage of
   1246 # the build_ (for now...)
   1247 # Later on, we build 5.36.0 using native GCC
   1248 begin_substep perl-5.32.1
   1249 if [ -x ${TL}/bin/perl ]; then
   1250 	msg info "%s exists, skipping %s" ${TL}/bin/perl ${pkg}
   1251 else
   1252 	extract_pkg ${G_SRC} perl-cross-1.4 perl-cross-1.4.tar.gz
   1253 	extract_pkg ${G_SRC} ${pkg} ${pkg}.tar.xz
   1254 	(
   1255 		cd_or_fail ${G_SRC}/${pkg}
   1256 		cp_or_fail -fr ${G_SRC}/perl-cross-1.4/* ./
   1257 		run_configure . \
   1258 			--prefix=/${TLD} \
   1259 			--target=${G_TARGET}
   1260 		run_make ${JN} || exit
   1261 		cp_or_fail perl cpan/podlators/scripts/pod2man ${TL}/bin
   1262 		mkdir -p ${TL}/lib/perl5/5.32.1
   1263 		cp_or_fail -R lib/* ${TL}/lib/perl5/5.32.1
   1264 		sh
   1265 	) || exit 1
   1266 	remove_dir ${G_SRC}/${pkg}
   1267 fi
   1268 end_substep
   1269 
   1270 msg info "Removing unneeded documentation"
   1271 remove_dir ${TL}/doc
   1272 remove_dir ${TL}/info
   1273 remove_dir ${TL}/man
   1274 remove_dir ${TL}/share/doc
   1275 remove_dir ${TL}/share/info
   1276 remove_dir ${TL}/share/man
   1277 
   1278 end_step # tools
   1279 
   1280 begin_step utilities
   1281 
   1282 totalsubsteps=3
   1283 substep=1
   1284 
   1285 begin_substep mksh-20230412
   1286 if [ -x ${TL}/bin/mksh ]; then
   1287 	msg info "%s exists, skipping %s" ${TL}/bin/mksh ${pkg}
   1288 else
   1289 	(
   1290 		cd_or_fail ${G_SRC}/${pkg}
   1291 		CFLAGS='-static --static -fcommon'
   1292 		LDSTATIC='-static'
   1293 		TARGET_OS=Linux
   1294 		export CFLAGS LDSTATIC TARGET_OS
   1295 		unset CPPFLAGS
   1296 	
   1297 		check_dir build-mksh
   1298 		cd_or_fail build-mksh
   1299 		setup_fifo
   1300 		sh ../Build.sh -r > ${G_FIFO}
   1301 		rm ${G_FIFO}
   1302 	
   1303 		#check_dir ${TL}/share/doc/mksh/examples
   1304 		#check_dir ${TL}/share/man/man1
   1305 	
   1306 		install -c -s -m 555 mksh ${TL}/bin/mksh
   1307 		install -c -m 444 ../dot.mkshrc \
   1308 			${GR}/share/doc/mksh/examples/
   1309 		install -c -m 444 ../lksh.1 ../mksh.1 \
   1310 			${GR}/share/man/man1/
   1311 		# install -c -s -o root -g root -m 555 mksh ${GR}/bin/mksh
   1312 		# install -c -o root -g root -m 444 ../dot.mkshrc \
   1313 		# 	${GR}/share/doc/mksh/examples/
   1314 		# install -c -o root -g root -m 444 ../lksh.1 ../mksh.1 \
   1315 		# 	${GR}/share/man/man1/
   1316 	
   1317 		cd ..
   1318 	
   1319 		CPPFLAGS=-DMKSH_BINSHPOSIX
   1320 		export CPPFLAGS
   1321 		check_dir build-lksh
   1322 		cd_or_fail build-lksh
   1323 		setup_fifo
   1324 		sh ../Build.sh -r -L > ${G_FIFO}
   1325 		rm ${G_FIFO}
   1326 	
   1327 		install -c -s -m 555 lksh ${TL}/bin/lksh
   1328 		link_if_ne lksh ${TL}/bin/sh
   1329 	
   1330 		unset CFLAGS CPPFLAGS LDSTATIC TARGET_OS
   1331 	) || exit 1
   1332 fi
   1333 end_substep
   1334 
   1335 begin_substep which-2.21
   1336 if [ -x ${TL}/bin/which ]; then
   1337 	msg info "%s exists, skipping %s" ${TL}/bin/which ${pkg}
   1338 else
   1339 	extract_pkg ${G_SRC} ${pkg} ${pkg}.tar.gz
   1340 	(
   1341 		cd_or_fail ${G_SRC}/${pkg}
   1342 		run_configure . \
   1343 			--prefix=/${TLD} \
   1344 			--build=${G_HOST} \
   1345 			--host=${G_TARGET}
   1346 		run_make ${JN}
   1347 		run_make install
   1348 	) || exit 1
   1349 	remove_dir ${G_SRC}/${pkg}
   1350 fi
   1351 end_substep
   1352 
   1353 begin_substep sled-0.11.5
   1354 if [ -x ${TL}/bin/sled ]; then
   1355 	msg info "%s exists, skipping %s" ${TL}/bin/sled ${pkg}
   1356 else
   1357 	extract_pkg ${G_SRC} sled-v0.11.5 ${pkg}.tar.gz ${pkg}
   1358 	(
   1359 		cd_or_fail ${G_SRC}/${pkg}
   1360 		FALLBACKVER=0.11.5
   1361 		SLED_CC=${CC}' -O2 -Wall -static -fcommon'
   1362 		PREFIX=/${TLD} 
   1363 		export FALLBACKVER SLED_CC PREFIX
   1364 		run_do -c install
   1365 	) || exit 1
   1366 fi
   1367 end_substep
   1368 
   1369 end_step # utilities
   1370 
   1371 msg info "Cleaning up environment"
   1372 export PATH=${OLDPATH}
   1373 unset OLDPATH CC CXX AR AS RANLIB LD STRIP
   1374 unset WD
   1375 unset HOST_COREUTILS HOST_FIND HOST_SHASUM HOST_SED HOST_TAR
   1376 
   1377 msg warn "Next run ./02-chroot.sh as root"