#!/bin/bash #also see: # http://autobuild.buildroot.org/toolchains/tarballs/ source ./build.conf export MKFLG export MWD=$(pwd) setvar ARCH_LIST = ""default i686 x86_64 arm"" #arm64 setvar ARCH_LIST_EX = ""i486 i586 i686 x86_64 armv4l armv4tl armv5l armv6l m68k mips mips64 mipsel powerpc powerpc-440fp sh2eb sh2elf sh4 sparc"" setvar DEFAULT_x86 = 'i686' setvar DEFAULT_ARM = 'armv6l' #DEFAULT_ARM64=aarch64 setvar PREBUILT_BINARIES = ""http://01micko.com/wdlkmpx/woof-CE/initrd_progs-20170322-static.tar.xz"" setvar ARCH = $(uname -m) setvar OS_ARCH = "$ARCH" proc get_initrd_progs { local var=INITRD_PROGS test $1 = "-pkg" && do { setvar var = 'PACKAGES' ; shift ; } local arch=$1 test $arch = "" && setvar arch = $(uname -m) case (arch) { i?86 { setvar arch = ""x86"" } } case (arch) { arm* { setvar arch = ''arm'' } } eval echo '$'$var '$'${var}_${arch} #ex: $PACKAGES $PACKAGES_x86, $INITRD_PROGS $INITRD_PROGS_x86 } case (1) { release|tarball { #this contains the $PREBUILT_BINARIES echo "If you made changes then don't forget to remove all 00_* directories first" sleep 4 for a in ${ARCH_LIST#default } { $0 -nord -auto -arch $a ; } setvar pkgx = "initrd_progs-$(date "+%Y%m%d")-static.tar.xz" echo -e "\n\n\n*** Creating $pkgx" while read ARCH { for PROG in $(get_initrd_progs ${ARCH#00_}) { case (PROG) { ""|'#'* { continue } } setvar progs2tar = "" ${ARCH}/bin/${PROG}"" } } <<< "$(ls -d 00_*)" tar -Jcf $pkgx ${progs2tar} echo "Done." exit } } case (1) { w|w_apps|c { for a in ${ARCH_LIST#default } { $0 -nord -auto -arch $a -pkg w_apps ; } exit } } #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ proc fatal_error { echo -e @ARGV ; exit 1 ; } proc help_msg { echo "Build static apps in the queue defined in build.conf Usage: $0 [options] Options: -pkg pkg : compile specific pkg only -all : force building all *_static pkgs -arch target: compile for target arch -sysgcc : use system gcc -cross : use the cross compilers from Aboriginal Linux -download : download pkgs only, this overrides other options -specs file : DISTRO_SPECS file to use -prebuilt : use prebuilt binaries -lang locale: set locale -keymap km : set keyboard layout -auto : don't prompt for input -gz|-xz : compression method for the initrd -help : show help and exit Valid for -arch: $ARCH_LIST_EX The most relevant for Puppy are: ${ARCH_LIST#default } Note that one target not yet supported by musl is aarch64 (arm64) " } ## defaults (other defaults are in build.conf) ## setvar USE_SYS_GCC = 'no' setvar CROSS_COMPILE = 'no' setvar FORCE_BUILD_ALL = 'no' export DLD_ONLY=no setvar INITRD_CREATE = 'yes' case{ gz|xz { setvar ok = 'yes' } * { setvar INITRD_COMP = ""gz"" } } ## command line ## while test $1 { case (1) { -sysgcc { setvar USE_SYS_GCC = 'yes' ; setvar USE_PREBUILT = 'no'; shift } -cross { setvar CROSS_COMPILE = 'yes' ; setvar USE_PREBUILT = 'no'; shift } -all { setvar FORCE_BUILD_ALL = 'yes' ; shift } -gz|-xz|gz|xz { setvar INITRD_COMP = ${1#-} ; shift } -download { setvar DLD_ONLY = 'yes' ; shift } -prebuilt { setvar USE_PREBUILT = 'yes' ; shift } -nord { setvar INITRD_CREATE = 'no' ; shift } -auto { setvar PROMPT = 'no' ; shift } -v { setvar V = '-v' ; shift } -lang { setvar LOCALE = "$2" ; shift 2 test $LOCALE = "" && fatal_error "$0 -locale: No locale specified" } -keymap { setvar KEYMAP = "$2" ; shift 2 test $KEYMAP = "" && fatal_error "$0 -locale: No keymap specified" } -pkg { setvar BUILD_PKG = "$2" ; shift 2 test $BUILD_PKG = "" && fatal_error "$0 -pkg: Specify a pkg to compile" } -arch { setvar TARGET_ARCH = "$2" ; shift 2 test $TARGET_ARCH = "" && fatal_error "$0 -arch: Specify a target arch" } -specs { setvar DISTRO_SPECS = "$2" ; shift 2 test ! -f $DISTRO_SPECS && fatal_error "$0 -specs: '${DISTRO_SPECS}' is not a regular file" } -h|-help|--help { help_msg ; exit } -clean { echo -e "Press P and hit enter to proceed, any other combination to cancel.." ; read zz case (zz) { p|P { echo rm -rf initrd.[gx]z initrd_progs-*.tar.* ZZ_initrd-expanded 00_* 0sources cross-compiler* } } exit } * { echo "Unrecognized option: $1" shift } } } #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ proc use_prebuilt_binaries { test ! $PREBUILT_BINARIES && do { echo "ERROR"; exit 1 ; } setvar zfile = "0sources/${PREBUILT_BINARIES##*/}" if test -f $zfile { #verify file integrity tar -taf $zfile &>/dev/null || rm -f $zfile } if test ! -f $zfile { mkdir -p 0sources wget -P 0sources --no-check-certificate $PREBUILT_BINARIES test $? -eq 0 || do { rm -f $zfile; echo "ERROR"; exit 1 ; } } echo "* Extracting ${zfile##*/}..." tar -xaf $zfile || do { rm -f $zfile; echo "ERROR"; exit 1 ; } } #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ proc set_compiler { which make &>/dev/null || fatal_error echo "It looks like development tools are not installed.. stopping" if test $USE_SYS_GCC = "no" -a $CROSS_COMPILE = "no" { # the cross compilers from landley.net were compiled on x86 # if we're using the script in a non-x86 system # it means that the system gcc must be chosen by default # perhaps we're running qemu or a native linux os case (ARCH) { i?86|x86_64 { setvar CROSS_COMPILE = 'yes' } * { setvar USE_SYS_GCC = 'yes' } } } if test $USE_SYS_GCC = "yes" { which gcc &>/dev/null || fatal_error "No gcc, aborting..." echo -e "\nBuilding in: $ARCH" echo -e "\n* Using system gcc\n" sleep 1.5 } else { # aboriginal linux # setvar CROSS_COMPILE = 'yes' #precaution case (ARCH) { i?86|x86_64 { setvar ok = 'yes' } * { fatal_error "*** Only use x86 systems to cross-compile\n* Run $0 -sysgcc to use the system gcc ... \n" } } } } #-- proc select_target_arch { test $CROSS_COMPILE = "no" -a $USE_PREBUILT = "no" && return #-- defaults case (TARGET_ARCH) { default { setvar TARGET_ARCH = ${ARCH} } x86 { setvar TARGET_ARCH = ${DEFAULT_x86} } arm { setvar TARGET_ARCH = ${DEFAULT_ARM} } #arm64) TARGET_ARCH=${DEFAULT_ARM64} ;; } setvar VALID_TARGET_ARCH = 'no' if test $TARGET_ARCH != "" { #no -arch specified for a in $ARCH_LIST_EX { test $TARGET_ARCH = $a && setvar VALID_TARGET_ARCH = 'yes' && break } if test $VALID_TARGET_ARCH = "no" { echo "Invalid target arch: $TARGET_ARCH" exit 1 } else { test $TARGET_ARCH != "default" && setvar ARCH = ${TARGET_ARCH} } } #-- if test $VALID_TARGET_ARCH = "no" -a $PROMPT = "yes" { echo -e "\nWe're going to compile apps for the init ram disk" echo -e "Select the arch you want to compile to\n" setvar x = '1' for a in $ARCH_LIST { case (a) { default { echo " ${x}) default [${ARCH}]" } * { echo " ${x}) $a" } } let x++ } echo " *) default [${ARCH}]" echo -en "\nEnter your choice: " ; read choice echo setvar x = '1' for a in $ARCH_LIST { test $x = $choice && setvar selected_arch = "$a" && break ; let x++ ; } for a in $ARCH_LIST_EX { test $a = $choice && setvar selected_arch = "$a" ; } case (selected_arch) { default|"" {setvar ok = 'yes' } * { setvar ARCH = "$selected_arch" } } } # using prebuilt binaries: echo $ARCH and return test $USE_PREBUILT = "yes" && echo "Arch: $ARCH" && return # don't check OS_ARCH if only downloading if test $DLD_ONLY = "no" { case (OS_ARCH) { *64 { setvar ok = 'yes' } * { case (ARCH) { *64 { fatal_error "\n*** Trying to compile for a 64bit arch in a 32bit system?\n*** That's not possible.. exiting.." } } } } } echo "Arch: $ARCH" sleep 1.5 } #-- proc setup_cross_compiler { # Aboriginal Linux # test $CROSS_COMPILE = "no" && return setvar CCOMP_DIR = "cross-compiler-${ARCH}" setvar URL = "http://landley.net/aboriginal/downloads/binaries" setvar PACKAGE = "${CCOMP_DIR}.tar.gz" echo ## download if test ! -f "0sources/${PACKAGE}"{ echo "Download cross compiler from Aboriginal Linux" test $PROMPT = "yes" && echo -n "Press enter to continue, CTRL-C to cancel..." && read zzz wget -c -P 0sources ${URL}/${PACKAGE} if test $? -ne 0 { rm -rf ${CCOMP_DIR} echo "failed to download ${PACKAGE}" exit 1 } } else { test $DLD_ONLY = "yes" && echo "Already downloaded ${PACKAGE}" } test $DLD_ONLY = "yes" && return ## extract if test ! -d $CCOMP_DIR { tar --directory=$PWD -xaf 0sources/${PACKAGE} if test $? -ne 0 { rm -rf ${CCOMP_DIR} rm -fv 0sources/${PACKAGE} echo "failed to extract ${PACKAGE}" exit 1 } } #-- test ! -d $CCOMP_DIR && do { echo "$CCOMP_DIR not found"; exit 1; } if test -d cross-compiler-${ARCH}/cc/lib { cp cross-compiler-${ARCH}/cc/lib/* cross-compiler-${ARCH}/lib } echo -e "\nUsing cross compiler from Aboriginal Linux\n" export OVERRIDE_ARCH=${ARCH} # = cross compiling # see ./func export XPATH=${PWD}/${CCOMP_DIR} # = cross compiling # see ./func } #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ proc check_bin { case (init_pkg) { ""|'#'* { continue } coreutils_static { setvar static_bins = ''cp'' } dosfstools_static { setvar static_bins = ''fsck.fat'' } e2fsprogs_static { setvar static_bins = ''e2fsck resize2fs'' } exfat-utils_static { setvar static_bins = ''exfatfsck'' } fuse-exfat_static { setvar static_bins = ''mount.exfat-fuse'' } findutils_static { setvar static_bins = ''find'' } util-linux_static { setvar static_bins = ''losetup'' } util-linux-222_static { setvar static_bins = ''losetup-222'' } * { setvar static_bins = ${init_pkg%_*} } } for sbin in ${static_bins} { test -f ./00_${ARCH}/bin/${sbin} || return 1 } } proc build_pkgs { rm -f .fatal mkdir -p 00_${ARCH}/bin 00_${ARCH}/log 0sources if test $DLD_ONLY = "no" { echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" echo -e "\nbuilding packages for the initial ram disk\n" sleep 1 } #-- test $BUILD_PKG != "" && setvar PACKAGES = "$BUILD_PKG" if test $FORCE_BUILD_ALL = "yes" { setvar PACKAGES = $(find pkg -maxdepth 1 -type d -name '*_static' | sed 's|.*/||' | sort) } else { setvar PACKAGES = $(get_initrd_progs -pkg $ARCH) } #-- for init_pkg in ${PACKAGES} { case (init_pkg) { ""|'#'* { continue } } test -f .fatal && do { echo "Exiting.." ; rm -f .fatal ; exit 1 ; } test -d pkg/"${init_pkg}_static" && setvar init_pkg = "${init_pkg}_static" if test $DLD_ONLY = "no" { check_bin $init_pkg test $? -eq 0 && do { echo "$init_pkg exists ... skipping" ; continue ; } echo -e "\n+=============================================================================+" echo -e "\nbuilding $init_pkg" sleep 1 } #-- cd pkg/${init_pkg} mkdir -p ${MWD}/00_${ARCH}/log sh ${init_pkg}.petbuild 2>&1 | tee ${MWD}/00_${ARCH}/log/${init_pkg}build.log cd ${MWD} test $DLD_ONLY = "yes" && continue check_bin $init_pkg test $? -ne 0 && do { echo "target binary does not exist..."; exit 1; } } rm -f .fatal } #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ proc set_lang { #in $MWD test ${LOCALE%_*} = "en" && setvar LOCALE = """" test ! $LOCALE && do { echo -e "\n* Using default locale" ; rm -f ZZ_initrd-expanded/PUPPYLANG ; return; } echo -e "* LANG set to: $LOCALE\n" echo -n $LOCALE > ZZ_initrd-expanded/PUPPYLANG } proc set_keymap { #in $MWD test ! -f 0initrd/lib/keymaps/${KEYMAP}.gz && setvar KEYMAP = """" case (KEYMAP) { default|en|us|"" { echo "* Using default keymap"; rm -f ZZ_initrd-expanded/PUPPYKEYMAP ; return } } echo -e "* Keymap set to: '${KEYMAP}'" echo -n $KEYMAP > ZZ_initrd-expanded/PUPPYKEYMAP } proc generate_initrd { test $DLD_ONLY = "yes" && return test $INITRD_CREATE = "no" && return setvar INITRD_FILE = ""initrd.${INITRD_COMP}"" test $INITRD_GZ = "yes" && setvar INITRD_FILE = ""initrd.gz"" if test $USE_PREBUILT = "no" { test $PROMPT = "yes" && echo -en "\nPress enter to create ${INITRD_FILE}, CTRL-C to end here.." && read zzz echo -e "\n============================================" echo "Now creating the initial ramdisk (${INITRD_FILE})" echo -e "=============================================\n" } rm -rf ZZ_initrd-expanded mkdir -p ZZ_initrd-expanded cp -rf 0initrd/* ZZ_initrd-expanded find ZZ_initrd-expanded -type f -name '*MARKER' -delete set_lang # set_keymap # cd ZZ_initrd-expanded for PROG in $(get_initrd_progs ${ARCH}) { case (PROG) { ""|'#'* { continue } } if test -f ../00_${ARCH}/bin/${PROG} { file ../00_${ARCH}/bin/${PROG} | grep -E 'dynamically|shared' && exit 1 cp -a ${V} --remove-destination ../00_${ARCH}/bin/${PROG} bin } else { echo "00_${ARCH}/bin/${PROG} not found" exit 1 } } test ! -f bin/nano && rm -rf usr lib/terminfo echo if test ! -f $DISTRO_SPECS -a -f ../DISTRO_SPECS { setvar DISTRO_SPECS = ''../DISTRO_SPECS'' } if test ! -f $DISTRO_SPECS -a ! -f ../0initrd/DISTRO_SPECS { test -f /etc/DISTRO_SPECS && setvar DISTRO_SPECS = ''/etc/DISTRO_SPECS'' test -f /initrd/DISTRO_SPECS && setvar DISTRO_SPECS = ''/initrd/DISTRO_SPECS'' } test -f $DISTRO_SPECS && cp -f ${V} ${DISTRO_SPECS} . test -x ../init && cp -f ${V} ../init . source ./DISTRO_SPECS cp -f ${V} ../pkg/busybox_static/bb-*-symlinks bin # essential shell { cd bin ; sh bb-create-symlinks 2>/dev/null } sed -i 's|^PUPDESKFLG=.*|PUPDESKFLG=0|' init find . | cpio -o -H newc > ../initrd 2>/dev/null cd .. test -f initrd.[gx]z && rm -f initrd.[gx]z case{ gz { gzip -f initrd } xz { xz --check=crc32 --lzma2 initrd } } test $? -eq 0 || do { echo "ERROR" ; exit 1 ; } test $INITRD_GZ = "yes" -a -f initrd.xz && mv -f initrd.xz initrd.gz echo -e "\n*** INITRD: ${INITRD_FILE} [${ARCH}]" echo -e "*** /DISTRO_SPECS: ${DISTRO_NAME} ${DISTRO_VERSION} ${DISTRO_TARGETARCH}" test $USE_PREBUILT = "yes" && return echo -e "\n@@ -- You can inspect ZZ_initrd-expanded to see the final results -- @@" echo -e "Finished.\n" } ############################################### # MAIN ############################################### if test $USE_PREBUILT = "yes" { use_prebuilt_binaries select_target_arch } else { setvar V = ""-v"" set_compiler select_target_arch setup_cross_compiler build_pkgs cd ${MWD} } generate_initrd ### END ###