the_memo2.sh 67 KB

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