#!/bin/echo "This file is sourced, not run" # Avoid trouble from unexpected environment settings by unsetting all # environment variables that we don't know about, in case some crazy # person already exported $CROSS_COMPILE, $ARCH, $CDPATH, or who knows # what else. It's hard to know what might drive some package crazy, # so use a whitelist. if test -z $NO_SANITIZE_ENVIRONMENT { # Which variables are set in config? global TEMP := $[echo $[sed -n 's/.*export[ \t]*\([^=]*\)=.*/\1/p' config] | sed 's/ /,/g] # What other variables should we keep? global TEMP := ""$TEMP,LANG,PATH,SHELL,TERM,USER,USERNAME,LOGNAME,PWD,EDITOR,HOME"" global TEMP := ""$TEMP,DISPLAY,_,TOPSHELL,START_TIME,STAGE_NAME,TOOLCHAIN_PREFIX"" global TEMP := ""$TEMP,HOST_ARCH,WRAPPY_LOGPATH,OLDPATH,http_proxy,ftp_proxy"" global TEMP := ""$TEMP,https_proxy,no_proxy,TEMP,TMPDIR,FORK,MUSL"" # Unset any variable we don't recognize. It can screw up the build. for i in [$[env | sed -n 's/=.*//p]] { is_in_list $i $TEMP && continue test $(i:0:7) == "DISTCC_" && continue test $(i:0:7) == "CCACHE_" && continue unset $i !2 >/dev/null } } # Assign (export) a variable only if current value is blank proc export_if_blank { test -z $[eval "echo \"\${$(1/=*/)}] && export $1 } # List of fallback mirrors to download package source from export_if_blank MIRROR_LIST="http://landley.net/code/aboriginal/mirror http://127.0.0.1/code/aboriginal/mirror" # Where are our working directories? export_if_blank TOP=$[pwd] export_if_blank SOURCES="$TOP/sources" export_if_blank SRCDIR="$TOP/packages" export_if_blank PATCHDIR="$SOURCES/patches" export_if_blank BUILD="$TOP/build" export_if_blank SRCTREE="$BUILD/packages" export_if_blank HOSTTOOLS="$BUILD/host" export_if_blank WRAPDIR="$BUILD/record-commands" test ! -z $MY_PATCH_DIR && export MY_PATCH_DIR="$[readlink -e $MY_PATCH_DIR]" # Set a default non-arch export WORK="$(BUILD)/host-temp" export ARCH_NAME=host # What host compiler should we use? export_if_blank CC=cc # How many processors should make -j use? global MEMTOTAL := $[awk '/MemTotal:/{print $2}' /proc/meminfo] if test -z $CPUS { export CPUS=$[echo /sys/devices/system/cpu/cpu[0-9]* | wc -w] test $CPUS -lt 1 && global CPUS := '1' # If we're not using hyper-threading, and there's plenty of memory, # use 50% more CPUS than we actually have to keep system busy test -z $[cat /proc/cpuinfo | grep '^flags' | head -n 1 | grep -w ht] && test $($CPUS*512*1024) -le $MEMTOTAL && global CPUS := $(($CPUS*3)/2) } export_if_blank STAGE_NAME=$[echo $0 | sed 's@.*/\(.*\)\.sh@\1@] test ! -z $BUILD_VERBOSE && global VERBOSITY := '"V=1'" export_if_blank BUILD_STATIC=busybox,toybox,binutils,gcc-core,gcc-g++,make # If record-commands.sh set up a wrapper directory, adjust $PATH. export PATH if test -z $OLDPATH { export OLDPATH="$PATH" test -z $BUSYBOX || global BUSYBOX := 'busybox' test -f "$HOSTTOOLS/$(BUSYBOX:-toybox)" && global PATH := $[hosttools_path] || global PATH := ""$[hosttools_path]:$PATH"" if test -f "$WRAPDIR/wrappy" { global OLDPATH := $PATH mkdir -p "$BUILD/logs" test $Status -ne 0 && echo "Bad $WRAPDIR" > !2 && dienow global PATH := $WRAPDIR } } export WRAPPY_LOGPATH="$BUILD/logs/cmdlines.$ARCH_NAME.early" (CommandList children: [ (If arms: [ (if_arm cond: [ (C {(Lit_Other "[")} {(-z)} {(DQ ($ VSub_Name "$NO_SANITIZE_ENVIRONMENT"))} {(Lit_Other "]")}) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:TEMP) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} { (CommandSubPart command_list: (CommandList children: [ (C {(sed)} {(-n)} {(SQ <"s/.*export[ \\t]*\\([^=]*\\)=.*/\\1/p">)} {(config)} ) ] ) left_token: spids: [44 54] ) } ) (C {(sed)} {(SQ <"s/ /,/g">)}) ] negated: False ) ] ) left_token: spids: [41 63] ) } spids: [40] ) ] spids: [40] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:TEMP) op: Equal rhs: { (DQ ($ VSub_Name "$TEMP") (",LANG,PATH,SHELL,TERM,USER,USERNAME,LOGNAME,PWD,EDITOR,HOME") ) } spids: [72] ) ] spids: [72] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:TEMP) op: Equal rhs: { (DQ ($ VSub_Name "$TEMP") (",DISPLAY,_,TOPSHELL,START_TIME,STAGE_NAME,TOOLCHAIN_PREFIX") ) } spids: [79] ) ] spids: [79] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:TEMP) op: Equal rhs: { (DQ ($ VSub_Name "$TEMP") (",HOST_ARCH,WRAPPY_LOGPATH,OLDPATH,http_proxy,ftp_proxy") ) } spids: [86] ) ] spids: [86] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:TEMP) op: Equal rhs: {(DQ ($ VSub_Name "$TEMP") (",https_proxy,no_proxy,TEMP,TMPDIR,FORK,MUSL"))} spids: [93] ) ] spids: [93] ) (ForEach iter_name: i iter_words: [ { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [(C {(env)}) (C {(sed)} {(-n)} {(SQ <"s/=.*//p">)})] negated: False ) ] ) left_token: spids: [112 124] ) } ] do_arg_iter: False body: (DoGroup children: [ (AndOr children: [ (C {(is_in_list)} {($ VSub_Name "$i")} {(DQ ($ VSub_Name "$TEMP"))}) (ControlFlow token:) ] op_id: Op_DAmp ) (AndOr children: [ (C {(Lit_Other "[")} { (DQ (BracedVarSub token: suffix_op: (Slice begin: (ArithWord w:{(Lit_Digits 0)}) length: (ArithWord w:{(Lit_Digits 7)}) ) spids: [146 152] ) ) } {(Lit_Other "=") (Lit_Other "=")} {(DQ (DISTCC_))} {(Lit_Other "]")} ) (ControlFlow token:) ] op_id: Op_DAmp ) (AndOr children: [ (C {(Lit_Other "[")} { (DQ (BracedVarSub token: suffix_op: (Slice begin: (ArithWord w:{(Lit_Digits 0)}) length: (ArithWord w:{(Lit_Digits 7)}) ) spids: [172 178] ) ) } {(Lit_Other "=") (Lit_Other "=")} {(DQ (CCACHE_))} {(Lit_Other "]")} ) (ControlFlow token:) ] op_id: Op_DAmp ) (SimpleCommand words: [{(unset)} {($ VSub_Name "$i")}] redirects: [(Redir op_id:Redir_Great fd:2 arg_word:{(/dev/null)} spids:[200])] ) ] spids: [127 204] ) spids: [111 -1] ) ] spids: [-1 32] ) ] spids: [-1 206] ) (FuncDef name: export_if_blank body: (BraceGroup children: [ (AndOr children: [ (C {(Lit_Other "[")} {(-z)} { (DQ (CommandSubPart command_list: (CommandList children: [ (C {(eval)} { (DQ ("echo ") (EscapedLiteralPart token:) (EscapedLiteralPart token: ) ("{") (BracedVarSub token: suffix_op: (PatSub pat: {("=*")} replace: {(SQ )} do_all: False do_prefix: False do_suffix: False ) spids: [233 238] ) ("}") (EscapedLiteralPart token:) ) } ) ] ) left_token: spids: [225 242] ) ) } {(Lit_Other "]")} ) (C {(export)} {(DQ ($ VSub_Number "$1"))}) ] op_id: Op_DAmp ) ] spids: [217] ) spids: [213 216] ) (C {(export_if_blank)} {(Lit_VarLike "MIRROR_LIST=") (DQ ("http://landley.net/code/aboriginal/mirror http://127.0.0.1/code/aboriginal/mirror")) } ) (C {(export_if_blank)} {(Lit_VarLike "TOP=") (CommandSubPart command_list: (CommandList children:[(C {(pwd)})]) left_token: spids: [277 279] ) } ) (C {(export_if_blank)} {(Lit_VarLike "SOURCES=") (DQ ($ VSub_Name "$TOP") (/sources))}) (C {(export_if_blank)} {(Lit_VarLike "SRCDIR=") (DQ ($ VSub_Name "$TOP") (/packages))}) (C {(export_if_blank)} {(Lit_VarLike "PATCHDIR=") (DQ ($ VSub_Name "$SOURCES") (/patches))}) (C {(export_if_blank)} {(Lit_VarLike "BUILD=") (DQ ($ VSub_Name "$TOP") (/build))}) (C {(export_if_blank)} {(Lit_VarLike "SRCTREE=") (DQ ($ VSub_Name "$BUILD") (/packages))}) (C {(export_if_blank)} {(Lit_VarLike "HOSTTOOLS=") (DQ ($ VSub_Name "$BUILD") (/host))}) (C {(export_if_blank)} {(Lit_VarLike "WRAPDIR=") (DQ ($ VSub_Name "$BUILD") (/record-commands))}) (AndOr children: [ (C {(Lit_Other "[")} {(KW_Bang "!")} {(-z)} {(DQ ($ VSub_Name "$MY_PATCH_DIR"))} {(Lit_Other "]")}) (C {(export)} {(Lit_VarLike "MY_PATCH_DIR=") (DQ (CommandSubPart command_list: (CommandList children: [(C {(readlink)} {(-e)} {(DQ ($ VSub_Name "$MY_PATCH_DIR"))})] ) left_token: spids: [356 364] ) ) } ) ] op_id: Op_DAmp ) (C {(export)} {(Lit_VarLike "WORK=") (DQ (${ VSub_Name BUILD) (/host-temp))}) (C {(export)} {(Lit_VarLike "ARCH_NAME=") (host)}) (C {(export_if_blank)} {(Lit_VarLike "CC=") (cc)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:MEMTOTAL) op: Equal rhs: { (DQ (CommandSubPart command_list: (CommandList children: [(C {(awk)} {(SQ <"/MemTotal:/{print $2}">)} {(/proc/meminfo)})] ) left_token: spids: [404 412] ) ) } spids: [402] ) ] spids: [402] ) (If arms: [ (if_arm cond: [(C {(Lit_Other "[")} {(-z)} {(DQ ($ VSub_Name "$CPUS"))} {(Lit_Other "]")})] action: [ (C {(export)} {(Lit_VarLike "CPUS=") (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {(/sys/devices/system/cpu/cpu) (Lit_Other "[") (0-9) (Lit_Other "]") (Lit_Other "*") } ) (C {(wc)} {(-w)}) ] negated: False ) ] ) left_token: spids: [433 447] ) } ) (AndOr children: [ (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$CPUS"))} {(-lt)} {(1)} {(Lit_Other "]")}) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:CPUS) op:Equal rhs:{(1)} spids:[464])] spids: [464] ) ] op_id: Op_DAmp ) (AndOr children: [ (C {(Lit_Other "[")} {(-z)} { (DQ (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(cat)} {(/proc/cpuinfo)}) (C {(grep)} {(SQ <"^flags">)}) (C {(head)} {(-n)} {(1)}) (C {(grep)} {(-w)} {(ht)}) ] negated: False ) ] ) left_token: spids: [483 511] ) ) } {(Lit_Other "]")} ) (AndOr children: [ (C {(Lit_Other "[")} { (ArithSubPart anode: (ArithBinary op_id: Arith_Star left: (ArithBinary op_id: Arith_Star left: (ArithWord w:{($ VSub_Name "$CPUS")}) right: (ArithWord w:{(Lit_Digits 512)}) ) right: (ArithWord w:{(Lit_Digits 1024)}) ) spids: [521 528] ) } {(-le)} {($ VSub_Name "$MEMTOTAL")} {(Lit_Other "]")} ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:CPUS) op: Equal rhs: { (ArithSubPart anode: (ArithBinary op_id: Arith_Slash left: (ArithBinary op_id: Arith_Star left: (ArithWord w:{($ VSub_Name "$CPUS")}) right: (ArithWord w:{(Lit_Digits 3)}) ) right: (ArithWord w:{(Lit_Digits 2)}) ) spids: [540 549] ) } spids: [539] ) ] spids: [539] ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] spids: [-1 427] ) ] spids: [-1 551] ) (C {(export_if_blank)} {(Lit_VarLike "STAGE_NAME=") (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Number "$0")}) (C {(sed)} {(SQ <"s@.*/\\(.*\\)\\.sh@\\1@">)}) ] negated: False ) ] ) left_token: spids: [557 569] ) } ) (AndOr children: [ (C {(Lit_Other "[")} {(KW_Bang "!")} {(-z)} {(DQ ($ VSub_Name "$BUILD_VERBOSE"))} {(Lit_Other "]")} ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:VERBOSITY) op:Equal rhs:{(DQ ("V=1"))} spids:[585])] spids: [585] ) ] op_id: Op_DAmp ) (C {(export_if_blank)} {(Lit_VarLike "BUILD_STATIC=") (busybox) (Lit_Comma ",") (toybox) (Lit_Comma ",") (binutils) (Lit_Comma ",") (gcc-core) (Lit_Comma ",") (gcc-g) (Lit_Other "+") (Lit_Other "+") (Lit_Comma ",") (make) } ) (C {(export)} {(PATH)}) (If arms: [ (if_arm cond: [(C {(Lit_Other "[")} {(-z)} {(DQ ($ VSub_Name "$OLDPATH"))} {(Lit_Other "]")})] action: [ (C {(export)} {(Lit_VarLike "OLDPATH=") (DQ ($ VSub_Name "$PATH"))}) (AndOr children: [ (C {(Lit_Other "[")} {(-z)} {(DQ ($ VSub_Name "$BUSYBOX"))} {(Lit_Other "]")}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:BUSYBOX) op: Equal rhs: {(busybox)} spids: [652] ) ] spids: [652] ) ] op_id: Op_DPipe ) (AndOr children: [ (C {(Lit_Other "[")} {(-f)} { (DQ ($ VSub_Name "$HOSTTOOLS") (/) (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(toybox)}) spids: [663 667] ) ) } {(Lit_Other "]")} ) (AndOr children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:PATH) op: Equal rhs: { (DQ (CommandSubPart command_list: (CommandList children:[(C {(hosttools_path)})]) left_token: spids: [677 679] ) ) } spids: [675] ) ] spids: [675] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:PATH) op: Equal rhs: { (DQ (CommandSubPart command_list: (CommandList children:[(C {(hosttools_path)})]) left_token: spids: [687 689] ) (":") ($ VSub_Name "$PATH") ) } spids: [685] ) ] spids: [685] ) ] op_id: Op_DPipe ) ] op_id: Op_DAmp ) (If arms: [ (if_arm cond: [ (C {(Lit_Other "[")} {(-f)} {(DQ ($ VSub_Name "$WRAPDIR") (/wrappy))} {(Lit_Other "]")} ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:OLDPATH) op: Equal rhs: {(DQ ($ VSub_Name "$PATH"))} spids: [713] ) ] spids: [713] ) (C {(mkdir)} {(-p)} {(DQ ($ VSub_Name "$BUILD") (/logs))}) (AndOr children: [ (C {(Lit_Other "[")} {($ VSub_QMark "$?")} {(-ne)} {(0)} {(Lit_Other "]")}) (AndOr children: [ (SimpleCommand words: [{(echo)} {(DQ ("Bad ") ($ VSub_Name "$WRAPDIR"))}] redirects: [ (Redir op_id: Redir_GreatAnd fd: -1 arg_word: {(2)} spids: [748] ) ] ) (C {(dienow)}) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:PATH) op: Equal rhs: {(DQ ($ VSub_Name "$WRAPDIR"))} spids: [756] ) ] spids: [756] ) ] spids: [-1 710] ) ] spids: [-1 762] ) ] spids: [-1 629] ) ] spids: [-1 764] ) (C {(export)} {(Lit_VarLike "WRAPPY_LOGPATH=") (DQ ($ VSub_Name "$BUILD") (/logs/cmdlines.) ($ VSub_Name "$ARCH_NAME") (.early)) } ) ] )