#!/bin/bash #also see: # http://autobuild.buildroot.org/toolchains/tarballs/ source ./build.conf export MKFLG export MWD=$[pwd] setglobal ARCH_LIST = '"default i686 x86_64 arm'" #arm64 setglobal ARCH_LIST_EX = '"i486 i586 i686 x86_64 armv4l armv4tl armv5l armv6l m68k mips mips64 mipsel powerpc powerpc-440fp sh2eb sh2elf sh4 sparc'" setglobal DEFAULT_x86 = 'i686' setglobal DEFAULT_ARM = 'armv6l' #DEFAULT_ARM64=aarch64 setglobal PREBUILT_BINARIES = '"http://01micko.com/wdlkmpx/woof-CE/initrd_progs-20170322-static.tar.xz'" setglobal ARCH = $[uname -m] setglobal OS_ARCH = $ARCH proc get_initrd_progs { var var = 'INITRD_PROGS' test $1 = "-pkg" && do { set var = 'PACKAGES' ; shift ; } var arch = $1 test $arch = "" && set arch = $[uname -m] match $arch { with i?86 set arch = '"x86'" } match $arch { with arm* set arch = ''arm'' } eval echo '$'$var '$'$(var)_$(arch) #ex: $PACKAGES $PACKAGES_x86, $INITRD_PROGS $INITRD_PROGS_x86 } match $1 { with 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 ; } setglobal 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_)]] { match $PROG { with ""|'#'* continue } setglobal progs2tar = "" $(ARCH)/bin/$(PROG)"" } } <<< "$(ls -d 00_*)" tar -Jcf $pkgx $(progs2tar) echo "Done." exit } match $1 { with 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) ## setglobal USE_SYS_GCC = 'no' setglobal CROSS_COMPILE = 'no' setglobal FORCE_BUILD_ALL = 'no' export DLD_ONLY=no setglobal INITRD_CREATE = 'yes' match $(INITRD_COMP) { with gz|xz setglobal ok = 'yes' with * setglobal INITRD_COMP = '"gz'" } ## command line ## while test $1 { match $1 { with -sysgcc setglobal USE_SYS_GCC = 'yes' ; setglobal USE_PREBUILT = 'no'; shift with -cross setglobal CROSS_COMPILE = 'yes' ; setglobal USE_PREBUILT = 'no'; shift with -all setglobal FORCE_BUILD_ALL = 'yes' ; shift with -gz|-xz|gz|xz setglobal INITRD_COMP = $(1#-) ; shift with -download setglobal DLD_ONLY = 'yes' ; shift with -prebuilt setglobal USE_PREBUILT = 'yes' ; shift with -nord setglobal INITRD_CREATE = 'no' ; shift with -auto setglobal PROMPT = 'no' ; shift with -v setglobal V = '-v' ; shift with -lang setglobal LOCALE = $2 ; shift 2 test $LOCALE = "" && fatal_error "$0 -locale: No locale specified" with -keymap setglobal KEYMAP = $2 ; shift 2 test $KEYMAP = "" && fatal_error "$0 -locale: No keymap specified" with -pkg setglobal BUILD_PKG = $2 ; shift 2 test $BUILD_PKG = "" && fatal_error "$0 -pkg: Specify a pkg to compile" with -arch setglobal TARGET_ARCH = $2 ; shift 2 test $TARGET_ARCH = "" && fatal_error "$0 -arch: Specify a target arch" with -specs setglobal DISTRO_SPECS = $2 ; shift 2 test ! -f $DISTRO_SPECS && fatal_error "$0 -specs: '$(DISTRO_SPECS)' is not a regular file" with -h|-help|--help help_msg ; exit with -clean echo -e "Press P and hit enter to proceed, any other combination to cancel.." ; read zz match $zz { with p|P echo rm -rf initrd.[gx]z initrd_progs-*.tar.* ZZ_initrd-expanded 00_* 0sources cross-compiler* } exit with * echo "Unrecognized option: $1" shift } } #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ proc use_prebuilt_binaries { test ! $PREBUILT_BINARIES && do { echo "ERROR"; exit 1 ; } setglobal 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 $Status -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 match $ARCH { with i?86|x86_64 setglobal CROSS_COMPILE = 'yes' with * setglobal 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 # setglobal CROSS_COMPILE = 'yes' #precaution match $ARCH { with i?86|x86_64 setglobal ok = 'yes' with * 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 match $TARGET_ARCH { with default setglobal TARGET_ARCH = $(ARCH) with x86 setglobal TARGET_ARCH = $(DEFAULT_x86) with arm setglobal TARGET_ARCH = $(DEFAULT_ARM) #arm64) TARGET_ARCH=${DEFAULT_ARM64} ;; } setglobal VALID_TARGET_ARCH = 'no' if test $TARGET_ARCH != "" { #no -arch specified for a in [$ARCH_LIST_EX] { test $TARGET_ARCH = $a && setglobal VALID_TARGET_ARCH = 'yes' && break } if test $VALID_TARGET_ARCH = "no" { echo "Invalid target arch: $TARGET_ARCH" exit 1 } else { test $TARGET_ARCH != "default" && setglobal 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" setglobal x = '1' for a in [$ARCH_LIST] { match $a { with default echo " $(x)) default [$(ARCH)]" with * echo " $(x)) $a" } let x++ } echo " *) default [$(ARCH)]" echo -en "\nEnter your choice: " ; read choice echo setglobal x = '1' for a in [$ARCH_LIST] { test $x = $choice && setglobal selected_arch = $a && break ; let x++ ; } for a in [$ARCH_LIST_EX] { test $a = $choice && setglobal selected_arch = $a ; } match $selected_arch { with default|""setglobal ok = 'yes' with * setglobal 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" { match $OS_ARCH { with *64 setglobal ok = 'yes' with * match $ARCH { with *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 setglobal CCOMP_DIR = "cross-compiler-$(ARCH)" setglobal URL = 'http://landley.net/aboriginal/downloads/binaries' setglobal 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 $Status -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 $Status -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 { match $init_pkg { with ""|'#'* continue with coreutils_static setglobal static_bins = ''cp'' with dosfstools_static setglobal static_bins = ''fsck.fat'' with e2fsprogs_static setglobal static_bins = ''e2fsck resize2fs'' with exfat-utils_static setglobal static_bins = ''exfatfsck'' with fuse-exfat_static setglobal static_bins = ''mount.exfat-fuse'' with findutils_static setglobal static_bins = ''find'' with util-linux_static setglobal static_bins = ''losetup'' with util-linux-222_static setglobal static_bins = ''losetup-222'' with * setglobal 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 != "" && setglobal PACKAGES = $BUILD_PKG if test $FORCE_BUILD_ALL = "yes" { setglobal PACKAGES = $[find pkg -maxdepth 1 -type d -name '*_static' | sed 's|.*/||' | sort] } else { setglobal PACKAGES = $[get_initrd_progs -pkg $ARCH] } #-- for init_pkg in [$(PACKAGES)] { match $init_pkg { with ""|'#'* continue } test -f .fatal && do { echo "Exiting.." ; rm -f .fatal ; exit 1 ; } test -d pkg/"$(init_pkg)_static" && setglobal init_pkg = "$(init_pkg)_static" if test $DLD_ONLY = "no" { check_bin $init_pkg test $Status -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 $Status -ne 0 && do { echo "target binary does not exist..."; exit 1; } } rm -f .fatal } #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ proc set_lang { #in $MWD test $(LOCALE%_*) = "en" && setglobal 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 && setglobal KEYMAP = ''"" match $KEYMAP { with 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 setglobal INITRD_FILE = ""initrd.$(INITRD_COMP)"" test $INITRD_GZ = "yes" && setglobal 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)]] { match $PROG { with ""|'#'* 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 { setglobal DISTRO_SPECS = ''../DISTRO_SPECS'' } if test ! -f $DISTRO_SPECS -a ! -f ../0initrd/DISTRO_SPECS { test -f /etc/DISTRO_SPECS && setglobal DISTRO_SPECS = ''/etc/DISTRO_SPECS'' test -f /initrd/DISTRO_SPECS && setglobal 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 match $(INITRD_COMP) { with gz gzip -f initrd with xz xz --check=crc32 --lzma2 initrd } test $Status -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 { setglobal V = '"-v'" set_compiler select_target_arch setup_cross_compiler build_pkgs cd $(MWD) } generate_initrd ### END ###