the_memo2.sh 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807
  1. #!/bin/bash -x
  2. BUILD_ROOT="$(pwd)"
  3. ROOT_LOG_FOLDER="$BUILD_ROOT/Logs"
  4. VERIFY="true"
  5. PLATFORM="AppleTVOS"
  6. PLATFORM_LOWER="appletvos"
  7. SDK_VERSION="$(xcrun --show-sdk-version --sdk $PLATFORM_LOWER)"
  8. ROOT_PREFIX="fs/jb/usr"
  9. SKEL_PREFIX="$BUILD_ROOT/skel"
  10. ALREADY_BUILT="$BUILD_ROOT/tracked"
  11. CLANG_PATH="$(xcrun -f clang)"
  12. CLANGPLUS_PATH="$(xcrun -f clang++)"
  13. MIN_VERSION="-mappletvos-version-min=13.0"
  14. ARCH="arm64"
  15. SDK_PATH="$(xcrun --sdk $PLATFORM_LOWER --show-sdk-path)"
  16. SPEAK="false"
  17. EXTRA_LD_FLAGS=""
  18. HOST="aarch64"
  19. FORCE="false"
  20. LOG_VERBOSE=""
  21. OPEN_LOG="false"
  22. TRIM="false"
  23. usage() {
  24. echo "usage: $0 [-s|--speak-updates] [-i|--insecure] [-v|--verbose] [-f|--force] [-o|--open-active-log] [-t|--trim-bootstrap]"
  25. trap - INT TERM EXIT
  26. exit 0
  27. }
  28. while test $# -gt 0; do
  29. case "$1" in
  30. -h|--help)
  31. usage
  32. ;;
  33. -v|--verbose)
  34. LOG_VERBOSE="verbose"
  35. shift
  36. ;;
  37. -i|--insecure|--no-verify)
  38. VERIFY="false"
  39. echo "Working without verifying packages..."
  40. echo "YOU BETTER KNOW WHAT YOU'RE DOING"
  41. sleep 2 #Give them a couple seconds to think about what they're about to do
  42. shift
  43. ;;
  44. -f|--force)
  45. FORCE="true"
  46. shift
  47. ;;
  48. -s|--speak-updates|--speak)
  49. SPEAK="true"
  50. shift
  51. ;;
  52. -t|--trim-bootstrap|--trim)
  53. TRIM="true"
  54. shift
  55. ;;
  56. -o|--open-log|--open)
  57. OPEN_LOG="true"
  58. shift
  59. ;;
  60. *)
  61. break
  62. ;;
  63. esac
  64. done
  65. # for some reason the files signed this way don't run on tvOS 9 anymore
  66. codesign() {
  67. BIN=$1
  68. ENT=$2
  69. if [[ ! -z $ENT ]]; then
  70. ldid -S$ENT $BIN
  71. else
  72. ldid -S $BIN
  73. fi
  74. }
  75. printPreprocessor() {
  76. $(xcrun --sdk $PLATFORM_LOWER --find clang) -E - - -dM < /dev/null
  77. }
  78. sayIfVerbal() {
  79. if [[ $SPEAK == "true" ]]; then
  80. say $1
  81. fi
  82. }
  83. splitName() {
  84. IN=$1
  85. i=0
  86. while [ "$IN" != "$iter" ] ;do
  87. # extract the substring from start of string up to delimiter.
  88. iter=${IN%%-*}
  89. # delete this first "element" AND next separator, from $IN.
  90. IN="${IN#$iter-}"
  91. ((i=i+1))
  92. if [[ $i == 1 ]]; then
  93. echo "set RAW_NAME var to $iter"
  94. RAW_NAME=$iter
  95. elif [[ $i == 2 ]]; then
  96. VERSION=$iter
  97. echo "set VERSION var to $iter"
  98. fi
  99. #echo $iter at $i
  100. done
  101. }
  102. spinner() {
  103. local pid=$!
  104. local delay=0.75
  105. local spinstr='|/-\'
  106. while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do
  107. local temp=${spinstr#?}
  108. printf " [%c]" "$spinstr"
  109. local spinstr=$temp${spinstr%"$temp"}
  110. sleep $delay
  111. printf "\b\b\b\b\b"
  112. done
  113. wait $pid
  114. return $?
  115. }
  116. setBuilt() {
  117. DIRECTORY_NAME=$1
  118. FULL=$ALREADY_BUILT/$DIRECTORY_NAME
  119. touch "$FULL"
  120. }
  121. checkStatus() {
  122. PKG=$1
  123. STATUS=$2
  124. FINISHED=$3
  125. if [[ $STATUS != 0 ]]; then
  126. echo "configure or make $PKG returned with non zero: $STATUS check $LOG_FILE for errors!"
  127. sayIfVerbal "configure or make of $PKG returned with non zero: $STATUS"
  128. open $LOG_FILE
  129. #printPreprocessor
  130. #/bin/bash ./finish.sh
  131. exit $STATUS
  132. else
  133. #echo "make returned with zero"
  134. if [[ $FINISHED == "true" ]]; then
  135. setBuilt $PKG
  136. fi
  137. fi
  138. }
  139. checkBuilt() {
  140. if [[ "$FORCE" == "true" ]]; then
  141. return 0
  142. fi
  143. DIRECTORY_NAME=$1
  144. FULL=$ALREADY_BUILT/$DIRECTORY_NAME
  145. if [[ ! -f $FULL ]]; then
  146. return 0
  147. fi
  148. return 1
  149. }
  150. notifyProgress() {
  151. echo "$1"
  152. sayIfVerbal "$1"
  153. }
  154. checkSHA256() {
  155. if [[ "$VERIFY" == "true" ]]; then
  156. FILE="$1"
  157. VALID_SHA="$2"
  158. VERIFY_TEST="`shasum -a 256 $FILE | cut -c 1-64`"
  159. if [[ "$VERIFY_TEST" != "$VALID_SHA" ]]; then
  160. echo "Failed to validate SHA256 signature for $FILE"
  161. trap - INT TERM EXIT
  162. exit 127
  163. fi
  164. echo "*** VALID SIGNATURE"
  165. fi
  166. }
  167. checkPGPSig() {
  168. if [[ "$VERIFY" == "true" ]]; then
  169. SIGFILE="$1"
  170. FILE="$2"
  171. local VERIFY_TEST="`gpg --verify $SIGFILE $FILE 2>&1 | grep 'Good signature'`"
  172. if [[ "$VERIFY_TEST" == "" ]]; then
  173. echo "Failed to validate PGP signature for $FILE"
  174. trap - INT TERM EXIT
  175. exit 127
  176. fi
  177. echo "*** VALID SIGNATURE"
  178. fi
  179. }
  180. exportBuildScript() {
  181. EXPORT_FILE="$1"
  182. echo -e "#!/bin/bash" > $EXPORT_FILE
  183. echo -e "\nexport CC=$(xcrun --sdk $PLATFORM_LOWER --find clang)" >> $EXPORT_FILE
  184. echo -e "export CXX=$(xcrun --sdk $PLATFORM_LOWER --find clang++)" >> $EXPORT_FILE
  185. echo -e "export LD=$(xcrun --sdk $PLATFORM_LOWER --find ld)" >> $EXPORT_FILE
  186. echo -e "export AR=$(xcrun --sdk $PLATFORM_LOWER --find ar)" >> $EXPORT_FILE
  187. echo -e "export 'CPP=$(xcrun --sdk $PLATFORM_LOWER -f clang) -E -D__arm__ -I$SDKROOT/usr/include' " >> $EXPORT_FILE
  188. echo -e "export 'CXXCPP=$(xcrun --sdk $PLATFORM_LOWER -f clang++) -E -D__arm__ -I$SDKROOT/usr/include' " >> $EXPORT_FILE
  189. echo -e "export RANLIB=$(xcrun --sdk $PLATFORM_LOWER --find ranlib)" >> $EXPORT_FILE
  190. echo -e "export LIBTOOL=$(xcrun --sdk $PLATFORM_LOWER --find libtool)" >> $EXPORT_FILE
  191. echo -e "export STRIP=$(xcrun --sdk $PLATFORM_LOWER --find strip)" >> $EXPORT_FILE
  192. echo -e "export 'CFLAGS=-arch arm64 -isysroot $SDKROOT -m$PLATFORM_LOWER-version-min=$VER_MIN -I$SKEL_PREFIX/$ROOT_PREFIX/include/ -DARM -DARM64 -D__arm64__ -Wno-unused-command-line-argument'" >> $EXPORT_FILE
  193. echo -e "export 'CXXFLAGS=-arch arm64 -isysroot $SDKROOT -m$PLATFORM_LOWER-version-min=$VER_MIN -I$SKEL_PREFIX/$ROOT_PREFIX/include/ -DARM -DARM64 -D__arm64__ -Wno-unused-command-line-argument'" >> $EXPORT_FILE
  194. echo -e "export 'LDFLAGS=-arch arm64 -isysroot $SDKROOT -L$SKEL_PREFIX/$ROOT_PREFIX/lib/ $EXTRA_LD_FLAGS'" >> $EXPORT_FILE
  195. echo -e "./configure --prefix=/$ROOT_PREFIX --host=$HOST-apple-darwin --target=$HOST-apple-darwin --disable-dependency-tracking --without-manpages --disable-tests $EXTRA_CFG" >> $EXPORT_FILE
  196. echo -e "make -j8 DESTDIR="$SKEL_PREFIX" install" >> $EXPORT_FILE
  197. chmod +x $EXPORT_FILE
  198. }
  199. buildProduct() {
  200. PKG_NAME=$1
  201. EXTRA_CFG=$2
  202. LOG_FILE="$ROOT_LOG_FOLDER/$PKG_NAME.log"
  203. #exit 2
  204. touch $LOG_FILE
  205. echo $PKG_NAME
  206. echo "build output going to: " $LOG_FILE
  207. echo $EXTRA_CFG
  208. local SDKROOT=$(xcrun --sdk $PLATFORM_LOWER --show-sdk-path)
  209. local VER_MIN=13.0
  210. export CC=$(xcrun --sdk $PLATFORM_LOWER --find clang)
  211. export CXX=$(xcrun --sdk $PLATFORM_LOWER --find clang++)
  212. export LD=$(xcrun --sdk $PLATFORM_LOWER --find ld)
  213. export AR=$(xcrun --sdk $PLATFORM_LOWER --find ar)
  214. #export CPP="$(xcrun --sdk $PLATFORM_LOWER -f clang) -E -D__arm__ -D__arm64__ -I$SKEL_PREFIX/$ROOT_PREFIX/include/ -I$SDKROOT/usr/include -arch arm64"
  215. #export CXXCPP="$(xcrun --sdk $PLATFORM_LOWER -f clang++) -E -D__arm__ -D__arm64__ -I$SKEL_PREFIX/$ROOT_PREFIX/include/ -I$SDKROOT/usr/include -arch arm64"
  216. export CPP="$(xcrun --sdk $PLATFORM_LOWER -f clang) -E -D__arm__ -I$SDKROOT/usr/include"
  217. export CXXCPP="$(xcrun --sdk $PLATFORM_LOWER -f clang++) -E -D__arm__ -I$SDKROOT/usr/include"
  218. export RANLIB=$(xcrun --sdk $PLATFORM_LOWER --find ranlib)
  219. export LIBTOOL=$(xcrun --sdk $PLATFORM_LOWER --find libtool)
  220. export STRIP=$(xcrun --sdk $PLATFORM_LOWER --find strip)
  221. export CFLAGS="-arch arm64 -isysroot $SDKROOT -m$PLATFORM_LOWER-version-min=$VER_MIN -I$SKEL_PREFIX/$ROOT_PREFIX/include/ -DARM -DARM64 -D__arm64__ -Wno-unused-command-line-argument"
  222. export CXXFLAGS=$CFLAGS
  223. export LDFLAGS="-arch arm64 -isysroot $SDKROOT -L$SKEL_PREFIX/$ROOT_PREFIX/lib/ $EXTRA_LD_FLAGS"
  224. exportBuildScript "finish.sh"
  225. notifyProgress "configuring $PKG_NAME"
  226. if [[ $LOG_VERBOSE == "verbose"* ]]; then
  227. ./configure --prefix=/$ROOT_PREFIX --host=$HOST-apple-darwin --target=$HOST-apple-darwin --disable-dependency-tracking --without-manpages --disable-tests $EXTRA_CFG | tee "${LOG_FILE}"
  228. EC=$(grep "configure: error:" -i "${LOG_FILE}" -c)
  229. checkStatus $PKG_NAME $EC "false"
  230. else
  231. (./configure --prefix=/$ROOT_PREFIX --host=$HOST-apple-darwin --target=$HOST-apple-darwin --disable-dependency-tracking --without-manpages --disable-tests $EXTRA_CFG > "${LOG_FILE}" 2>&1)
  232. checkStatus $PKG_NAME $? "false"
  233. if [[ $OPEN_LOG == "true" ]]; then
  234. open "${LOG_FILE}"
  235. fi
  236. fi
  237. notifyProgress "making $PKG_NAME"
  238. echo -e "\n\nPOST CONFIGURE\n\n" >> "$LOG_FILE"
  239. if [[ $LOG_VERBOSE == "verbose"* ]]; then
  240. make -j8 DESTDIR="$SKEL_PREFIX" install | tee -a "${LOG_FILE}"
  241. EC=$(grep "fatal error:" -i "${LOG_FILE}" -c)
  242. checkStatus $PKG_NAME $EC "true"
  243. else
  244. (make -j8 DESTDIR="$SKEL_PREFIX" install >> "${LOG_FILE}" 2>&1) #& spinner
  245. checkStatus $PKG_NAME $? "true"
  246. fi
  247. cd "$BUILD_ROOT"
  248. }
  249. downloadProduct() {
  250. cd "$BUILD_ROOT"
  251. DOWNLOAD_LINK=$1
  252. FILENAME=$(basename $DOWNLOAD_LINK)
  253. SIG_DOWNLOAD=$2
  254. RAW_NAME=$3
  255. VERSION=$4
  256. FILE_EXTENSION="${FILENAME##*.}"
  257. DIRECTORY_NAME="$RAW_NAME-$VERSION"
  258. SIG_FILE=$(basename $SIG_DOWNLOAD)
  259. if [[ ! -e $FILENAME ]]; then
  260. echo "Downloading $FILENAME"
  261. curl -LO $DOWNLOAD_LINK
  262. if [[ ! $SIG_FILE == "-" ]]; then
  263. curl -LO $SIG_DOWNLOAD
  264. checkPGPSig $SIG_FILE $FILENAME
  265. fi
  266. else
  267. echo "Using existing $FILENAME"
  268. fi
  269. rm -rf $DIRECTORY_NAME
  270. if [[ $FILE_EXTENSION == "gz" ]]; then
  271. echo "is gz file!"
  272. tar xzvf $FILENAME
  273. fi
  274. if [[ $FILE_EXTENSION == "xz" ]]; then
  275. echo "is lzma file!"
  276. tar xJvf $FILENAME
  277. fi
  278. if [[ $FILE_EXTENSION == "bz2" ]]; then
  279. echo "is bzip2 file!"
  280. tar xjvf $FILENAME
  281. fi
  282. WORKING_DIR=$DIRECTORY_NAME
  283. PKG_VERSION=$VERSION-1
  284. cd "$WORKING_DIR"
  285. #buildProduct
  286. }
  287. patchBash() {
  288. if [[ "$PLATFORM" == "AppleTVOS" ]]; then
  289. sed -i -- 's|^#undef HAVE_SYS_SIGLIST$|#define HAVE_SYS_SIGLIST 1|' config.h.in
  290. fi
  291. }
  292. patchDpkg() {
  293. if [[ "$PLATFORM" == "AppleTVOS" ]]; then
  294. sed -i -- "s|#define ARCHITECTURE \"darwin-arm\"|#define ARCHITECTURE \"$PLATFORM_LOWER-$ARCH\"|" config.h
  295. sed -i -- 's|gtar|tar|' config.h
  296. fi
  297. }
  298. # DONT USE UNLESS YOU ARE ON 11+; OVERWRITE BASH (or any other apple-signed file, for that matter), LEAD TO BRICK
  299. # 10.2 and up
  300. buildBashAndFriends() {
  301. notifyProgress "Building readline"
  302. buildReadline
  303. notifyProgress "Building ncurses"
  304. buildNcurses
  305. notifyProgress "Building bash"
  306. buildBash
  307. }
  308. buildReadline() {
  309. PKG_NAME="readline-7.0"
  310. checkBuilt $PKG_NAME
  311. if [[ $? != 0 ]]; then
  312. echo "$PKG_NAME already exists, skipping!"
  313. else
  314. echo "building $PKG_NAME..."
  315. splitName $PKG_NAME
  316. downloadProduct http://gnu.askapache.com/readline/readline-7.0.tar.gz http://gnu.askapache.com/readline/readline-7.0.tar.gz.sig $RAW_NAME $VERSION
  317. buildProduct $PKG_NAME
  318. codesign "$SKEL_PREFIX/$ROOT_PREFIX/lib/libhistory.7.0.dylib"
  319. codesign "$SKEL_PREFIX/$ROOT_PREFIX/lib/libreadline.7.0.dylib"
  320. fi
  321. }
  322. fixSystem() {
  323. FILE="$1"
  324. echo '#define PROC_PIDPATHINFO_MAXSIZE (1024)' >> "$FILE"
  325. echo 'static int file_exist(const char *filename) {' >> "$FILE"
  326. echo ' struct stat buffer;' >> "$FILE"
  327. echo ' int r = stat(filename, &buffer);' >> "$FILE"
  328. echo ' return (r == 0);' >> "$FILE"
  329. echo '}' >> "$FILE"
  330. echo '' >> "$FILE"
  331. echo 'static char *searchpath(const char *binaryname){' >> "$FILE"
  332. echo ' if (strstr(binaryname, "/") != NULL){' >> "$FILE"
  333. echo ' if (file_exist(binaryname)){' >> "$FILE"
  334. echo ' char *foundpath = malloc((strlen(binaryname) + 1) * (sizeof(char)));' >> "$FILE"
  335. echo ' strcpy(foundpath, binaryname);' >> "$FILE"
  336. echo ' return foundpath;' >> "$FILE"
  337. echo ' } else {' >> "$FILE"
  338. echo ' return NULL;' >> "$FILE"
  339. echo ' }' >> "$FILE"
  340. echo ' }' >> "$FILE"
  341. echo ' ' >> "$FILE"
  342. echo ' char *pathvar = getenv("PATH");' >> "$FILE"
  343. echo ' ' >> "$FILE"
  344. echo ' char *dir = strtok(pathvar,":");' >> "$FILE"
  345. echo ' while (dir != NULL){' >> "$FILE"
  346. echo ' char searchpth[PROC_PIDPATHINFO_MAXSIZE];' >> "$FILE"
  347. echo ' strcpy(searchpth, dir);' >> "$FILE"
  348. echo ' strcat(searchpth, "/");' >> "$FILE"
  349. echo ' strcat(searchpth, binaryname);' >> "$FILE"
  350. echo ' ' >> "$FILE"
  351. echo ' if (file_exist(searchpth)){' >> "$FILE"
  352. echo ' char *foundpath = malloc((strlen(searchpth) + 1) * (sizeof(char)));' >> "$FILE"
  353. echo ' strcpy(foundpath, searchpth);' >> "$FILE"
  354. echo ' return foundpath;' >> "$FILE"
  355. echo ' }' >> "$FILE"
  356. echo ' ' >> "$FILE"
  357. echo ' dir = strtok(NULL, ":");' >> "$FILE"
  358. echo ' }' >> "$FILE"
  359. echo ' return NULL;' >> "$FILE"
  360. echo '}' >> "$FILE"
  361. echo '' >> "$FILE"
  362. echo 'static int isShellScript(const char *path){' >> "$FILE"
  363. echo ' FILE *file = fopen(path, "r");' >> "$FILE"
  364. echo ' uint8_t header[2];' >> "$FILE"
  365. echo ' if (fread(header, sizeof(uint8_t), 2, file) == 2){' >> "$FILE"
  366. echo " if (header[0] == '#' && header[1] == '!'){" >> "$FILE"
  367. echo ' fclose(file);' >> "$FILE"
  368. echo ' return 1;' >> "$FILE"
  369. echo ' }' >> "$FILE"
  370. echo ' }' >> "$FILE"
  371. echo ' fclose(file);' >> "$FILE"
  372. echo ' return -1;' >> "$FILE"
  373. echo '}' >> "$FILE"
  374. echo '' >> "$FILE"
  375. echo 'static char *getInterpreter(char *path){' >> "$FILE"
  376. echo ' FILE *file = fopen(path, "r");' >> "$FILE"
  377. echo ' char *interpreterLine = NULL;' >> "$FILE"
  378. echo ' unsigned long lineSize = 0;' >> "$FILE"
  379. echo ' getline(&interpreterLine, &lineSize, file);' >> "$FILE"
  380. echo ' ' >> "$FILE"
  381. echo ' char *rawInterpreter = (interpreterLine+2);' >> "$FILE"
  382. echo ' rawInterpreter = strtok(rawInterpreter, " ");' >> "$FILE"
  383. echo ' rawInterpreter = strtok(rawInterpreter, "\n");' >> "$FILE"
  384. echo ' ' >> "$FILE"
  385. echo ' char *interpreter = malloc((strlen(rawInterpreter)+1) * sizeof(char));' >> "$FILE"
  386. echo ' strcpy(interpreter, rawInterpreter);' >> "$FILE"
  387. echo ' ' >> "$FILE"
  388. echo ' free(interpreterLine);' >> "$FILE"
  389. echo ' fclose(file);' >> "$FILE"
  390. echo ' return interpreter;' >> "$FILE"
  391. echo '}' >> "$FILE"
  392. echo '' >> "$FILE"
  393. echo 'static char *fixedCmd(const char *cmdStr){' >> "$FILE"
  394. echo ' char *cmdCpy = malloc((strlen(cmdStr)+1) * sizeof(char));' >> "$FILE"
  395. echo ' strcpy(cmdCpy, cmdStr);' >> "$FILE"
  396. echo ' ' >> "$FILE"
  397. echo ' char *cmd = strtok(cmdCpy, " ");' >> "$FILE"
  398. echo ' ' >> "$FILE"
  399. echo ' uint8_t size = strlen(cmd) + 1;' >> "$FILE"
  400. echo ' ' >> "$FILE"
  401. echo ' char *args = cmdCpy + size;' >> "$FILE"
  402. echo ' if ((strlen(cmdStr) - strlen(cmd)) == 0)' >> "$FILE"
  403. echo ' args = NULL;' >> "$FILE"
  404. echo ' ' >> "$FILE"
  405. echo ' char *abs_path = searchpath(cmd);' >> "$FILE"
  406. echo ' if (abs_path){' >> "$FILE"
  407. echo ' int isScript = isShellScript(abs_path);' >> "$FILE"
  408. echo ' if (isScript == 1){' >> "$FILE"
  409. echo ' char *interpreter = getInterpreter(abs_path);' >> "$FILE"
  410. echo ' ' >> "$FILE"
  411. echo ' uint8_t commandSize = strlen(interpreter) + 1 + strlen(abs_path);' >> "$FILE"
  412. echo ' ' >> "$FILE"
  413. echo ' if (args){' >> "$FILE"
  414. echo ' commandSize += 1 + strlen(args);' >> "$FILE"
  415. echo ' }' >> "$FILE"
  416. echo ' ' >> "$FILE"
  417. echo ' char *rawCommand = malloc(sizeof(char) * (commandSize + 1));' >> "$FILE"
  418. echo ' strcpy(rawCommand, interpreter);' >> "$FILE"
  419. echo ' strcat(rawCommand, " ");' >> "$FILE"
  420. echo ' strcat(rawCommand, abs_path);' >> "$FILE"
  421. echo ' ' >> "$FILE"
  422. echo ' if (args){' >> "$FILE"
  423. echo ' strcat(rawCommand, " ");' >> "$FILE"
  424. echo ' strcat(rawCommand, args);' >> "$FILE"
  425. echo ' }' >> "$FILE"
  426. echo ' rawCommand[(commandSize)+1] = "\0";' >> "$FILE"
  427. echo ' ' >> "$FILE"
  428. echo ' free(interpreter);' >> "$FILE"
  429. echo ' free(abs_path);' >> "$FILE"
  430. echo ' free(cmdCpy);' >> "$FILE"
  431. echo ' ' >> "$FILE"
  432. echo ' return rawCommand;' >> "$FILE"
  433. echo ' } else {' >> "$FILE"
  434. echo ' uint8_t commandSize = strlen(abs_path);' >> "$FILE"
  435. echo ' ' >> "$FILE"
  436. echo ' if (args){' >> "$FILE"
  437. echo ' commandSize += 1 + strlen(args);' >> "$FILE"
  438. echo ' }' >> "$FILE"
  439. echo ' ' >> "$FILE"
  440. echo ' char *rawCommand = malloc(sizeof(char) * (commandSize + 1));' >> "$FILE"
  441. echo ' strcat(rawCommand, abs_path);' >> "$FILE"
  442. echo ' ' >> "$FILE"
  443. echo ' if (args){' >> "$FILE"
  444. echo ' strcat(rawCommand, " ");' >> "$FILE"
  445. echo ' strcat(rawCommand, args);' >> "$FILE"
  446. echo ' }' >> "$FILE"
  447. echo ' rawCommand[(commandSize)+1] = "\0";' >> "$FILE"
  448. echo ' ' >> "$FILE"
  449. echo ' free(abs_path);' >> "$FILE"
  450. echo ' free(cmdCpy);' >> "$FILE"
  451. echo ' ' >> "$FILE"
  452. echo ' return rawCommand;' >> "$FILE"
  453. echo ' }' >> "$FILE"
  454. echo ' }' >> "$FILE"
  455. echo ' return cmdCpy;' >> "$FILE"
  456. echo '}' >> "$FILE"
  457. echo '' >> "$FILE"
  458. echo 'int RunCmd(const char *cmd) {' >> "$FILE"
  459. echo ' pid_t pid;' >> "$FILE"
  460. echo ' char *rawCmd = fixedCmd(cmd);' >> "$FILE"
  461. echo ' char *argv[] = {"sh", "-c", (char*)rawCmd, NULL};' >> "$FILE"
  462. echo ' int status;' >> "$FILE"
  463. echo ' status = posix_spawn(&pid, "/fs/jb/bin/sh", NULL, NULL, argv, environ);' >> "$FILE"
  464. echo ' if (status == 0) {' >> "$FILE"
  465. echo ' if (waitpid(pid, &status, 0) == -1) {' >> "$FILE"
  466. echo ' perror("waitpid");' >> "$FILE"
  467. echo ' }' >> "$FILE"
  468. echo ' } else {' >> "$FILE"
  469. echo ' printf("posix_spawn: %s\n", strerror(status));' >> "$FILE"
  470. echo ' }' >> "$FILE"
  471. echo ' free(rawCmd);' >> "$FILE"
  472. echo ' return status;' >> "$FILE"
  473. echo '}' >> "$FILE"
  474. }
  475. patchNcurses() {
  476. PKG_NAME=$1
  477. echo "patchNCurses PKG_NAME: $PKG_NAME"
  478. if [[ "$PLATFORM" == "AppleTVOS" ]]; then
  479. if [[ "$PKG_VERSION" == "6.0-1" ]]; then
  480. # LEFT ERROR ON environ)' no ;
  481. # For some reason, building never fails on the error...
  482. # But still, tput is in /usr/bin... so.... ??
  483. cat progs/tput.c | head -n 55 > tput.patched.c
  484. echo "#include <stdint.h>" >> tput.patched.c
  485. echo "#include <stdio.h>" >> tput.patched.c
  486. echo "#include <stdlib.h>" >> tput.patched.c
  487. echo "#include <spawn.h>" >> tput.patched.c
  488. echo "#include <sys/wait.h>" >> tput.patched.c
  489. echo "" >> tput.patched.c
  490. echo "extern char **environ;" >> tput.patched.c
  491. echo "" >> tput.patched.c
  492. cat progs/tput.c | tail -n 350 | head -n 50 >> tput.patched.c
  493. fixSystem "tput.patched.c"
  494. cat progs/tput.c | tail -n 301 | sed 's/system(init_prog)/RunCmd(init_prog)/g' >> tput.patched.c
  495. cp tput.patched.c progs/tput.c
  496. fi
  497. fi
  498. #sed -i -- 's|#include <stdlib.h>|\n#if !defined(__arm64__)\n#define __arm64__\n#endif\n\n#include <stdlib.h>|' ncurses/build.priv.h
  499. # CURSES_PRIV="$SKEL_PREFIX/$ROOT_PREFIX/include/curses.priv.h"
  500. # FIFO="$SKEL_PREFIX/$ROOT_PREFIX/include/fifo_defs.h"
  501. # BUILD_P="$SKEL_PREFIX/$ROOT_PREFIX/include/build.priv.h"
  502. # if [[ ! -f "$CURSES_PRIV" ]]; then
  503. # cp $BUILD_ROOT/$1/ncurses/*.h "$SKEL_PREFIX/$ROOT_PREFIX/include/"
  504. #cp "$BUILD_ROOT/$1/ncurses/fifo_defs.h" "$FIFO"
  505. #cp "$BUILD_ROOT/$1/ncurses/build.priv.h" "$BUILD_P"
  506. # fi
  507. }
  508. #http://gnu.mirror.constant.com/ncurses/ncurses-6.0.tar.gz
  509. #https://git.elucubratus.com/elucubratus/elucubratus/-/raw/master/data/ncurses/ncurses_6.1+20181013.orig.tar.gz
  510. buildNcurses() {
  511. PKG_NAME="ncurses-6.1-20181013"
  512. checkBuilt $PKG_NAME
  513. if [[ $? != 0 ]]; then
  514. echo "$PKG_NAME already exists, skipping!"
  515. else
  516. echo "building $PKG_NAME..."
  517. #splitName $PKG_NAME
  518. downloadProduct https://git.elucubratus.com/elucubratus/elucubratus/-/raw/master/data/ncurses/ncurses_6.1+20181013.orig.tar.gz - ncurses 6.1-20181013
  519. patchNcurses $PKG_NAME
  520. export HOST="arm"
  521. buildProduct $PKG_NAME
  522. export HOST="aarch64"
  523. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/clear"
  524. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/infocmp"
  525. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/tabs"
  526. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/tic"
  527. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/toe"
  528. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/tput"
  529. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/tset"
  530. fi
  531. }
  532. #https://git.elucubratus.com/elucubratus/elucubratus/-/raw/master/data/bash/bash-5.0.tar.gz
  533. buildBash() {
  534. PKG_NAME="bash-5.0"
  535. checkBuilt $PKG_NAME
  536. if [[ $? != 0 ]]; then
  537. echo "$PKG_NAME already exists, skipping!"
  538. else
  539. echo "building $PKG_NAME..."
  540. splitName $PKG_NAME
  541. downloadProduct https://git.elucubratus.com/elucubratus/elucubratus/-/raw/master/data/bash/bash-5.0.tar.gz - $RAW_NAME $VERSION
  542. patchBash
  543. buildProduct $PKG_NAME "--disable-nls --with-installed-readline --disable-largefile bash_cv_dev_fd=absent bash_cv_sys_named_pipes=present bash_cv_job_control_missing=present bash_cv_func_sigsetjmp=present bash_cv_func_ctype_nonascii=no bash_cv_must_reinstall_sighandlers=no bash_cv_func_strcoll_broken=yes ac_cv_c_stack_direction=-1 ac_cv_func_mmap_fixed_mapped=yes gt_cv_int_divbyzero_sigfpe=no ac_cv_func_setvbuf_reversed=no ac_cv_func_strcoll_works=yes ac_cv_func_working_mktime=yes ac_cv_type_getgroups=gid_t bash_cv_dup2_broken=no ac_cv_prog_cc_g=no ac_cv_rl_version=6.0"
  544. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/bash"
  545. codesign "$SKEL_PREFIX/$ROOT_PREFIX/lib/bash/basename"
  546. codesign "$SKEL_PREFIX/$ROOT_PREFIX/lib/bash/dirname"
  547. codesign "$SKEL_PREFIX/$ROOT_PREFIX/lib/bash/finfo"
  548. codesign "$SKEL_PREFIX/$ROOT_PREFIX/lib/bash/head"
  549. codesign "$SKEL_PREFIX/$ROOT_PREFIX/lib/bash/id"
  550. codesign "$SKEL_PREFIX/$ROOT_PREFIX/lib/bash/ln"
  551. codesign "$SKEL_PREFIX/$ROOT_PREFIX/lib/bash/logname"
  552. codesign "$SKEL_PREFIX/$ROOT_PREFIX/lib/bash/mkdir"
  553. codesign "$SKEL_PREFIX/$ROOT_PREFIX/lib/bash/mypid"
  554. codesign "$SKEL_PREFIX/$ROOT_PREFIX/lib/bash/pathchk"
  555. codesign "$SKEL_PREFIX/$ROOT_PREFIX/lib/bash/print"
  556. codesign "$SKEL_PREFIX/$ROOT_PREFIX/lib/bash/printenv"
  557. codesign "$SKEL_PREFIX/$ROOT_PREFIX/lib/bash/push"
  558. codesign "$SKEL_PREFIX/$ROOT_PREFIX/lib/bash/realpath"
  559. codesign "$SKEL_PREFIX/$ROOT_PREFIX/lib/bash/rmdir"
  560. codesign "$SKEL_PREFIX/$ROOT_PREFIX/lib/bash/setpgid"
  561. codesign "$SKEL_PREFIX/$ROOT_PREFIX/lib/bash/sleep"
  562. codesign "$SKEL_PREFIX/$ROOT_PREFIX/lib/bash/strftime"
  563. codesign "$SKEL_PREFIX/$ROOT_PREFIX/lib/bash/sync"
  564. codesign "$SKEL_PREFIX/$ROOT_PREFIX/lib/bash/tee"
  565. codesign "$SKEL_PREFIX/$ROOT_PREFIX/lib/bash/truefalse"
  566. codesign "$SKEL_PREFIX/$ROOT_PREFIX/lib/bash/tty"
  567. codesign "$SKEL_PREFIX/$ROOT_PREFIX/lib/bash/uname"
  568. codesign "$SKEL_PREFIX/$ROOT_PREFIX/lib/bash/unlink"
  569. codesign "$SKEL_PREFIX/$ROOT_PREFIX/lib/bash/whoami"
  570. fi
  571. }
  572. buildSed() {
  573. PKG_NAME="sed-4.4"
  574. checkBuilt $PKG_NAME
  575. if [[ $? != 0 ]]; then
  576. echo "$PKG_NAME already exists, skipping!"
  577. else
  578. echo "building $PKG_NAME..."
  579. splitName $PKG_NAME
  580. downloadProduct https://ftp.gnu.org/gnu/sed/sed-4.4.tar.xz https://ftp.gnu.org/gnu/sed/sed-4.4.tar.xz.sig $RAW_NAME $VERSION
  581. buildProduct $PKG_NAME
  582. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/sed"
  583. fi
  584. }
  585. buildGrep() {
  586. PKG_NAME="grep-3.0"
  587. checkBuilt $PKG_NAME
  588. if [[ $? != 0 ]]; then
  589. echo "$PKG_NAME already exists, skipping!"
  590. else
  591. echo "building $PKG_NAME..."
  592. splitName $PKG_NAME
  593. downloadProduct https://ftp.gnu.org/gnu/grep/grep-3.0.tar.xz https://ftp.gnu.org/gnu/grep/grep-3.0.tar.xz.sig $RAW_NAME $VERSION
  594. buildProduct $PKG_NAME
  595. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/grep"
  596. fi
  597. }
  598. patchCoreutils() {
  599. if [[ "$PLATFORM" == "AppleTVOS" ]]; then
  600. sed -i -- 's|#undef HAVE_CLOCK_GETTIME||' lib/config.hin
  601. sed -i -- 's|#undef HAVE_CLOCK_SETTIME||' lib/config.hin
  602. sed -i -- 's|#undef HAVE_FDATASYNC||' lib/config.hin
  603. sed -i -- 's|# define __stpncpy stpncpy||' lib/stpncpy.c
  604. if [[ ! -d "$SKEL_PREFIX/$ROOT_PREFIX/include" ]]; then
  605. mkdir -p "$SKEL_PREFIX/$ROOT_PREFIX/include"
  606. fi
  607. if [[ ! -e "$SKEL_PREFIX/$ROOT_PREFIX/include/crt_externs.h" ]]; then
  608. echo "#include <sys/cdefs.h>" >> "$SKEL_PREFIX/$ROOT_PREFIX/include/crt_externs.h"
  609. echo "" >> "$SKEL_PREFIX/$ROOT_PREFIX/include/crt_externs.h"
  610. echo "__BEGIN_DECLS" >> "$SKEL_PREFIX/$ROOT_PREFIX/include/crt_externs.h"
  611. echo "extern char ***_NSGetArgv(void);" >> "$SKEL_PREFIX/$ROOT_PREFIX/include/crt_externs.h"
  612. echo "extern int *_NSGetArgc(void);" >> "$SKEL_PREFIX/$ROOT_PREFIX/include/crt_externs.h"
  613. echo "extern char ***_NSGetEnviron(void);" >> "$SKEL_PREFIX/$ROOT_PREFIX/include/crt_externs.h"
  614. echo "extern char **_NSGetProgname(void);" >> "$SKEL_PREFIX/$ROOT_PREFIX/include/crt_externs.h"
  615. echo "extern struct mach_header *_NSGetMachExecuteHeader(void);" >> "$SKEL_PREFIX/$ROOT_PREFIX/include/crt_externs.h"
  616. echo "__END_DECLS" >> "$SKEL_PREFIX/$ROOT_PREFIX/include/crt_externs.h"
  617. fi
  618. fi
  619. }
  620. buildCoreutils() {
  621. PKG_NAME="coreutils-8.9"
  622. checkBuilt $PKG_NAME
  623. if [[ $? != 0 ]]; then
  624. echo "$PKG_NAME already exists, skipping!"
  625. else
  626. echo "building $PKG_NAME..."
  627. splitName $PKG_NAME
  628. downloadProduct http://gnu.mirror.constant.com/coreutils/coreutils-8.9.tar.xz http://gnu.mirror.constant.com/coreutils/coreutils-8.9.tar.xz.sig $RAW_NAME $VERSION
  629. patchCoreutils
  630. export HOST="arm"
  631. buildProduct $PKG_NAME
  632. export HOST="aarch64"
  633. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/["
  634. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/base64"
  635. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/basename"
  636. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/cat"
  637. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/chcon"
  638. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/chgrp"
  639. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/chmod"
  640. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/chown"
  641. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/chroot"
  642. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/cksum"
  643. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/comm"
  644. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/cp"
  645. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/csplit"
  646. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/cut"
  647. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/date"
  648. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/dd"
  649. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/df"
  650. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/dir"
  651. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/dircolors"
  652. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/dirname"
  653. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/du"
  654. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/echo"
  655. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/env"
  656. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/expand"
  657. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/expr"
  658. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/factor"
  659. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/false"
  660. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/fmt"
  661. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/fold"
  662. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/groups"
  663. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/head"
  664. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/hostid"
  665. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/id"
  666. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/install"
  667. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/join"
  668. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/kill"
  669. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/link"
  670. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/ln"
  671. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/logname"
  672. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/ls"
  673. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/md5sum"
  674. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/mkdir"
  675. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/mkfifo"
  676. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/mknod"
  677. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/mktemp"
  678. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/mv"
  679. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/nice"
  680. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/nl"
  681. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/nohup"
  682. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/nproc"
  683. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/od"
  684. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/paste"
  685. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/pathchk"
  686. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/pinky"
  687. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/pr"
  688. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/printenv"
  689. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/printf"
  690. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/ptx"
  691. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/pwd"
  692. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/readlink"
  693. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/rm"
  694. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/rmdir"
  695. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/runcon"
  696. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/seq"
  697. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/sha1sum"
  698. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/sha224sum"
  699. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/sha256sum"
  700. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/sha384sum"
  701. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/sha512sum"
  702. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/shred"
  703. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/shuf"
  704. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/sleep"
  705. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/sort"
  706. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/split"
  707. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/stat"
  708. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/stty"
  709. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/sum"
  710. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/sync"
  711. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/tac"
  712. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/tail"
  713. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/tee"
  714. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/test"
  715. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/timeout"
  716. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/touch"
  717. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/tr"
  718. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/true"
  719. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/truncate"
  720. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/tsort"
  721. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/tty"
  722. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/uname"
  723. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/unexpand"
  724. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/uniq"
  725. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/unlink"
  726. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/uptime"
  727. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/users"
  728. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/vdir"
  729. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/wc"
  730. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/who"
  731. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/whoami"
  732. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/yes"
  733. fi
  734. }
  735. buildFindUtils() {
  736. PKG_NAME="findutils-4.6.0"
  737. checkBuilt $PKG_NAME
  738. if [[ $? != 0 ]]; then
  739. echo "$PKG_NAME already exists, skipping!"
  740. else
  741. echo "building $PKG_NAME..."
  742. splitName $PKG_NAME
  743. downloadProduct http://mirror.keystealth.org/gnu/findutils/findutils-4.6.0.tar.gz - $RAW_NAME $VERSION
  744. buildProduct $PKG_NAME
  745. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/find"
  746. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/locate"
  747. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/xargs"
  748. fi
  749. }
  750. buildDiffUtils() {
  751. PKG_NAME="diffutils-3.6"
  752. checkBuilt $PKG_NAME
  753. if [[ $? != 0 ]]; then
  754. echo "$PKG_NAME already exists, skipping!"
  755. else
  756. echo "building $PKG_NAME..."
  757. splitName $PKG_NAME
  758. downloadProduct http://ftp.gnu.org/gnu/diffutils/diffutils-3.6.tar.xz http://ftp.gnu.org/gnu/diffutils/diffutils-3.6.tar.xz.sig $RAW_NAME $VERSION
  759. buildProduct $PKG_NAME
  760. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/cmp"
  761. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/diff"
  762. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/diff3"
  763. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/sdiff"
  764. fi
  765. }
  766. downloadDarwinTools() {
  767. if [[ ! -d DarwinToolsARM ]]; then
  768. echo "Fetching DarwinTools"
  769. mkdir -p DarwinToolsARM
  770. cd DarwinToolsARM
  771. curl -LO https://opensource.apple.com/source/DarwinTools/DarwinTools-1/sw_vers.c
  772. #Not built yet
  773. curl -LO https://opensource.apple.com/source/launchd/launchd-842.92.1/support/launchctl.c
  774. #sw_vers.c
  775. checkSHA256 sw_vers.c 55aab510b465f7687b8ebe23f0e51926606fd5316da138778838b2dac3e7c7e0
  776. else
  777. echo "Using existing DarwinTools"
  778. cd DarwinToolsARM
  779. fi
  780. WORKING_DIR="DarwinToolsARM"
  781. PKG_NAME="darwintools"
  782. PKG_VERSION="1.0-1"
  783. }
  784. patchDarwinTools() {
  785. if [[ "$PLATFORM" == "AppleTVOS" ]]; then
  786. sed -i -- 's|#include <CoreFoundation/CFPriv.h>|extern CFDictionaryRef _CFCopySystemVersionDictionary(void);\
  787. extern CFDictionaryRef _CFCopyServerVersionDictionary(void);|' sw_vers.c
  788. sed -i -- 's|_kCFSystemVersionProductNameKey|CFSTR(\"ProductName\")|g' sw_vers.c
  789. sed -i -- 's|_kCFSystemVersionProductVersionKey|CFSTR(\"ProductVersion\")|g' sw_vers.c
  790. sed -i -- 's|_kCFSystemVersionBuildVersionKey|CFSTR(\"ProductBuildVersion\")|g' sw_vers.c
  791. fi
  792. }
  793. #darwintools
  794. #Notes:
  795. # This only builds a striped down version of the one on iOS
  796. # If you're building for a non-appletv platform, you may need to fix things here.
  797. buildDarwinTools() {
  798. downloadDarwinTools
  799. patchDarwinTools
  800. "$CLANG_PATH" -arch "$ARCH" -isysroot"$SDK_PATH" -framework CoreFoundation "$MIN_VERSION" -o "sw_vers" sw_vers.c
  801. codesign "$BUILD_ROOT/$WORKING_DIR/sw_vers"
  802. cp sw_vers "$SKEL_PREFIX/$ROOT_PREFIX/bin/"
  803. cd "$BUILD_ROOT"
  804. }
  805. #Download uikittools
  806. downloadUIKitTools() {
  807. if [[ ! -d uikittools ]]; then
  808. echo "Fetching uikittools"
  809. git clone git://git.saurik.com/uikittools.git
  810. else
  811. echo "Using existing uikittools"
  812. fi
  813. WORKING_DIR="uikittools"
  814. PKG_NAME="uikittools"
  815. PKG_VERSION="1.1.12-1"
  816. cd "$WORKING_DIR"
  817. git checkout tags/v1.1.12
  818. }
  819. #uikittools
  820. #Notes:
  821. # This only builds a striped down version of the one on iOS
  822. # If you're building for a non-appletv platform, you may need to fix things here.
  823. buildUIKitTools() {
  824. downloadUIKitTools
  825. "$CLANGPLUS_PATH" -arch "$ARCH" -isysroot"$SDK_PATH" -Os -Werror -framework CoreFoundation -framework Foundation "$MIN_VERSION" -o cfversion cfversion.mm
  826. "$CLANGPLUS_PATH" -arch "$ARCH" -isysroot"$SDK_PATH" -Os -Werror -framework CoreFoundation -framework Foundation "$MIN_VERSION" -o gssc gssc.mm
  827. "$CLANGPLUS_PATH" -arch "$ARCH" -isysroot"$SDK_PATH" -Os -Werror -framework CoreFoundation -framework Foundation -framework UIKit "$MIN_VERSION" -o uiduid uiduid.mm
  828. codesign "$BUILD_ROOT/$WORKING_DIR/cfversion"
  829. codesign "$BUILD_ROOT/$WORKING_DIR/gssc"
  830. codesign "$BUILD_ROOT/$WORKING_DIR/uiduid"
  831. cp gssc cfversion uiduid "$SKEL_PREFIX/$ROOT_PREFIX/bin/"
  832. cd "$BUILD_ROOT"
  833. }
  834. buildBasicUtils() {
  835. notifyProgress "Building sed"
  836. buildSed
  837. notifyProgress "Building grep"
  838. buildGrep
  839. notifyProgress "Building coreutils"
  840. buildCoreutils
  841. notifyProgress "Building findutils"
  842. buildFindUtils
  843. notifyProgress "Building diffutils"
  844. buildDiffUtils
  845. notifyProgress "Building DarwinTools"
  846. buildDarwinTools
  847. notifyProgress "Building UIKitTools"
  848. buildUIKitTools
  849. }
  850. mkdirIfNecessary() {
  851. MK_DIR="$1"
  852. if [[ ! -d $MK_DIR ]]; then
  853. mkdir -p $MK_DIR
  854. fi
  855. }
  856. removeIfNecessary() {
  857. REMOVE_FILE="$1"
  858. if [[ -f $REMOVE_FILE ]]; then
  859. rm -rf $REMOVE_FILE
  860. fi
  861. }
  862. #=====================
  863. #DPKG and Dependencies
  864. #---------------------
  865. #Download zlib
  866. downloadZLib() {
  867. #Download zlib
  868. if [[ ! -d zlib ]]; then
  869. echo "Downloading zlib git"
  870. git clone https://github.com/madler/zlib.git
  871. else
  872. echo "Using existing zlib"
  873. fi
  874. WORKING_DIR="zlib"
  875. PKG_NAME="zlib"
  876. PKG_VERSION="1.2.11-1"
  877. cd "$WORKING_DIR"
  878. git checkout tags/v1.2.11
  879. removeIfNecessary build
  880. mkdirIfNecessary build
  881. cd build
  882. WORKING_DIR="$WORKING_DIR/build"
  883. }
  884. #zlib
  885. buildZLib() {
  886. PKG_NAME="lzib-1.2.11"
  887. checkBuilt $PKG_NAME
  888. if [[ $? != 0 ]]; then
  889. echo "$PKG_NAME already exists, skipping!"
  890. else
  891. downloadZLib
  892. cmake -DCMAKE_INSTALL_NAME_DIR="/$ROOT_PREFIX/lib" -DCMAKE_OSX_SYSROOT="$SDK_PATH/" -DCMAKE_C_FLAGS="-arch $ARCH" -DCMAKE_INSTALL_PREFIX="/$ROOT_PREFIX" ..
  893. checkStatus $PKG_NAME $? "false"
  894. make -j8 DESTDIR="$SKEL_PREFIX" install
  895. checkStatus $PKG_NAME $? "true"
  896. cd "$BUILD_ROOT"
  897. fi
  898. }
  899. patchXZ() {
  900. if [[ "$PLATFORM" == "AppleTVOS" ]]; then
  901. sed -i -- 's|#undef HAVE_CLOCK_GETTIME||' config.h.in
  902. fi
  903. }
  904. patchTar() {
  905. if [[ "$PLATFORM" == "AppleTVOS" ]]; then
  906. sed -i -- 's|#undef HAVE_CLOCK_GETTIME||' config.h.in
  907. fi
  908. }
  909. patchOpenSSL() {
  910. sed -i -- "s|-arch $ARCH -mios-version-min=7.0.0|-arch $ARCH $MIN_VERSION|" Configurations/10-main.conf
  911. }
  912. patchBZip2() {
  913. if [[ "$PLATFORM" == "AppleTVOS" ]]; then
  914. #fix up our makefile...
  915. sed -i -- "s|CC=gcc|CC=$(xcrun --sdk $PLATFORM_LOWER --find clang)|" Makefile
  916. sed -i -- "s|AR=ar|AR=$(xcrun --sdk $PLATFORM_LOWER --find ar)|" Makefile
  917. sed -i -- "s|RANLIB=ranlib|RANLIB=$(xcrun --sdk $PLATFORM_LOWER --find ranlib)|" Makefile
  918. sed -i -- "s|LDFLAGS=|LDFLAGS=$MIN_VERSION -isysroot \"$SDK_PATH\" -arch $ARCH|" Makefile
  919. sed -i -- "s|CFLAGS=|CFLAGS=$MIN_VERSION -isysroot \"$SDK_PATH\" -arch $ARCH |" Makefile
  920. sed -i -- 's|all:\(.*\) test$|all: \1|' Makefile
  921. sed -i -- 's|ln -s -f \$(PREFIX)/bin/|ln -s -f |g' Makefile
  922. fi
  923. }
  924. patchCurl() {
  925. if [[ "$PLATFORM" == "AppleTVOS" ]]; then
  926. #(Forcibly) Remove that dirty clock_gettime
  927. #TODO: Determine if this is the best way
  928. sed -i -- 's|#undef HAVE_CLOCK_GETTIME_MONOTONIC||' lib/curl_config.h.in
  929. fi
  930. }
  931. buildXZ() {
  932. PKG_NAME="xz-5.2.3"
  933. checkBuilt $PKG_NAME
  934. if [[ $? != 0 ]]; then
  935. echo "$PKG_NAME already exists, skipping!"
  936. else
  937. echo "building $PKG_NAME..."
  938. splitName $PKG_NAME
  939. downloadProduct http://tukaani.org/xz/xz-5.2.3.tar.gz http://tukaani.org/xz/xz-5.2.3.tar.gz.sig $RAW_NAME $VERSION
  940. patchXZ
  941. buildProduct $PKG_NAME
  942. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/lzmadec"
  943. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/lzmainfo"
  944. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/xz"
  945. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/xzdec"
  946. codesign "$SKEL_PREFIX/$ROOT_PREFIX/lib/liblzma.5.dylib"
  947. fi
  948. }
  949. buildBZip2() {
  950. PKG_NAME="bzip2-1.0.6"
  951. checkBuilt $PKG_NAME
  952. if [[ $? != 0 ]]; then
  953. echo "$PKG_NAME already exists, skipping!"
  954. else
  955. echo "building $PKG_NAME..."
  956. splitName $PKG_NAME
  957. downloadProduct https://gigenet.dl.sourceforge.net/project/bzip2/bzip2-1.0.6.tar.gz - $RAW_NAME $VERSION
  958. patchBZip2
  959. make -j8 install PREFIX="$SKEL_PREFIX/$ROOT_PREFIX"
  960. checkStatus $PKG_NAME $? "true"
  961. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/bunzip2"
  962. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/bzcat"
  963. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/bzip2"
  964. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/bzip2recover"
  965. cd "$BUILD_ROOT"
  966. fi
  967. }
  968. buildLZ4() {
  969. PKG_NAME="lz4-1.7.5"
  970. checkBuilt $PKG_NAME
  971. if [[ $? != 0 ]]; then
  972. echo "$PKG_NAME already exists, skipping!"
  973. else
  974. echo "building $PKG_NAME..."
  975. splitName $PKG_NAME
  976. downloadProduct https://github.com/lz4/lz4/archive/v1.7.5.tar.gz - $RAW_NAME $VERSION
  977. cd contrib/cmake_unofficial/
  978. mkdirIfNecessary build
  979. cd build
  980. cmake -DCMAKE_INSTALL_NAME_DIR="/$ROOT_PREFIX/lib" -DCMAKE_OSX_SYSROOT="$SDK_PATH/" -DCMAKE_C_FLAGS="-arch $ARCH" -DCMAKE_INSTALL_PREFIX="/$ROOT_PREFIX" ..
  981. checkStatus $PKG_NAME $? "false"
  982. make -j8
  983. make -j8 DESTDIR="$SKEL_PREFIX" install
  984. checkStatus $PKG_NAME $? "true"
  985. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/lz4"
  986. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/lz4c"
  987. codesign "$SKEL_PREFIX/$ROOT_PREFIX/lib/liblz4.1.7.5.dylib"
  988. codesign "$SKEL_PREFIX/$ROOT_PREFIX/lib/liblz4.1.dylib"
  989. cd "$BUILD_ROOT"
  990. fi
  991. }
  992. downloadOpenSSL() {
  993. if [[ ! -d openssl ]]; then
  994. git clone -b OpenSSL_1_1_0-stable https://github.com/openssl/openssl.git
  995. else
  996. echo "Using existing openssl repo"
  997. fi
  998. WORKING_DIR="openssl"
  999. PKG_NAME="openssl"
  1000. PKG_VERSION="1.1.0-1"
  1001. cd "$WORKING_DIR"
  1002. }
  1003. buildOpenSSL() {
  1004. PKG_NAME="openssl"
  1005. checkBuilt $PKG_NAME
  1006. if [[ $? != 0 ]]; then
  1007. echo "$PKG_NAME already exists, skipping!"
  1008. else
  1009. LOG_FILE="$ROOT_LOG_FOLDER/openssl.log"
  1010. touch $LOG_FILE
  1011. downloadOpenSSL
  1012. patchOpenSSL
  1013. export AR=""
  1014. export PLATFORM="$PLATFORM"
  1015. export BUILD_TOOLS="$(xcode-select --print-path)"
  1016. export CC="clang -fembed-bitcode"
  1017. export CROSS_COMPILE="$(xcode-select --print-path)/Toolchains/XcodeDefault.xctoolchain/usr/bin/"
  1018. export CROSS_TOP="$(xcode-select --print-path)/Platforms/$PLATFORM.platform/Developer"
  1019. export CROSS_SDK="$(echo $SDK_PATH | sed 's/.*\///g')"
  1020. notifyProgress "Configuring openSSL"
  1021. if [[ $LOG_VERBOSE == "verbose"* ]]; then
  1022. ./Configure ios64-cross no-dso no-hw no-engine --prefix="/$ROOT_PREFIX" | tee "${LOG_FILE}"
  1023. EC=$(grep "configure: error:" -i "${LOG_FILE}" -c)
  1024. checkStatus $PKG_NAME $EC "false"
  1025. else
  1026. (./Configure ios64-cross no-dso no-hw no-engine --prefix="/$ROOT_PREFIX" > "$LOG_FILE" 2>&1)
  1027. checkStatus $PKG_NAME $? "false"
  1028. if [[ $OPEN_LOG == "true" ]]; then
  1029. open "${LOG_FILE}"
  1030. fi
  1031. fi
  1032. echo -e "\n\nPOST CONFIGURE\n\n" >> "$LOG_FILE"
  1033. notifyProgress "making openSSL"
  1034. if [[ $LOG_VERBOSE == "verbose"* ]]; then
  1035. make DESTDIR="$SKEL_PREFIX" install | tee -a "${LOG_FILE}"
  1036. EC=$(grep "fatal error:" -i "${LOG_FILE}" -c)
  1037. checkStatus $PKG_NAME $EC "true"
  1038. else
  1039. (make DESTDIR="$SKEL_PREFIX" install >> "${LOG_FILE}" 2>&1)
  1040. checkStatus $PKG_NAME $? "true"
  1041. fi
  1042. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/openssl"
  1043. codesign "$SKEL_PREFIX/$ROOT_PREFIX/lib/libcrypto.1.1.dylib"
  1044. cd "$BUILD_ROOT"
  1045. fi
  1046. }
  1047. buildCurl() {
  1048. PKG_NAME="curl-7.50.1"
  1049. checkBuilt $PKG_NAME
  1050. if [[ $? != 0 ]]; then
  1051. echo "$PKG_NAME already exists, skipping!"
  1052. else
  1053. echo "building $PKG_NAME..."
  1054. splitName $PKG_NAME
  1055. downloadProduct https://curl.haxx.se/download/curl-7.50.1.tar.gz - $RAW_NAME $VERSION
  1056. patchCurl
  1057. buildProduct $PKG_NAME
  1058. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/curl"
  1059. codesign "$SKEL_PREFIX/$ROOT_PREFIX/lib/libcurl.4.dylib"
  1060. fi
  1061. }
  1062. patchBerkeleyDB() {
  1063. if [[ "$PLATFORM" == "AppleTVOS" ]]; then
  1064. sed -i -- 's|#undef HAVE_CLOCK_GETTIME||' ../dist/config.hin
  1065. #if [[ "$PKG_VERSION" == "6.2.23-1" ]]; then
  1066. cat ../lang/sql/sqlite/src/shell.c | head -n 14 > shell.patched.c
  1067. echo "#include <stdint.h>" >> shell.patched.c
  1068. echo "#include <stdio.h>" >> shell.patched.c
  1069. echo "#include <stdlib.h>" >> shell.patched.c
  1070. echo "#include <spawn.h>" >> shell.patched.c
  1071. echo "#include <sys/wait.h>" >> shell.patched.c
  1072. echo "#include <sys/stat.h>" >> shell.patched.c
  1073. echo "" >> shell.patched.c
  1074. echo "extern char **environ;" >> shell.patched.c
  1075. echo "" >> shell.patched.c
  1076. cat ../lang/sql/sqlite/src/shell.c | tail -n 4847 | head -n 2622 >> shell.patched.c
  1077. fixSystem "shell.patched.c"
  1078. cat ../lang/sql/sqlite/src/shell.c | tail -n 2226 | sed 's/system(zCmd)/RunCmd(zCmd)/g' >> shell.patched.c
  1079. cp shell.patched.c ../lang/sql/sqlite/src/shell.c
  1080. #fi
  1081. fi
  1082. }
  1083. buildBerkeleyDB() {
  1084. PKG_NAME="db-6.2.23"
  1085. checkBuilt $PKG_NAME
  1086. if [[ $? != 0 ]]; then
  1087. echo "$PKG_NAME already exists, skipping!"
  1088. else
  1089. echo "building $PKG_NAME..."
  1090. LOG_FILE="$ROOT_LOG_FOLDER/$PKG_NAME.log"
  1091. touch $LOG_FILE
  1092. splitName $PKG_NAME
  1093. DOWNLOAD_URL="http://download.oracle.com/berkeley-db/db-6.2.23.tar.gz"
  1094. downloadProduct $DOWNLOAD_URL - $RAW_NAME $VERSION
  1095. cd build_unix
  1096. patchBerkeleyDB
  1097. export CPP="$(xcrun --sdk $PLATFORM_LOWER -f clang) -E "
  1098. export CXXCPP="$(xcrun --sdk $PLATFORM_LOWER -f clang++) -E "
  1099. export PLATFORM="$PLATFORM" #TODO: Maybe necessary? Need to test.
  1100. export BUILD_TOOLS="$(xcode-select --print-path)"
  1101. export CC="clang"
  1102. export CROSS_COMPILE="$(xcode-select --print-path)/Toolchains/XcodeDefault.xctoolchain/usr/bin/"
  1103. export CROSS_TOP="$(xcode-select --print-path)/Platforms/$PLATFORM.platform/Developer"
  1104. export CROSS_SDK="$(echo $SDK_PATH | sed 's/.*\///g')"
  1105. export CFLAGS="-arch $ARCH -pipe -Os -gdwarf-2 -isysroot $SDK_PATH $MIN_VERSION"
  1106. export CXXFLAGS="-arch $ARCH -pipe -Os -gdwarf-2 -isysroot $SDK_PATH $MIN_VERSION"
  1107. export LDFLAGS="-arch $ARCH -isysroot $SDK_PATH" # -L${SKEL_PREFIX}/lib"
  1108. #buildProduct $PKG_NAME
  1109. if [[ $LOG_VERBOSE == "verbose"* ]]; then
  1110. ../dist/configure --disable-debug --disable-test --disable-atomicsupport --enable-cxx--enable-compact185 --enable-sql --enable-sql_codegen --enable-dbm --enable-slt --disable-java --host=arm-apple-darwin --prefix="/$ROOT_PREFIX" | tee "${LOG_FILE}"
  1111. else
  1112. (../dist/configure --disable-debug --disable-test --disable-atomicsupport --enable-cxx--enable-compact185 --enable-sql --enable-sql_codegen --enable-dbm --enable-slt --disable-java --host=arm-apple-darwin --prefix="/$ROOT_PREFIX" > "$LOG_FILE" 2>&1)
  1113. if [[ $OPEN_LOG == "true" ]]; then
  1114. open "${LOG_FILE}"
  1115. fi
  1116. fi
  1117. checkStatus $PKG_NAME $? "false"
  1118. if [[ $LOG_VERBOSE == "verbose"* ]]; then
  1119. make DESTDIR="$SKEL_PREFIX" install | tee "${LOG_FILE}"
  1120. else
  1121. (make DESTDIR="$SKEL_PREFIX" install >> "${LOG_FILE}" 2>&1)
  1122. fi
  1123. checkStatus $PKG_NAME $? "true"
  1124. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/db_archive"
  1125. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/db_checkpoint"
  1126. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/db_deadlock"
  1127. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/db_dump"
  1128. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/db_hotbackup"
  1129. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/db_load"
  1130. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/db_log_verify"
  1131. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/db_printlog"
  1132. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/db_recover"
  1133. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/db_replicate"
  1134. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/db_sql_codegen"
  1135. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/db_stat"
  1136. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/db_tuner"
  1137. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/db_upgrade"
  1138. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/db_verify"
  1139. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/dbsql"
  1140. codesign "$SKEL_PREFIX/$ROOT_PREFIX/lib/libdb_sql-6.2.dylib"
  1141. codesign "$SKEL_PREFIX/$ROOT_PREFIX/lib/libdb-6.2.dylib"
  1142. fi
  1143. }
  1144. buildTar(){
  1145. PKG_NAME="tar-1.33"
  1146. checkBuilt $PKG_NAME
  1147. if [[ $? != 0 ]]; then
  1148. echo "$PKG_NAME already exists, skipping!"
  1149. else
  1150. echo "building $PKG_NAME..."
  1151. splitName $PKG_NAME
  1152. downloadProduct http://ftp.gnu.org/gnu/tar/tar-1.33.tar.xz - $RAW_NAME $VERSION
  1153. patchTar
  1154. buildProduct $PKG_NAME
  1155. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/tar"
  1156. fi
  1157. }
  1158. #Download dpkg
  1159. downloadDpkg() {
  1160. if [[ ! -d dpkg ]]; then
  1161. echo "Downlading dpkg"
  1162. git clone https://git.nito.tv/NitoTV/dpkg.git
  1163. else
  1164. echo "Using existing dpkg"
  1165. fi
  1166. WORKING_DIR="dpkg"
  1167. PKG_NAME="dpkg"
  1168. PKG_VERSION="1.18.23-1" #FIXME
  1169. cd "$WORKING_DIR"
  1170. }
  1171. #dpkg
  1172. buildDpkg() {
  1173. PKG_NAME="dpkg-1.18.23"
  1174. LOG_FILE="$ROOT_LOG_FOLDER/$PKG_NAME.log"
  1175. touch $LOG_FILE
  1176. checkBuilt $PKG_NAME
  1177. if [[ $? != 0 ]]; then
  1178. echo "$PKG_NAME already exists, skipping!"
  1179. else
  1180. downloadDpkg
  1181. local dont_die_here=$(./autogen.sh)
  1182. # need to clear these preprocessor flags or they get all wonky
  1183. export CPP="$(xcrun --sdk $PLATFORM_LOWER -f clang) -E "
  1184. export CXXCPP="$(xcrun --sdk $PLATFORM_LOWER -f clang++) -E "
  1185. export LZMA_LIBS="$SKEL_PREFIX/$ROOT_PREFIX/lib/liblzma.dylib"
  1186. export CC=$(xcrun --sdk $PLATFORM_LOWER --find clang)
  1187. export CXX=$(xcrun --sdk $PLATFORM_LOWER --find clang++)
  1188. export CFLAGS="-isysroot $SDK_PATH -I$SDK_PATH/usr/include -I$SKEL_PREFIX/$ROOT_PREFIX/include/ -arch $ARCH"
  1189. export CXXFLAGS=$CFLAGS
  1190. export LDFLAGS="-isysroot $SDK_PATH -L$SKEL_PREFIX/$ROOT_PREFIX/lib/ -arch $ARCH"
  1191. export CPPFLAGS="-isysroot $SDK_PATH -I$SKEL_PREFIX/$ROOT_PREFIX/include/ -arch $ARCH"
  1192. export CXXFLAGS=$CFLAGS
  1193. export LDFLAGS="-isysroot $SDK_PATH -L$SKEL_PREFIX/$ROOT_PREFIX/lib/ -arch $ARCH"
  1194. if [[ $LOG_VERBOSE == "verbose"* ]]; then
  1195. ./configure --prefix="/$ROOT_PREFIX" --disable-start-stop-daemon --host=aarch64-apple-darwin --disable-dependency-tracking PERL_LIBDIR='$(prefix)/lib/' --disable-dselect --localstatedir="/var/" --sysconfdir="/fs/jb/etc" | tee "${LOG_FILE}"
  1196. EC=$(grep "configure: error:" -i "${LOG_FILE}" -c)
  1197. checkStatus $PKG_NAME $EC "false"
  1198. else
  1199. (./configure --prefix="/$ROOT_PREFIX" --disable-start-stop-daemon --host=aarch64-apple-darwin --disable-dependency-tracking PERL_LIBDIR='$(prefix)/lib/' --disable-dselect --localstatedir="/var/" --sysconfdir="/fs/jb/etc" > "${LOG_FILE}" 2>&1)
  1200. if [[ $OPEN_LOG == "true" ]]; then
  1201. open "${LOG_FILE}"
  1202. fi
  1203. fi
  1204. checkStatus $PKG_NAME $? "false"
  1205. patchDpkg #Must be after configure for now. I'll deal with this later
  1206. if [[ $LOG_VERBOSE == "verbose"* ]]; then
  1207. make -j8 DESTDIR="$SKEL_PREFIX" install | tee "${LOG_FILE}"
  1208. EC=$(grep "fatal error:" -i "${LOG_FILE}" -c)
  1209. checkStatus $PKG_NAME $EC "true"
  1210. else
  1211. (make -j8 DESTDIR="$SKEL_PREFIX" install >> "${LOG_FILE}" 2>&1)
  1212. checkStatus $PKG_NAME $? "true"
  1213. fi
  1214. #lzma conflicts with built in libraries when running in certian conditions.
  1215. #we make -j8 a symlink our version of lzma in the xz build process
  1216. #here we change dpkg-deb to look for this version instead
  1217. #if we do not do this, apt-get/dpkg* will fail from our setuid tool
  1218. install_name_tool -change /usr/lib/liblzma.5.dylib /usr/local/lib/liblzma.5.dylib "$SKEL_PREFIX/$ROOT_PREFIX/bin/dpkg-deb"
  1219. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/dpkg"
  1220. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/dpkg-deb"
  1221. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/dpkg-divert"
  1222. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/dpkg-query"
  1223. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/dpkg-split"
  1224. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/dpkg-trigger"
  1225. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/dpkg-statoverride"
  1226. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/update-alternatives"
  1227. echo "appletvos-arm64" >> "$SKEL_PREFIX/var/lib/dpkg/arch"
  1228. echo "darwin-arm64" >> "$SKEL_PREFIX/var/lib/dpkg/arch"
  1229. #Get rid of cross-compile artifacts
  1230. sed -i -- "s|$SKEL_PREFIX||g" "$BUILD_ROOT/$WORKING_DIR/deb/$ROOT_PREFIX/lib/libdpkg.la"
  1231. sed -i -- "s|$SKEL_PREFIX||g" "$BUILD_ROOT/$WORKING_DIR/deb/$ROOT_PREFIX/lib/pkgconfig/libdpkg.pc"
  1232. rm -rf "$BUILD_ROOT/$WORKING_DIR/deb/$ROOT_PREFIX/lib/libdpkg.la--"
  1233. rm -rf "$BUILD_ROOT/$WORKING_DIR/deb/$ROOT_PREFIX/lib/pkgconfig/libdpkg.pc--"
  1234. cd "$BUILD_ROOT"
  1235. fi
  1236. }
  1237. buildDPKGAndDependencies() {
  1238. notifyProgress "Building zlib"
  1239. buildZLib
  1240. notifyProgress "Building xz"
  1241. buildXZ
  1242. notifyProgress "Building bzip2"
  1243. buildBZip2
  1244. notifyProgress "Building lz4"
  1245. buildLZ4
  1246. notifyProgress "Building openSSL"
  1247. buildOpenSSL
  1248. notifyProgress "Building curl"
  1249. buildCurl
  1250. notifyProgress "Building BerkeleyDB"
  1251. buildBerkeleyDB
  1252. notifyProgress "Building tar"
  1253. buildTar
  1254. notifyProgress "Building dpkg"
  1255. buildDpkg
  1256. }
  1257. buildGpgError() {
  1258. PKG_NAME="libgpg-error-1.32"
  1259. checkBuilt $PKG_NAME
  1260. if [[ $? != 0 ]]; then
  1261. echo "$PKG_NAME already exists, skipping!"
  1262. else
  1263. echo "building $PKG_NAME..."
  1264. #splitName $PKG_NAME
  1265. DOWNLOAD_URL="https://www.gnupg.org/ftp/gcrypt/libgpg-error/libgpg-error-1.32.tar.bz2"
  1266. downloadProduct $DOWNLOAD_URL $DOWNLOAD_URL.sig libgpg-error 1.32
  1267. #sed -i -- 's|#include <stdlib.h>|\n#if !defined(__arm64__)\n#define __arm64__\n#endif\n\n#include <stdlib.h>|' ncurses/build.priv.h
  1268. #echo -e "\n#if !defined(__arm64__)\n#define __arm64__\n#endif\n\n" >> config.h.in
  1269. #export HOST="arm"
  1270. buildProduct $PKG_NAME "--enable-threads=posix"
  1271. codesign "$SKEL_PREFIX/$ROOT_PREFIX/lib/libgpg-error.0.dylib"
  1272. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/gpg-error"
  1273. #export HOST="aarch64"
  1274. fi
  1275. }
  1276. patchGcrypt() {
  1277. if [[ "$PLATFORM" == "AppleTVOS" ]]; then
  1278. #if [[ "$PKG_VERSION" == "1.8.2-1" ]]; then
  1279. cat tests/random.c | head -n 39 > random.patched.c
  1280. echo "#include <stdint.h>" >> random.patched.c
  1281. echo "#include <stdio.h>" >> random.patched.c
  1282. echo "#include <stdlib.h>" >> random.patched.c
  1283. echo "#include <spawn.h>" >> random.patched.c
  1284. echo "#include <sys/wait.h>" >> random.patched.c
  1285. echo "#include <sys/stat.h>" >> random.patched.c
  1286. echo "" >> random.patched.c
  1287. echo "extern char **environ;" >> random.patched.c
  1288. echo "" >> random.patched.c
  1289. fixSystem "random.patched.c"
  1290. cat tests/random.c | tail -n 727 | sed 's/system (cmdline)/RunCmd(cmdline)/g' >> random.patched.c
  1291. cp random.patched.c tests/random.c
  1292. #fi
  1293. fi
  1294. }
  1295. buildGcrypt() {
  1296. PKG_NAME="libgcrypt-1.8.2"
  1297. checkBuilt $PKG_NAME
  1298. if [[ $? != 0 ]]; then
  1299. echo "$PKG_NAME already exists, skipping!"
  1300. else
  1301. echo "building $PKG_NAME..."
  1302. splitName $PKG_NAME
  1303. downloadProduct https://www.gnupg.org/ftp/gcrypt/libgcrypt/libgcrypt-1.8.2.tar.bz2 https://www.gnupg.org/ftp/gcrypt/libgcrypt/libgcrypt-1.8.2.tar.bz2.sig $RAW_NAME $VERSION
  1304. patchGcrypt
  1305. export HOST="arm"
  1306. buildProduct $PKG_NAME "--with-libgpg-error-prefix=$SKEL_PREFIX/$ROOT_PREFIX/"
  1307. export HOST="aarch64"
  1308. codesign "$BUILD_ROOT/$WORKING_DIR/deb/$ROOT_PREFIX/bin/dumpsexp"
  1309. codesign "$BUILD_ROOT/$WORKING_DIR/deb/$ROOT_PREFIX/bin/hmac256"
  1310. codesign "$BUILD_ROOT/$WORKING_DIR/deb/$ROOT_PREFIX/bin/mpicalc"
  1311. codesign "$BUILD_ROOT/$WORKING_DIR/deb/$ROOT_PREFIX/lib/libgcrypt.20.dylib"
  1312. fi
  1313. }
  1314. patchKSBA() {
  1315. sed -i -- 's|#include <stdarg.h>|#include <stdarg.h>\n#include "ksba.h"\n|' src/asn1-gentables.c
  1316. FIND='$(CC_FOR_BUILD) -I$(srcdir)'
  1317. sed -i -- "s|$FIND |$FIND -I$SKEL_PREFIX/$ROOT_PREFIX/include |" src/Makefile.in
  1318. # sed -i -- "s|$(CC_FOR_BUILD) -I$(srcdir) |$(CC_FOR_BUILD) -I$(srcdir) -I$SKEL_PREFIX/$ROOT_PREFIX/include/ |" src/Makefile.in
  1319. sed -i -- 's|const char \*gpg_strerror|//const char \*gpg_strerror|' src/gen-help.h
  1320. }
  1321. buildKSBA() {
  1322. PKG_NAME="libksba-1.3.5"
  1323. checkBuilt $PKG_NAME
  1324. if [[ $? != 0 ]]; then
  1325. echo "$PKG_NAME already exists, skipping!"
  1326. else
  1327. echo "building $PKG_NAME..."
  1328. splitName $PKG_NAME
  1329. DOWNLOAD_URL="https://www.gnupg.org/ftp/gcrypt/libksba/libksba-1.3.5.tar.bz2"
  1330. downloadProduct $DOWNLOAD_URL $DOWNLOAD_URL.sig $RAW_NAME $VERSION
  1331. patchKSBA
  1332. buildProduct $PKG_NAME "--with-libgpg-error-prefix=$SKEL_PREFIX/$ROOT_PREFIX/"
  1333. codesign "$SKEL_PREFIX/$ROOT_PREFIX/lib/libksba.8.dylib"
  1334. fi
  1335. }
  1336. patchNpth() {
  1337. if [[ "$PLATFORM" == "AppleTVOS" ]]; then
  1338. sed -i -- 's|#undef HAVE_CLOCK_GETTIME||' config.h.in
  1339. #if [[ "$PKG_VERSION" == "1.5-1" ]]; then
  1340. cat src/npth.c | head -n 19 > npth.patched.c
  1341. echo "#include <stdint.h>" >> npth.patched.c
  1342. echo "#include <stdio.h>" >> npth.patched.c
  1343. echo "#include <stdlib.h>" >> npth.patched.c
  1344. echo "#include <spawn.h>" >> npth.patched.c
  1345. echo "#include <sys/wait.h>" >> npth.patched.c
  1346. echo "" >> npth.patched.c
  1347. echo "extern char **environ;" >> npth.patched.c
  1348. echo "" >> npth.patched.c
  1349. cat src/npth.c | tail -n 757 | head -n 537 >> npth.patched.c
  1350. fixSystem "npth.patched.c"
  1351. cat src/npth.c | tail -n 220 | sed 's/system(cmd)/RunCmd(cmd)/g' >> npth.patched.c
  1352. cp npth.patched.c src/npth.c
  1353. #fi
  1354. fi
  1355. }
  1356. buildNpth() {
  1357. PKG_NAME="npth-1.5"
  1358. checkBuilt $PKG_NAME
  1359. if [[ $? != 0 ]]; then
  1360. echo "$PKG_NAME already exists, skipping!"
  1361. else
  1362. echo "building $PKG_NAME..."
  1363. splitName $PKG_NAME
  1364. DOWNLOAD_URL="https://www.gnupg.org/ftp/gcrypt/npth/npth-1.5.tar.bz2"
  1365. downloadProduct $DOWNLOAD_URL $DOWNLOAD_URL.sig $RAW_NAME $VERSION
  1366. patchNpth
  1367. buildProduct $PKG_NAME
  1368. codesign "$SKEL_PREFIX/$ROOT_PREFIX/lib/libnpth.0.dylib"
  1369. fi
  1370. }
  1371. #https://www.gnupg.org/ftp/gcrypt/libassuan/libassuan-2.5.1.tar.bz2
  1372. buildAssuan() {
  1373. PKG_NAME="libassuan-2.5.1"
  1374. checkBuilt $PKG_NAME
  1375. if [[ $? != 0 ]]; then
  1376. echo "$PKG_NAME already exists, skipping!"
  1377. else
  1378. echo "building $PKG_NAME..."
  1379. splitName $PKG_NAME
  1380. DOWNLOAD_URL="https://www.gnupg.org/ftp/gcrypt/libassuan/libassuan-2.5.1.tar.bz2"
  1381. downloadProduct $DOWNLOAD_URL $DOWNLOAD_URL.sig $RAW_NAME $VERSION
  1382. buildProduct $PKG_NAME "--with-libgpg-error-prefix=$SKEL_PREFIX/$ROOT_PREFIX/"
  1383. codesign "$SKEL_PREFIX/$ROOT_PREFIX/lib/libassuan.0.dylib"
  1384. fi
  1385. }
  1386. patchNtbtls() {
  1387. if [[ "$PLATFORM" == "AppleTVOS" ]]; then
  1388. # this is required because prior dependencies write /$ROOT_PREFIX/lib/libgpg-error.la as a dependency in the .la file
  1389. sed -i -- "s|/$ROOT_PREFIX/lib/libgpg-error.la|$SKEL_PREFIX/$ROOT_PREFIX/lib/libgpg-error.la|g" "$SKEL_PREFIX/$ROOT_PREFIX/lib/libgcrypt.la"
  1390. sed -i -- "s|/$ROOT_PREFIX/lib/libgpg-error.la|$SKEL_PREFIX/$ROOT_PREFIX/lib/libgpg-error.la|g" "$SKEL_PREFIX/$ROOT_PREFIX/lib/libksba.la"
  1391. rm -f "$SKEL_PREFIX/$ROOT_PREFIX/lib/libgcrypt.la--"
  1392. rm -f "$SKEL_PREFIX/$ROOT_PREFIX/lib/libksba.la--"
  1393. fi
  1394. }
  1395. buildNtbtls() {
  1396. PKG_NAME="ntbtls-0.1.2"
  1397. checkBuilt $PKG_NAME
  1398. if [[ $? != 0 ]]; then
  1399. echo "$PKG_NAME already exists, skipping!"
  1400. else
  1401. echo "building $PKG_NAME..."
  1402. splitName $PKG_NAME
  1403. DOWNLOAD_URL="https://www.gnupg.org/ftp/gcrypt/ntbtls/ntbtls-0.1.2.tar.bz2"
  1404. downloadProduct $DOWNLOAD_URL $DOWNLOAD_URL.sig $RAW_NAME $VERSION
  1405. patchNtbtls
  1406. buildProduct $PKG_NAME "--with-libgpg-error-prefix=$SKEL_PREFIX/$ROOT_PREFIX/ --with-libgcrypt-prefix=$SKEL_PREFIX/$ROOT_PREFIX --with-ksba-prefix=$SKEL_PREFIX/$ROOT_PREFIX"
  1407. codesign "$SKEL_PREFIX/$ROOT_PREFIX/lib/libntbtls.0.dylib"
  1408. fi
  1409. }
  1410. patchGpg() {
  1411. if [[ "$PLATFORM" == "AppleTVOS" ]]; then
  1412. #if [[ "$PKG_VERSION" == "2.2.3-1" ]]; then
  1413. cat "g10/exec.c" | head -n 54 > "exec.patched.c"
  1414. echo "#include <stdint.h>" >> "exec.patched.c"
  1415. echo "#include <stdio.h>" >> "exec.patched.c"
  1416. echo "#include <stdlib.h>" >> "exec.patched.c"
  1417. echo "#include <spawn.h>" >> "exec.patched.c"
  1418. echo "#include <sys/wait.h>" >> "exec.patched.c"
  1419. echo "" >> "exec.patched.c"
  1420. echo "extern char **environ;" >> "exec.patched.c"
  1421. echo "" >> "exec.patched.c"
  1422. cat "g10/exec.c" | head -n 111 | tail -n 57 >> "exec.patched.c"
  1423. fixSystem "exec.patched.c"
  1424. cat "g10/exec.c" | tail -n 524 | sed 's/=system(info->command)/=RunCmd(info->command)/g' >> "exec.patched.c"
  1425. cp "exec.patched.c" "g10/exec.c"
  1426. #fi
  1427. fi
  1428. }
  1429. #
  1430. buildGpg() {
  1431. PKG_NAME="gnupg-2.2.3"
  1432. checkBuilt $PKG_NAME
  1433. if [[ $? != 0 ]]; then
  1434. echo "$PKG_NAME already exists, skipping!"
  1435. else
  1436. echo "building $PKG_NAME..."
  1437. splitName $PKG_NAME
  1438. DOWNLOAD_URL="https://www.gnupg.org/ftp/gcrypt/gnupg/gnupg-2.2.3.tar.bz2"
  1439. downloadProduct $DOWNLOAD_URL $DOWNLOAD_URL.sig $RAW_NAME $VERSION
  1440. patchGpg
  1441. buildProduct $PKG_NAME "--with-libgpg-error-prefix=$SKEL_PREFIX/$ROOT_PREFIX/ --with-libgcrypt-prefix=$SKEL_PREFIX/$ROOT_PREFIX/ --with-libassuan-prefix=$SKEL_PREFIX/$ROOT_PREFIX/ --with-ksba-prefix=$SKEL_PREFIX/$ROOT_PREFIX/ --with-npth-prefix=$SKEL_PREFIX/$ROOT_PREFIX/ --with-ntbtls-prefix=$SKEL_PREFIX/$ROOT_PREFIX/"
  1442. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/dirmngr"
  1443. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/dirmngr-client"
  1444. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/gpg"
  1445. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/gpg-agent"
  1446. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/gpg-connect-agent"
  1447. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/gpgconf"
  1448. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/gpgparsemail"
  1449. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/gpgscm"
  1450. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/gpgsm"
  1451. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/gpgtar"
  1452. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/gpgv"
  1453. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/kbxutil"
  1454. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/watchgnupg"
  1455. codesign "$SKEL_PREFIX/$ROOT_PREFIX/libexec/gpg-check-pattern"
  1456. codesign "$SKEL_PREFIX/$ROOT_PREFIX/libexec/gpg-preset-passphrase"
  1457. codesign "$SKEL_PREFIX/$ROOT_PREFIX/libexec/gpg-protect-tool"
  1458. codesign "$SKEL_PREFIX/$ROOT_PREFIX/libexec/gpg-wks-client"
  1459. codesign "$SKEL_PREFIX/$ROOT_PREFIX/libexec/scdaemon"
  1460. fi
  1461. }
  1462. patchAPT() {
  1463. if [[ "$PLATFORM" == "AppleTVOS" ]]; then
  1464. sed -i -- '/^INCLUDE_DIRECTORIES/d' ../CMakeLists.txt
  1465. sed -i -- '/^LINK_DIRECTORIES/d' ../CMakeLists.txt
  1466. cat ../CMakeLists.txt | head -n 15 > newCmakeLists.txt
  1467. echo "INCLUDE_DIRECTORIES($SKEL_PREFIX/$ROOT_PREFIX/include)" >> newCmakeLists.txt
  1468. echo "LINK_DIRECTORIES($SKEL_PREFIX/$ROOT_PREFIX/lib)" >> newCmakeLists.txt
  1469. echo "" >> newCmakeLists.txt
  1470. cat ../CMakeLists.txt | tail -n 217 >> newCmakeLists.txt
  1471. mv newCmakeLists.txt ../CmakeLists.txt
  1472. #sed -i -- "s|/Users/jaywalker/RnD/ATV/packages/test/skel/|$SKEL_PREFIX/|g" ../CMakeLists.txt
  1473. fi
  1474. }
  1475. downloadApt() {
  1476. if [[ ! -d apt ]]; then
  1477. echo "Downlading apt"
  1478. git clone https://git.nito.tv/NitoTV/apt.git
  1479. else
  1480. echo "Using existing apt"
  1481. fi
  1482. WORKING_DIR="apt"
  1483. cd "$WORKING_DIR"
  1484. removeIfNecessary build
  1485. mkdirIfNecessary build
  1486. cd build
  1487. WORKING_DIR="$WORKING_DIR/build"
  1488. }
  1489. buildAPT() {
  1490. PKG_NAME="apt7-0.7.25.3"
  1491. LOG_FILE="$ROOT_LOG_FOLDER/$PKG_NAME.log"
  1492. touch $LOG_FILE
  1493. checkBuilt $PKG_NAME
  1494. if [[ $? != 0 ]]; then
  1495. echo "$PKG_NAME already exists, skipping!"
  1496. else
  1497. downloadApt
  1498. patchAPT
  1499. echo "build output going to: " $LOG_FILE
  1500. if [[ $LOG_VERBOSE == "verbose"* ]]; then
  1501. cmake -DCMAKE_LOCALSTATEDIR="/private/var" -DCMAKE_INSTALL_NAME_DIR="/$ROOT_PREFIX/lib" -DCMAKE_INSTALL_RPATH="/$ROOT_PREFIX/" -DCMAKE_OSX_SYSROOT="$SDK_PATH" -DCMAKE_CXX_FLAGS="-arch $ARCH -Wno-unused-parameter -Wno-unused-private-field -Wno-unknown-warning-option -Wno-writable-strings" -DCMAKE_C_FLAGS="-arch $ARCH -Wno-unused-parameter -Wno-unused-private-field -Wno-unknown-warning-option -Wno-writable-strings" -DCMAKE_INSTALL_PREFIX="/$ROOT_PREFIX/" -DCMAKE_SHARED_LINKER_FLAGS="-lresolv -L$SKEL_PREFIX/$ROOT_PREFIX/lib/" -DCURL_INCLUDE_DIR="$SKEL_PREFIX/$ROOT_PREFIX/include" -DCURL_LIBRARIES="$SKEL_PREFIX/$ROOT_PREFIX/lib/libcurl.4.dylib" -DLZ4_INCLUDE_DIRS="$SKEL_PREFIX/$ROOT_PREFIX/include/" -DLZ4_LIBRARIES="$SKEL_PREFIX/$ROOT_PREFIX/lib/liblz4.dylib" -DLZMA_INCLUDE_DIRS="$SKEL_PREFIX/$ROOT_PREFIX/include/" -DLZMA_LIBRARIES="$SKEL_PREFIX/$ROOT_PREFIX/lib/liblzma.dylib" -DCURRENT_VENDOR=debian -DUSE_NLS=0 -DWITH_DOC=0 -DBERKELEY_DB_INCLUDE_DIRS="$SKEL_PREFIX/$ROOT_PREFIX/include" -DBERKELEY_DB_LIBRARIES="$SKEL_PREFIX/$ROOT_PREFIX/lib/libdb.dylib" -DCMAKE_FIND_ROOT_PATH="$SKEL_PREFIX" .. | tee "${LOG_FILE}"
  1502. #FIXME : need status / error checking here!
  1503. else
  1504. (cmake -DCMAKE_LOCALSTATEDIR="/private/var" -DCMAKE_INSTALL_NAME_DIR="/$ROOT_PREFIX/lib" -DCMAKE_INSTALL_RPATH="/$ROOT_PREFIX/" -DCMAKE_OSX_SYSROOT="$SDK_PATH" -DCMAKE_CXX_FLAGS="-arch $ARCH -Wno-unused-parameter -Wno-unused-private-field -Wno-unknown-warning-option -Wno-writable-strings" -DCMAKE_C_FLAGS="-arch $ARCH -Wno-unused-parameter -Wno-unused-private-field -Wno-unknown-warning-option -Wno-writable-strings" -DCMAKE_INSTALL_PREFIX="/$ROOT_PREFIX/" -DCMAKE_SHARED_LINKER_FLAGS="-lresolv -L$SKEL_PREFIX/$ROOT_PREFIX/lib/" -DCURL_INCLUDE_DIR="$SKEL_PREFIX/$ROOT_PREFIX/include" -DCURL_LIBRARIES="$SKEL_PREFIX/$ROOT_PREFIX/lib/libcurl.4.dylib" -DLZ4_INCLUDE_DIRS="$SKEL_PREFIX/$ROOT_PREFIX/include/" -DLZ4_LIBRARIES="$SKEL_PREFIX/$ROOT_PREFIX/lib/liblz4.dylib" -DLZMA_INCLUDE_DIRS="$SKEL_PREFIX/$ROOT_PREFIX/include/" -DLZMA_LIBRARIES="$SKEL_PREFIX/$ROOT_PREFIX/lib/liblzma.dylib" -DCURRENT_VENDOR=debian -DUSE_NLS=0 -DWITH_DOC=0 -DBERKELEY_DB_INCLUDE_DIRS="$SKEL_PREFIX/$ROOT_PREFIX/include" -DBERKELEY_DB_LIBRARIES="$SKEL_PREFIX/$ROOT_PREFIX/lib/libdb.dylib" -DCMAKE_FIND_ROOT_PATH="$SKEL_PREFIX" .. > "${LOG_FILE}" 2>&1)
  1505. checkStatus $PKG_NAME $? "false"
  1506. if [[ $OPEN_LOG == "true" ]]; then
  1507. open "${LOG_FILE}"
  1508. fi
  1509. fi
  1510. sed -i -- "s|#define COMMON_ARCH \"darwin-amd64\"|#define COMMON_ARCH \"$PLATFORM_LOWER-$ARCH\"|" include/config.h
  1511. if [[ $LOG_VERBOSE == "verbose"* ]]; then
  1512. make -j8 DESTDIR="$SKEL_PREFIX" install | tee "${LOG_FILE}"
  1513. EC=$(grep "fatal error:" -i "${LOG_FILE}" -c)
  1514. checkStatus $PKG_NAME $EC "true"
  1515. else
  1516. (make -j8 DESTDIR="$SKEL_PREFIX" install >> "${LOG_FILE}" 2>&1)
  1517. checkStatus $PKG_NAME $? "true"
  1518. fi
  1519. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/apt"
  1520. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/apt-cache"
  1521. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/apt-cdrom"
  1522. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/apt-config"
  1523. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/apt-ftparchive"
  1524. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/apt-get"
  1525. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/apt-mark"
  1526. codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/apt-sortpkgs"
  1527. codesign "$SKEL_PREFIX/$ROOT_PREFIX/lib/libapt-inst.2.0.0.dylib"
  1528. codesign "$SKEL_PREFIX/$ROOT_PREFIX/lib/libapt-pkg.5.0.1.dylib"
  1529. codesign "$SKEL_PREFIX/$ROOT_PREFIX/lib/libapt-private.0.0.0.dylib"
  1530. codesign "$SKEL_PREFIX/$ROOT_PREFIX/libexec/apt/apt-helper"
  1531. codesign "$SKEL_PREFIX/$ROOT_PREFIX/libexec/apt/methods/cdrom"
  1532. codesign "$SKEL_PREFIX/$ROOT_PREFIX/libexec/apt/methods/copy"
  1533. codesign "$SKEL_PREFIX/$ROOT_PREFIX/libexec/apt/methods/file"
  1534. codesign "$SKEL_PREFIX/$ROOT_PREFIX/libexec/apt/methods/ftp"
  1535. codesign "$SKEL_PREFIX/$ROOT_PREFIX/libexec/apt/methods/gpgv"
  1536. codesign "$SKEL_PREFIX/$ROOT_PREFIX/libexec/apt/methods/http"
  1537. codesign "$SKEL_PREFIX/$ROOT_PREFIX/libexec/apt/methods/https"
  1538. #codesign "$SKEL_PREFIX/$ROOT_PREFIX/libexec/apt/methods/mirror"
  1539. codesign "$SKEL_PREFIX/$ROOT_PREFIX/libexec/apt/methods/rred"
  1540. codesign "$SKEL_PREFIX/$ROOT_PREFIX/libexec/apt/methods/rsh"
  1541. codesign "$SKEL_PREFIX/$ROOT_PREFIX/libexec/apt/methods/store"
  1542. codesign "$SKEL_PREFIX/$ROOT_PREFIX/libexec/apt/planners/apt"
  1543. codesign "$SKEL_PREFIX/$ROOT_PREFIX/libexec/apt/solvers/apt"
  1544. codesign "$SKEL_PREFIX/$ROOT_PREFIX/libexec/apt/solvers/dump"
  1545. #lzma conflicts with built in libraries we make -j8 an extra copy of our version of lzma in the xz build process
  1546. #here we change libapt-pkg*.dylib to look for this version instead
  1547. #if we do not do this, apt-get will fail from our helper tool
  1548. install_name_tool -change /usr/lib/liblzma.5.dylib /usr/local/lib/liblzma.5.dylib $SKEL_PREFIX/$ROOT_PREFIX/lib/libapt-pkg.5.0.1.dylib
  1549. cd "$BUILD_ROOT"
  1550. fi
  1551. }
  1552. buildAPTAndDependencies() {
  1553. notifyProgress "Building gpg-error"
  1554. buildGpgError
  1555. notifyProgress "Building gcrypt"
  1556. buildGcrypt
  1557. notifyProgress "Building KSBA"
  1558. buildKSBA
  1559. notifyProgress "Building npth"
  1560. buildNpth
  1561. notifyProgress "Building Assuan"
  1562. buildAssuan
  1563. notifyProgress "Building ntbtls"
  1564. buildNtbtls
  1565. notifyProgress "Building gpg"
  1566. buildGpg
  1567. notifyProgress "Building apt"
  1568. buildAPT
  1569. }
  1570. prepSDK() {
  1571. if [[ ! -e "$SDK_PATH/usr/include/sys/ttydev.h" ]]; then
  1572. echo "Missing <sys/ttydev.h>. Moving it in from MacOSX SDK (with sudo)"
  1573. sudo cp "$(xcrun --sdk macosx --show-sdk-path)/usr/include/sys/ttydev.h" "$SDK_PATH/usr/include/sys/ttydev.h"
  1574. fi
  1575. if [[ ! -e "$SDK_PATH/usr/include/lockdown.h" ]]; then
  1576. echo "Missing lockdown.h! Generating the bare essentials for apt to build..."
  1577. echo "#ifndef LOCKDOWN_LOCKDOWN_H" >> "$SDK_PATH/usr/include/lockdown.h"
  1578. echo "#define LOCKDOWN_LOCKDOWN_H" >> "$SDK_PATH/usr/include/lockdown.h"
  1579. echo "" >> "$SDK_PATH/usr/include/lockdown.h"
  1580. echo "#include <CoreFoundation/CFString.h>" >> "$SDK_PATH/usr/include/lockdown.h"
  1581. echo "" >> "$SDK_PATH/usr/include/lockdown.h"
  1582. echo "#ifdef __cplusplus" >> "$SDK_PATH/usr/include/lockdown.h"
  1583. echo "extern \"C\" {" >> "$SDK_PATH/usr/include/lockdown.h"
  1584. echo "#endif" >> "$SDK_PATH/usr/include/lockdown.h"
  1585. echo "" >> "$SDK_PATH/usr/include/lockdown.h"
  1586. echo "extern CFStringRef kLockdownUniqueDeviceIDKey;" >> "$SDK_PATH/usr/include/lockdown.h"
  1587. echo "" >> "$SDK_PATH/usr/include/lockdown.h"
  1588. echo "extern void *lockdown_connect(void);" >> "$SDK_PATH/usr/include/lockdown.h"
  1589. echo "extern CFStringRef lockdown_copy_value(void *lockdown, void *null, CFStringRef key);" >> "$SDK_PATH/usr/include/lockdown.h"
  1590. echo "extern void lockdown_disconnect(void *lockdown);" >> "$SDK_PATH/usr/include/lockdown.h"
  1591. echo "" >> "$SDK_PATH/usr/include/lockdown.h"
  1592. echo "#ifdef __cplusplus" >> "$SDK_PATH/usr/include/lockdown.h"
  1593. echo "}" >> "$SDK_PATH/usr/include/lockdown.h"
  1594. echo "#endif" >> "$SDK_PATH/usr/include/lockdown.h"
  1595. echo "" >> "$SDK_PATH/usr/include/lockdown.h"
  1596. echo "#endif/*LOCKDOWN_LOCKDOWN_H*/" >> "$SDK_PATH/usr/include/lockdown.h"
  1597. fi
  1598. IOKIT_MATCH="`find ~/Library/Developer/Xcode/tvOS\ DeviceSupport/ -name IOKit.framework | grep "$SDK_VERSION" -m 1`"
  1599. echo "IOKit match: $IOKIT_MATCH"
  1600. echo "IOKit: $SDK_PATH/System/Library/Frameworks/IOKit.framework"
  1601. if [[ ! -d "$SDK_PATH/System/Library/Frameworks/IOKit.framework" ]]; then
  1602. if [[ ! -z "$IOKIT_MATCH" ]]; then
  1603. echo "we do indeed have an IOKit match and IOKit is missing!!"
  1604. echo "cp -r $IOKIT_MATCH $SDK_PATH/System/Library/Frameworks/"
  1605. cp -r "$IOKIT_MATCH" "$SDK_PATH/System/Library/Frameworks/"
  1606. fi
  1607. fi
  1608. # patch fork to be available in tvOS
  1609. sed -i -- "s|__TVOS_PROHIBITED| |" $SDK_PATH/usr/include/unistd.h
  1610. # patch 'system' in places where it isnt patched out and replaced by our own version (ie cdromtools etc)
  1611. sed -i -- "s|__TVOS_PROHIBITED| |" $SDK_PATH/usr/include/stdlib.h
  1612. sed -i -- "s|__API_AVAILABLE(macos(10.0))|__API_AVAILABLE(macos(10.0), tvos(9.0))|" $SDK_PATH/usr/include/stdlib.h
  1613. }
  1614. if [[ $LOG_VERBOSE == "verbose"* ]]; then
  1615. set -x
  1616. fi
  1617. if [[ "$VERIFY" == "true" ]]; then
  1618. command -v gpg >/dev/null 2>&1 || { echo >&2 "Missing GPG. Cannot verify. Dying."; exit 127 ; }
  1619. echo "Importing necessary PGP keys"
  1620. gpg --recv-key 69184620 7C0135FB088AAF6C66C650B9BB5869F064EA74AB 702353E0F7E48EDB 7FD9FCCB000BEEEE A15B725964A95EE5 D8692123C4065DEA5E0F3AB5249B39D24F25E3B6 031EC2536E580D8EA286A9F22071B08A33BD3F06 9D5EAAF69013B842
  1621. fi
  1622. createStatusFile() {
  1623. cd "$BUILD_ROOT"
  1624. rm -rf status
  1625. rm -rf available
  1626. for f in debs/*.deb; do
  1627. echo "Processing $f..";
  1628. dpkg-deb -f "$f" >> status
  1629. dpkg-deb -f "$f" >> available
  1630. echo "Status: install ok installed" >> status
  1631. echo "" >> status
  1632. echo "" >> available
  1633. done
  1634. if [[ -d "$SKEL_PREFIX/private/var/lib/dpkg/" ]]; then
  1635. mv status "$SKEL_PREFIX/private/var/lib/dpkg/status"
  1636. mv available "$SKEL_PREFIX/private/var/lib/dpkg/available"
  1637. else
  1638. echo "### [WARNING]: $SKEL_PREFIX/private/var/lib/dpkg/ is missing! this bootstrap is likely malformed..."
  1639. echo ""
  1640. mv status "$SKEL_PREFIX/var/lib/dpkg/status"
  1641. mv available "$SKEL_PREFIX/var/lib/dpkg/available"
  1642. fi
  1643. }
  1644. cleanBootstrap() {
  1645. # Get rid of the docs
  1646. rm -rf "$SKEL_PREFIX/$ROOT_PREFIX/docs"
  1647. rm -rf "$SKEL_PREFIX/$ROOT_PREFIX/share/doc"
  1648. rm -rf "$SKEL_PREFIX/$ROOT_PREFIX/share/info"
  1649. rm -rf "$SKEL_PREFIX/$ROOT_PREFIX/share/man"
  1650. rm -rf "$SKEL_PREFIX/$ROOT_PREFIX/man"
  1651. rm -rf "$SKEL_PREFIX/$ROOT_PREFIX/share/gnupg" #TODO: See if the keys in this folder are needed
  1652. rm -rf "$SKEL_PREFIX/$ROOT_PREFIX/share/readline"
  1653. # Get rid of dev stuff
  1654. rm -rf "$SKEL_PREFIX/$ROOT_PREFIX/include"
  1655. rm -rf "$SKEL_PREFIX/$ROOT_PREFIX/share/aclocal"
  1656. rm -rf "$SKEL_PREFIX/$ROOT_PREFIX/share/pkgconfig"
  1657. rm -rf "$SKEL_PREFIX/$ROOT_PREFIX/share/common-lisp"
  1658. # remove all the static and libtool libraries from the bootstrap, they take up a LOT of space
  1659. cd "$SKEL_PREFIX/$ROOT_PREFIX/lib"
  1660. rm *.a
  1661. rm *.la
  1662. rmdir "$SKEL_PREFIX/$ROOT_PREFIX/var"
  1663. #Get rid of non-skel packages which were needed to compile
  1664. rm -rf "$SKEL_PREFIX/$ROOT_PREFIX/bin/gpg-error-config"
  1665. rm -rf "$SKEL_PREFIX/$ROOT_PREFIX/bin/libgcrypt-config"
  1666. rm -rf "$SKEL_PREFIX/$ROOT_PREFIX/lib/pkgconfig"
  1667. rm -rf "$SKEL_PREFIX/$ROOT_PREFIX/bin/curl-config"
  1668. rm -rf "$SKEL_PREFIX/$ROOT_PREFIX/bin/ncurses6-config"
  1669. rm -rf "$SKEL_PREFIX/$ROOT_PREFIX/bin/npth-config"
  1670. rm -rf "$SKEL_PREFIX/$ROOT_PREFIX/bin/ntbtls-config"
  1671. }
  1672. mkdirIfNecessary $ROOT_LOG_FOLDER
  1673. mkdirIfNecessary $ALREADY_BUILT
  1674. # Ensure our SDK has all the required "extras" installed/setup
  1675. prepSDK
  1676. buildBashAndFriends
  1677. buildBasicUtils
  1678. buildDPKGAndDependencies
  1679. buildAPTAndDependencies
  1680. # comment the below in to clean up aftewards to slim down the bootstrap
  1681. if [[ $TRIM == "true" ]]; then
  1682. cleanBootstrap
  1683. fi
  1684. #createStatusFile
  1685. echo -e "\nDone!\n"
  1686. sayIfVerbal "Finished!"