the_memo2.sh 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384
  1. #!/bin/bash
  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. usage() {
  22. echo "usage: $0 [-s|--speak-updates] [-i|--insecure] [-v|--verbose] [-f|--force]"
  23. trap - INT TERM EXIT
  24. exit 0
  25. }
  26. while test $# -gt 0; do
  27. case "$1" in
  28. -h|--help)
  29. usage
  30. ;;
  31. -v|--verbose)
  32. LOG_VERBOSE="verbose"
  33. shift
  34. ;;
  35. -i|--insecure|--no-verify)
  36. VERIFY="false"
  37. echo "Working without verifying packages..."
  38. echo "YOU BETTER KNOW WHAT YOU'RE DOING"
  39. sleep 2 #Give them a couple seconds to think about what they're about to do
  40. shift
  41. ;;
  42. -f|--force)
  43. shift
  44. FORCE="true"
  45. shift
  46. ;;
  47. -s|--speak-updates|--speak)
  48. shift
  49. SPEAK="true"
  50. shift
  51. ;;
  52. *)
  53. break
  54. ;;
  55. esac
  56. done
  57. sayIfVerbal() {
  58. if [[ $SPEAK == "true" ]]; then
  59. say $1
  60. fi
  61. }
  62. splitName() {
  63. IN=$1
  64. i=0
  65. while [ "$IN" != "$iter" ] ;do
  66. # extract the substring from start of string up to delimiter.
  67. iter=${IN%%-*}
  68. # delete this first "element" AND next separator, from $IN.
  69. IN="${IN#$iter-}"
  70. ((i=i+1))
  71. if [[ $i == 1 ]]; then
  72. echo "set RAW_NAME var to $iter"
  73. RAW_NAME=$iter
  74. elif [[ $i == 2 ]]; then
  75. VERSION=$iter
  76. echo "set VERSION var to $iter"
  77. fi
  78. #echo $iter at $i
  79. done
  80. }
  81. #IN="bla@some.com;john@home.com;Full Name <fulnam@other.org>"
  82. spinner() {
  83. local pid=$!
  84. local delay=0.75
  85. local spinstr='|/-\'
  86. while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do
  87. local temp=${spinstr#?}
  88. printf " [%c]" "$spinstr"
  89. local spinstr=$temp${spinstr%"$temp"}
  90. sleep $delay
  91. printf "\b\b\b\b\b"
  92. done
  93. wait $pid
  94. return $?
  95. }
  96. setBuilt() {
  97. DIRECTORY_NAME=$1
  98. FULL=$ALREADY_BUILT/$DIRECTORY_NAME
  99. touch "$FULL"
  100. }
  101. checkStatus() {
  102. PKG=$1
  103. STATUS=$2
  104. FINISHED=$3
  105. if [[ $STATUS != 0 ]]; then
  106. echo "configure or make $PKG returned with non zero: $STATUS check $LOG_FILE for errors!"
  107. open $LOG_FILE
  108. exit $STATUS
  109. else
  110. echo "make returned with zero"
  111. if [[ $FINISHED == "true" ]]; then
  112. setBuilt $PKG
  113. fi
  114. fi
  115. }
  116. checkBuilt() {
  117. if [[ "$FORCE" == "true" ]]; then
  118. echo 0
  119. return 0
  120. fi
  121. DIRECTORY_NAME=$1
  122. FULL=$ALREADY_BUILT/$DIRECTORY_NAME
  123. if [[ ! -f $FULL ]]; then
  124. echo 0
  125. return 0
  126. fi
  127. echo 1
  128. return 1
  129. }
  130. notifyProgress() {
  131. echo "$1"
  132. sayIfVerbal "$1"
  133. }
  134. checkSHA256() {
  135. if [[ "$VERIFY" == "true" ]]; then
  136. FILE="$1"
  137. VALID_SHA="$2"
  138. VERIFY_TEST="`shasum -a 256 $FILE | cut -c 1-64`"
  139. if [[ "$VERIFY_TEST" != "$VALID_SHA" ]]; then
  140. echo "Failed to validate SHA256 signature for $FILE"
  141. trap - INT TERM EXIT
  142. exit 127
  143. fi
  144. echo "*** VALID SIGNATURE"
  145. fi
  146. }
  147. checkPGPSig() {
  148. if [[ "$VERIFY" == "true" ]]; then
  149. SIGFILE="$1"
  150. FILE="$2"
  151. local VERIFY_TEST="`gpg --verify $SIGFILE $FILE 2>&1 | grep 'Good signature'`"
  152. if [[ "$VERIFY_TEST" == "" ]]; then
  153. echo "Failed to validate PGP signature for $FILE"
  154. trap - INT TERM EXIT
  155. exit 127
  156. fi
  157. echo "*** VALID SIGNATURE"
  158. fi
  159. }
  160. buildProduct() {
  161. PKG_NAME=$1
  162. EXTRA_CFG=$2
  163. LOG_FILE="$ROOT_LOG_FOLDER/$PKG_NAME.log"
  164. touch $LOG_FILE
  165. echo $PKG_NAME
  166. echo "build output going to: " $LOG_FILE
  167. echo $EXTRA_CFG
  168. export SDKROOT=$(xcrun --sdk $PLATFORM_LOWER --show-sdk-path)
  169. export VER_MIN=13.0
  170. export CC=$(xcrun --sdk $PLATFORM_LOWER --find clang)
  171. export CXX=$(xcrun --sdk $PLATFORM_LOWER --find clang++)
  172. export LD=$(xcrun --sdk $PLATFORM_LOWER --find ld)
  173. export AR=$(xcrun --sdk $PLATFORM_LOWER --find ar)
  174. export CPP="$(xcrun --sdk $PLATFORM_LOWER -f clang) -E -D__arm__ -D__arm64__ -I$SKEL_PREFIX/$ROOT_PREFIX/include/ -I$SDKROOT/usr/include"
  175. export CXXCPP="$(xcrun --sdk $PLATFORM_LOWER -f clang++) -E -D__arm__ -D__arm64__ -I$SKEL_PREFIX/$ROOT_PREFIX/include/ -I$SDKROOT/usr/include"
  176. export RANLIB=$(xcrun --sdk $PLATFORM_LOWER --find ranlib)
  177. export LIBTOOL=$(xcrun --sdk $PLATFORM_LOWER --find libtool)
  178. export STRIP=$(xcrun --sdk $PLATFORM_LOWER --find strip)
  179. 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"
  180. export CXXFLAGS=$CFLAGS
  181. export LDFLAGS="-arch arm64 -isysroot $SDKROOT -L$SKEL_PREFIX/$ROOT_PREFIX/lib/ $EXTRA_LD_FLAGS"
  182. sayIfVerbal "configuring $PKG_NAME"
  183. if [[ $LOG_VERBOSE == "verbose"* ]]; then
  184. ./configure --prefix=/$ROOT_PREFIX --host=$HOST-apple-darwin --target=$HOST-apple-darwin --disable-dependency-tracking --without-manpages --disable-tests $EXTRA_CFG | tee "${LOG_FILE}"
  185. else
  186. (./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)
  187. fi
  188. checkStatus $PKG_NAME $? "false"
  189. sayIfVerbal "making $PKG_NAME"
  190. echo -e "\n\nPOST CONFIGURE\n\n" >> "$LOG_FILE"
  191. if [[ $LOG_VERBOSE == "verbose"* ]]; then
  192. make -j8 DESTDIR="$SKEL_PREFIX" install | tee -a "${LOG_FILE}"
  193. else
  194. (make -j8 DESTDIR="$SKEL_PREFIX" install >> "${LOG_FILE}" 2>&1) #& spinner
  195. fi
  196. checkStatus $PKG_NAME $? "true"
  197. cd "$BUILD_ROOT"
  198. }
  199. downloadProduct() {
  200. DOWNLOAD_LINK=$1
  201. FILENAME=$(basename $DOWNLOAD_LINK)
  202. SIG_DOWNLOAD=$2
  203. RAW_NAME=$3
  204. VERSION=$4
  205. FILE_EXTENSION="${FILENAME##*.}"
  206. DIRECTORY_NAME="$RAW_NAME-$VERSION"
  207. SIG_FILE=$(basename $SIG_DOWNLOAD)
  208. if [[ ! -e $FILENAME ]]; then
  209. echo "Downloading $FILENAME"
  210. curl -LO $DOWNLOAD_LINK
  211. if [[ ! $SIG_FILE == "-" ]]; then
  212. curl -LO $SIG_DOWNLOAD
  213. checkPGPSig $SIG_FILE $FILENAME
  214. fi
  215. else
  216. echo "Using existing $FILENAME"
  217. fi
  218. rm -rf $DIRECTORY_NAME
  219. if [[ $FILE_EXTENSION == "gz" ]]; then
  220. echo "is gz file!"
  221. tar xzvf $FILENAME
  222. fi
  223. if [[ $FILE_EXTENSION == "xz" ]]; then
  224. echo "is lzma file!"
  225. tar xJvf $FILENAME
  226. fi
  227. if [[ $FILE_EXTENSION == "bz2" ]]; then
  228. echo "is bzip2 file!"
  229. tar xjvf $FILENAME
  230. fi
  231. WORKING_DIR=$DIRECTORY_NAME
  232. PKG_VERSION=$VERSION-1
  233. cd "$WORKING_DIR"
  234. #buildProduct
  235. }
  236. patchBash() {
  237. if [[ "$PLATFORM" == "AppleTVOS" ]]; then
  238. sed -i -- 's|^#undef HAVE_SYS_SIGLIST$|#define HAVE_SYS_SIGLIST 1|' config.h.in
  239. fi
  240. }
  241. patchDpkg() {
  242. if [[ "$PLATFORM" == "AppleTVOS" ]]; then
  243. sed -i -- "s|#define ARCHITECTURE \"darwin-arm\"|#define ARCHITECTURE \"$PLATFORM_LOWER-$ARCH\"|" config.h
  244. sed -i -- 's|gtar|tar|' config.h
  245. fi
  246. }
  247. # DONT USE UNLESS YOU ARE ON 11+; OVERWRITE BASH (or any other apple-signed file, for that matter), LEAD TO BRICK
  248. # 10.2 and up
  249. buildBashAndFriends() {
  250. notifyProgress "Building readline"
  251. buildReadline
  252. #notifyProgress "Building ncurses"
  253. #buildNcurses
  254. #notifyProgress "Building bash"
  255. #buildBash
  256. }
  257. buildReadline() {
  258. PKG_NAME="readline-7.0"
  259. checkBuilt $PKG_NAME
  260. if [[ $? != 0 ]]; then
  261. echo "$PKG_NAME already exists, skipping!"
  262. else
  263. echo "building $PKG_NAME..."
  264. splitName $PKG_NAME
  265. 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
  266. buildProduct $PKG_NAME
  267. fi
  268. }
  269. fixSystem() {
  270. FILE="$1"
  271. echo '#define PROC_PIDPATHINFO_MAXSIZE (1024)' >> "$FILE"
  272. echo 'static int file_exist(const char *filename) {' >> "$FILE"
  273. echo ' struct stat buffer;' >> "$FILE"
  274. echo ' int r = stat(filename, &buffer);' >> "$FILE"
  275. echo ' return (r == 0);' >> "$FILE"
  276. echo '}' >> "$FILE"
  277. echo '' >> "$FILE"
  278. echo 'static char *searchpath(const char *binaryname){' >> "$FILE"
  279. echo ' if (strstr(binaryname, "/") != NULL){' >> "$FILE"
  280. echo ' if (file_exist(binaryname)){' >> "$FILE"
  281. echo ' char *foundpath = malloc((strlen(binaryname) + 1) * (sizeof(char)));' >> "$FILE"
  282. echo ' strcpy(foundpath, binaryname);' >> "$FILE"
  283. echo ' return foundpath;' >> "$FILE"
  284. echo ' } else {' >> "$FILE"
  285. echo ' return NULL;' >> "$FILE"
  286. echo ' }' >> "$FILE"
  287. echo ' }' >> "$FILE"
  288. echo ' ' >> "$FILE"
  289. echo ' char *pathvar = getenv("PATH");' >> "$FILE"
  290. echo ' ' >> "$FILE"
  291. echo ' char *dir = strtok(pathvar,":");' >> "$FILE"
  292. echo ' while (dir != NULL){' >> "$FILE"
  293. echo ' char searchpth[PROC_PIDPATHINFO_MAXSIZE];' >> "$FILE"
  294. echo ' strcpy(searchpth, dir);' >> "$FILE"
  295. echo ' strcat(searchpth, "/");' >> "$FILE"
  296. echo ' strcat(searchpth, binaryname);' >> "$FILE"
  297. echo ' ' >> "$FILE"
  298. echo ' if (file_exist(searchpth)){' >> "$FILE"
  299. echo ' char *foundpath = malloc((strlen(searchpth) + 1) * (sizeof(char)));' >> "$FILE"
  300. echo ' strcpy(foundpath, searchpth);' >> "$FILE"
  301. echo ' return foundpath;' >> "$FILE"
  302. echo ' }' >> "$FILE"
  303. echo ' ' >> "$FILE"
  304. echo ' dir = strtok(NULL, ":");' >> "$FILE"
  305. echo ' }' >> "$FILE"
  306. echo ' return NULL;' >> "$FILE"
  307. echo '}' >> "$FILE"
  308. echo '' >> "$FILE"
  309. echo 'static int isShellScript(const char *path){' >> "$FILE"
  310. echo ' FILE *file = fopen(path, "r");' >> "$FILE"
  311. echo ' uint8_t header[2];' >> "$FILE"
  312. echo ' if (fread(header, sizeof(uint8_t), 2, file) == 2){' >> "$FILE"
  313. echo " if (header[0] == '#' && header[1] == '!'){" >> "$FILE"
  314. echo ' fclose(file);' >> "$FILE"
  315. echo ' return 1;' >> "$FILE"
  316. echo ' }' >> "$FILE"
  317. echo ' }' >> "$FILE"
  318. echo ' fclose(file);' >> "$FILE"
  319. echo ' return -1;' >> "$FILE"
  320. echo '}' >> "$FILE"
  321. echo '' >> "$FILE"
  322. echo 'static char *getInterpreter(char *path){' >> "$FILE"
  323. echo ' FILE *file = fopen(path, "r");' >> "$FILE"
  324. echo ' char *interpreterLine = NULL;' >> "$FILE"
  325. echo ' unsigned long lineSize = 0;' >> "$FILE"
  326. echo ' getline(&interpreterLine, &lineSize, file);' >> "$FILE"
  327. echo ' ' >> "$FILE"
  328. echo ' char *rawInterpreter = (interpreterLine+2);' >> "$FILE"
  329. echo ' rawInterpreter = strtok(rawInterpreter, " ");' >> "$FILE"
  330. echo ' rawInterpreter = strtok(rawInterpreter, "\n");' >> "$FILE"
  331. echo ' ' >> "$FILE"
  332. echo ' char *interpreter = malloc((strlen(rawInterpreter)+1) * sizeof(char));' >> "$FILE"
  333. echo ' strcpy(interpreter, rawInterpreter);' >> "$FILE"
  334. echo ' ' >> "$FILE"
  335. echo ' free(interpreterLine);' >> "$FILE"
  336. echo ' fclose(file);' >> "$FILE"
  337. echo ' return interpreter;' >> "$FILE"
  338. echo '}' >> "$FILE"
  339. echo '' >> "$FILE"
  340. echo 'static char *fixedCmd(const char *cmdStr){' >> "$FILE"
  341. echo ' char *cmdCpy = malloc((strlen(cmdStr)+1) * sizeof(char));' >> "$FILE"
  342. echo ' strcpy(cmdCpy, cmdStr);' >> "$FILE"
  343. echo ' ' >> "$FILE"
  344. echo ' char *cmd = strtok(cmdCpy, " ");' >> "$FILE"
  345. echo ' ' >> "$FILE"
  346. echo ' uint8_t size = strlen(cmd) + 1;' >> "$FILE"
  347. echo ' ' >> "$FILE"
  348. echo ' char *args = cmdCpy + size;' >> "$FILE"
  349. echo ' if ((strlen(cmdStr) - strlen(cmd)) == 0)' >> "$FILE"
  350. echo ' args = NULL;' >> "$FILE"
  351. echo ' ' >> "$FILE"
  352. echo ' char *abs_path = searchpath(cmd);' >> "$FILE"
  353. echo ' if (abs_path){' >> "$FILE"
  354. echo ' int isScript = isShellScript(abs_path);' >> "$FILE"
  355. echo ' if (isScript == 1){' >> "$FILE"
  356. echo ' char *interpreter = getInterpreter(abs_path);' >> "$FILE"
  357. echo ' ' >> "$FILE"
  358. echo ' uint8_t commandSize = strlen(interpreter) + 1 + strlen(abs_path);' >> "$FILE"
  359. echo ' ' >> "$FILE"
  360. echo ' if (args){' >> "$FILE"
  361. echo ' commandSize += 1 + strlen(args);' >> "$FILE"
  362. echo ' }' >> "$FILE"
  363. echo ' ' >> "$FILE"
  364. echo ' char *rawCommand = malloc(sizeof(char) * (commandSize + 1));' >> "$FILE"
  365. echo ' strcpy(rawCommand, interpreter);' >> "$FILE"
  366. echo ' strcat(rawCommand, " ");' >> "$FILE"
  367. echo ' strcat(rawCommand, abs_path);' >> "$FILE"
  368. echo ' ' >> "$FILE"
  369. echo ' if (args){' >> "$FILE"
  370. echo ' strcat(rawCommand, " ");' >> "$FILE"
  371. echo ' strcat(rawCommand, args);' >> "$FILE"
  372. echo ' }' >> "$FILE"
  373. echo ' rawCommand[(commandSize)+1] = "\0";' >> "$FILE"
  374. echo ' ' >> "$FILE"
  375. echo ' free(interpreter);' >> "$FILE"
  376. echo ' free(abs_path);' >> "$FILE"
  377. echo ' free(cmdCpy);' >> "$FILE"
  378. echo ' ' >> "$FILE"
  379. echo ' return rawCommand;' >> "$FILE"
  380. echo ' } else {' >> "$FILE"
  381. echo ' uint8_t commandSize = strlen(abs_path);' >> "$FILE"
  382. echo ' ' >> "$FILE"
  383. echo ' if (args){' >> "$FILE"
  384. echo ' commandSize += 1 + strlen(args);' >> "$FILE"
  385. echo ' }' >> "$FILE"
  386. echo ' ' >> "$FILE"
  387. echo ' char *rawCommand = malloc(sizeof(char) * (commandSize + 1));' >> "$FILE"
  388. echo ' strcat(rawCommand, abs_path);' >> "$FILE"
  389. echo ' ' >> "$FILE"
  390. echo ' if (args){' >> "$FILE"
  391. echo ' strcat(rawCommand, " ");' >> "$FILE"
  392. echo ' strcat(rawCommand, args);' >> "$FILE"
  393. echo ' }' >> "$FILE"
  394. echo ' rawCommand[(commandSize)+1] = "\0";' >> "$FILE"
  395. echo ' ' >> "$FILE"
  396. echo ' free(abs_path);' >> "$FILE"
  397. echo ' free(cmdCpy);' >> "$FILE"
  398. echo ' ' >> "$FILE"
  399. echo ' return rawCommand;' >> "$FILE"
  400. echo ' }' >> "$FILE"
  401. echo ' }' >> "$FILE"
  402. echo ' return cmdCpy;' >> "$FILE"
  403. echo '}' >> "$FILE"
  404. echo '' >> "$FILE"
  405. echo 'int RunCmd(const char *cmd) {' >> "$FILE"
  406. echo ' pid_t pid;' >> "$FILE"
  407. echo ' char *rawCmd = fixedCmd(cmd);' >> "$FILE"
  408. echo ' char *argv[] = {"sh", "-c", (char*)rawCmd, NULL};' >> "$FILE"
  409. echo ' int status;' >> "$FILE"
  410. echo ' status = posix_spawn(&pid, "/bin/sh", NULL, NULL, argv, environ);' >> "$FILE"
  411. echo ' if (status == 0) {' >> "$FILE"
  412. echo ' if (waitpid(pid, &status, 0) == -1) {' >> "$FILE"
  413. echo ' perror("waitpid");' >> "$FILE"
  414. echo ' }' >> "$FILE"
  415. echo ' } else {' >> "$FILE"
  416. echo ' printf("posix_spawn: %s\n", strerror(status));' >> "$FILE"
  417. echo ' }' >> "$FILE"
  418. echo ' free(rawCmd);' >> "$FILE"
  419. echo ' return status;' >> "$FILE"
  420. echo '}' >> "$FILE"
  421. }
  422. patchNcurses() {
  423. PKG_NAME=$1
  424. echo "patchNCurses PKG_NAME: $PKG_NAME"
  425. if [[ "$PLATFORM" == "AppleTVOS" ]]; then
  426. if [[ "$PKG_VERSION" == "6.0-1" ]]; then
  427. # LEFT ERROR ON environ)' no ;
  428. # For some reason, building never fails on the error...
  429. # But still, tput is in /usr/bin... so.... ??
  430. cat progs/tput.c | head -n 55 > tput.patched.c
  431. echo "#include <stdint.h>" >> tput.patched.c
  432. echo "#include <stdio.h>" >> tput.patched.c
  433. echo "#include <stdlib.h>" >> tput.patched.c
  434. echo "#include <spawn.h>" >> tput.patched.c
  435. echo "#include <sys/wait.h>" >> tput.patched.c
  436. echo "" >> tput.patched.c
  437. echo "extern char **environ;" >> tput.patched.c
  438. echo "" >> tput.patched.c
  439. cat progs/tput.c | tail -n 350 | head -n 50 >> tput.patched.c
  440. fixSystem "tput.patched.c"
  441. cat progs/tput.c | tail -n 301 | sed 's/system(init_prog)/RunCmd(init_prog)/g' >> tput.patched.c
  442. cp tput.patched.c progs/tput.c
  443. fi
  444. fi
  445. sed -i -- 's|#include <stdlib.h>|\n#if !defined(__arm64__)\n#define __arm64__\n#endif\n\n#include <stdlib.h>|' ncurses/build.priv.h
  446. CURSES_PRIV="$SKEL_PREFIX/$ROOT_PREFIX/include/curses.priv.h"
  447. FIFO="$SKEL_PREFIX/$ROOT_PREFIX/include/fifo_defs.h"
  448. BUILD_P="$SKEL_PREFIX/$ROOT_PREFIX/include/build.priv.h"
  449. if [[ ! -f "$CURSES_PRIV" ]]; then
  450. cp $BUILD_ROOT/$1/ncurses/*.h "$SKEL_PREFIX/$ROOT_PREFIX/include/"
  451. #cp "$BUILD_ROOT/$1/ncurses/fifo_defs.h" "$FIFO"
  452. #cp "$BUILD_ROOT/$1/ncurses/build.priv.h" "$BUILD_P"
  453. fi
  454. }
  455. #https://git.elucubratus.com/elucubratus/elucubratus/-/raw/master/data/ncurses/ncurses_6.1+20181013.orig.tar.gz
  456. buildNcurses() {
  457. PKG_NAME="ncurses-6.0"
  458. checkBuilt $PKG_NAME
  459. if [[ $? != 0 ]]; then
  460. echo "$PKG_NAME already exists, skipping!"
  461. else
  462. echo "building $PKG_NAME..."
  463. splitName $PKG_NAME
  464. downloadProduct http://gnu.mirror.constant.com/ncurses/ncurses-6.0.tar.gz http://gnu.mirror.constant.com/ncurses/ncurses-6.0.tar.gz.sig $RAW_NAME $VERSION
  465. patchNcurses $PKG_NAME
  466. buildProduct $PKG_NAME
  467. fi
  468. }
  469. #https://git.elucubratus.com/elucubratus/elucubratus/-/raw/master/data/bash/bash-5.0.tar.gz
  470. buildBash() {
  471. PKG_NAME="bash-5.0"
  472. checkBuilt $PKG_NAME
  473. if [[ $? != 0 ]]; then
  474. echo "$PKG_NAME already exists, skipping!"
  475. else
  476. echo "building $PKG_NAME..."
  477. splitName $PKG_NAME
  478. downloadProduct https://git.elucubratus.com/elucubratus/elucubratus/-/raw/master/data/bash/bash-5.0.tar.gz - $RAW_NAME $VERSION
  479. patchBash
  480. 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"
  481. fi
  482. }
  483. buildSed() {
  484. PKG_NAME="sed-4.4"
  485. checkBuilt $PKG_NAME
  486. if [[ $? != 0 ]]; then
  487. echo "$PKG_NAME already exists, skipping!"
  488. else
  489. echo "building $PKG_NAME..."
  490. splitName $PKG_NAME
  491. 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
  492. buildProduct $PKG_NAME
  493. fi
  494. }
  495. buildGrep() {
  496. PKG_NAME="grep-3.0"
  497. checkBuilt $PKG_NAME
  498. if [[ $? != 0 ]]; then
  499. echo "$PKG_NAME already exists, skipping!"
  500. else
  501. echo "building $PKG_NAME..."
  502. splitName $PKG_NAME
  503. 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
  504. buildProduct $PKG_NAME
  505. fi
  506. }
  507. patchCoreutils() {
  508. if [[ "$PLATFORM" == "AppleTVOS" ]]; then
  509. sed -i -- 's|#undef HAVE_CLOCK_GETTIME||' lib/config.hin
  510. sed -i -- 's|#undef HAVE_CLOCK_SETTIME||' lib/config.hin
  511. sed -i -- 's|#undef HAVE_FDATASYNC||' lib/config.hin
  512. sed -i -- 's|# define __stpncpy stpncpy||' lib/stpncpy.c
  513. if [[ ! -d "$SKEL_PREFIX/$ROOT_PREFIX/include" ]]; then
  514. mkdir -p "$SKEL_PREFIX/$ROOT_PREFIX/include"
  515. fi
  516. if [[ ! -e "$SKEL_PREFIX/$ROOT_PREFIX/include/crt_externs.h" ]]; then
  517. echo "#include <sys/cdefs.h>" >> "$SKEL_PREFIX/$ROOT_PREFIX/include/crt_externs.h"
  518. echo "" >> "$SKEL_PREFIX/$ROOT_PREFIX/include/crt_externs.h"
  519. echo "__BEGIN_DECLS" >> "$SKEL_PREFIX/$ROOT_PREFIX/include/crt_externs.h"
  520. echo "extern char ***_NSGetArgv(void);" >> "$SKEL_PREFIX/$ROOT_PREFIX/include/crt_externs.h"
  521. echo "extern int *_NSGetArgc(void);" >> "$SKEL_PREFIX/$ROOT_PREFIX/include/crt_externs.h"
  522. echo "extern char ***_NSGetEnviron(void);" >> "$SKEL_PREFIX/$ROOT_PREFIX/include/crt_externs.h"
  523. echo "extern char **_NSGetProgname(void);" >> "$SKEL_PREFIX/$ROOT_PREFIX/include/crt_externs.h"
  524. echo "extern struct mach_header *_NSGetMachExecuteHeader(void);" >> "$SKEL_PREFIX/$ROOT_PREFIX/include/crt_externs.h"
  525. echo "__END_DECLS" >> "$SKEL_PREFIX/$ROOT_PREFIX/include/crt_externs.h"
  526. fi
  527. fi
  528. }
  529. buildCoreutils() {
  530. PKG_NAME="coreutils-8.9"
  531. checkBuilt $PKG_NAME
  532. if [[ $? != 0 ]]; then
  533. echo "$PKG_NAME already exists, skipping!"
  534. else
  535. echo "building $PKG_NAME..."
  536. splitName $PKG_NAME
  537. 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
  538. patchCoreutils
  539. export HOST="arm"
  540. buildProduct $PKG_NAME
  541. export HOST="aarch64"
  542. fi
  543. }
  544. buildFindUtils() {
  545. PKG_NAME="findutils-4.6.0"
  546. checkBuilt $PKG_NAME
  547. if [[ $? != 0 ]]; then
  548. echo "$PKG_NAME already exists, skipping!"
  549. else
  550. echo "building $PKG_NAME..."
  551. splitName $PKG_NAME
  552. downloadProduct http://mirror.keystealth.org/gnu/findutils/findutils-4.6.0.tar.gz - $RAW_NAME $VERSION
  553. buildProduct $PKG_NAME
  554. fi
  555. }
  556. buildDiffUtils() {
  557. PKG_NAME="diffutils-3.6"
  558. checkBuilt $PKG_NAME
  559. if [[ $? != 0 ]]; then
  560. echo "$PKG_NAME already exists, skipping!"
  561. else
  562. echo "building $PKG_NAME..."
  563. splitName $PKG_NAME
  564. 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
  565. buildProduct $PKG_NAME
  566. fi
  567. }
  568. downloadDarwinTools() {
  569. if [[ ! -d DarwinToolsARM ]]; then
  570. echo "Fetching DarwinTools"
  571. mkdir -p DarwinToolsARM
  572. cd DarwinToolsARM
  573. curl -LO https://opensource.apple.com/source/DarwinTools/DarwinTools-1/sw_vers.c
  574. #Not built yet
  575. curl -LO https://opensource.apple.com/source/launchd/launchd-842.92.1/support/launchctl.c
  576. #sw_vers.c
  577. checkSHA256 sw_vers.c 55aab510b465f7687b8ebe23f0e51926606fd5316da138778838b2dac3e7c7e0
  578. else
  579. echo "Using existing DarwinTools"
  580. cd DarwinToolsARM
  581. fi
  582. WORKING_DIR="DarwinToolsARM"
  583. PKG_NAME="darwintools"
  584. PKG_VERSION="1.0-1"
  585. }
  586. patchDarwinTools() {
  587. if [[ "$PLATFORM" == "AppleTVOS" ]]; then
  588. sed -i -- 's|#include <CoreFoundation/CFPriv.h>|extern CFDictionaryRef _CFCopySystemVersionDictionary(void);\
  589. extern CFDictionaryRef _CFCopyServerVersionDictionary(void);|' sw_vers.c
  590. sed -i -- 's|_kCFSystemVersionProductNameKey|CFSTR(\"ProductName\")|g' sw_vers.c
  591. sed -i -- 's|_kCFSystemVersionProductVersionKey|CFSTR(\"ProductVersion\")|g' sw_vers.c
  592. sed -i -- 's|_kCFSystemVersionBuildVersionKey|CFSTR(\"ProductBuildVersion\")|g' sw_vers.c
  593. fi
  594. }
  595. #darwintools
  596. #Notes:
  597. # This only builds a striped down version of the one on iOS
  598. # If you're building for a non-appletv platform, you may need to fix things here.
  599. buildDarwinTools() {
  600. downloadDarwinTools
  601. patchDarwinTools
  602. "$CLANG_PATH" -arch "$ARCH" -isysroot"$SDK_PATH" -framework CoreFoundation "$MIN_VERSION" -o "sw_vers" sw_vers.c
  603. #codesign "$BUILD_ROOT/$WORKING_DIR/sw_vers"
  604. cp sw_vers "$SKEL_PREFIX/$ROOT_PREFIX/bin/"
  605. cd "$BUILD_ROOT"
  606. }
  607. #Download uikittools
  608. downloadUIKitTools() {
  609. if [[ ! -d uikittools ]]; then
  610. echo "Fetching uikittools"
  611. git clone git://git.saurik.com/uikittools.git
  612. else
  613. echo "Using existing uikittools"
  614. fi
  615. WORKING_DIR="uikittools"
  616. PKG_NAME="uikittools"
  617. PKG_VERSION="1.1.12-1"
  618. cd "$WORKING_DIR"
  619. git checkout tags/v1.1.12
  620. }
  621. #uikittools
  622. #Notes:
  623. # This only builds a striped down version of the one on iOS
  624. # If you're building for a non-appletv platform, you may need to fix things here.
  625. buildUIKitTools() {
  626. downloadUIKitTools
  627. "$CLANGPLUS_PATH" -arch "$ARCH" -isysroot"$SDK_PATH" -Os -Werror -framework CoreFoundation -framework Foundation "$MIN_VERSION" -o cfversion cfversion.mm
  628. "$CLANGPLUS_PATH" -arch "$ARCH" -isysroot"$SDK_PATH" -Os -Werror -framework CoreFoundation -framework Foundation "$MIN_VERSION" -o gssc gssc.mm
  629. "$CLANGPLUS_PATH" -arch "$ARCH" -isysroot"$SDK_PATH" -Os -Werror -framework CoreFoundation -framework Foundation -framework UIKit "$MIN_VERSION" -o uiduid uiduid.mm
  630. #odesign "$BUILD_ROOT/$WORKING_DIR/cfversion"
  631. #codesign "$BUILD_ROOT/$WORKING_DIR/gssc"
  632. #codesign "$BUILD_ROOT/$WORKING_DIR/uiduid"
  633. cp gssc cfversion uiduid "$SKEL_PREFIX/$ROOT_PREFIX/bin/"
  634. cd "$BUILD_ROOT"
  635. }
  636. buildBasicUtils() {
  637. notifyProgress "Building sed"
  638. buildSed
  639. notifyProgress "Building grep"
  640. buildGrep
  641. notifyProgress "Building coreutils"
  642. buildCoreutils
  643. notifyProgress "Building findutils"
  644. buildFindUtils
  645. notifyProgress "Building diffutils"
  646. buildDiffUtils
  647. notifyProgress "Building DarwinTools"
  648. buildDarwinTools
  649. notifyProgress "Building UIKitTools"
  650. buildUIKitTools
  651. }
  652. mkdirIfNecessary() {
  653. MK_DIR="$1"
  654. if [[ ! -d $MK_DIR ]]; then
  655. mkdir -p $MK_DIR
  656. fi
  657. }
  658. removeIfNecessary() {
  659. REMOVE_FILE="$1"
  660. if [[ -f $REMOVE_FILE ]]; then
  661. rm -rf $REMOVE_FILE
  662. fi
  663. }
  664. #=====================
  665. #DPKG and Dependencies
  666. #---------------------
  667. #Download zlib
  668. downloadZLib() {
  669. #Download zlib
  670. if [[ ! -d zlib ]]; then
  671. echo "Downloading zlib git"
  672. git clone https://github.com/madler/zlib.git
  673. else
  674. echo "Using existing zlib"
  675. fi
  676. WORKING_DIR="zlib"
  677. PKG_NAME="zlib"
  678. PKG_VERSION="1.2.11-1"
  679. cd "$WORKING_DIR"
  680. git checkout tags/v1.2.11
  681. removeIfNecessary build
  682. mkdirIfNecessary build
  683. cd build
  684. WORKING_DIR="$WORKING_DIR/build"
  685. }
  686. #zlib
  687. buildZLib() {
  688. PKG_NAME="lzib-1.2.11"
  689. checkBuilt $PKG_NAME
  690. if [[ $? != 0 ]]; then
  691. echo "$PKG_NAME already exists, skipping!"
  692. else
  693. downloadZLib
  694. cmake -DCMAKE_INSTALL_NAME_DIR="/$ROOT_PREFIX/lib" -DCMAKE_OSX_SYSROOT="$SDK_PATH/" -DCMAKE_C_FLAGS="-arch $ARCH" -DCMAKE_INSTALL_PREFIX="/$ROOT_PREFIX" ..
  695. checkStatus $PKG_NAME $? "false"
  696. make -j8 DESTDIR="$SKEL_PREFIX" install
  697. checkStatus $PKG_NAME $? "true"
  698. cd "$BUILD_ROOT"
  699. fi
  700. }
  701. patchXZ() {
  702. if [[ "$PLATFORM" == "AppleTVOS" ]]; then
  703. sed -i -- 's|#undef HAVE_CLOCK_GETTIME||' config.h.in
  704. fi
  705. }
  706. patchTar() {
  707. if [[ "$PLATFORM" == "AppleTVOS" ]]; then
  708. sed -i -- 's|#undef HAVE_CLOCK_GETTIME||' config.h.in
  709. fi
  710. }
  711. patchOpenSSL() {
  712. sed -i -- "s|-arch $ARCH -mios-version-min=7.0.0|-arch $ARCH $MIN_VERSION|" Configurations/10-main.conf
  713. }
  714. patchBZip2() {
  715. if [[ "$PLATFORM" == "AppleTVOS" ]]; then
  716. #fix up our makefile...
  717. sed -i -- 's|CC=gcc|CC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang|' Makefile
  718. sed -i -- 's|AR=ar|AR=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar|' Makefile
  719. sed -i -- 's|RANLIB=ranlib|RANLIB=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib|' Makefile
  720. sed -i -- "s|LDFLAGS=|LDFLAGS=$MIN_VERSION -isysroot \"$SDK_PATH\" -arch $ARCH|" Makefile
  721. sed -i -- "s|CFLAGS=|CFLAGS=$MIN_VERSION -isysroot \"$SDK_PATH\" -arch $ARCH |" Makefile
  722. sed -i -- 's|all:\(.*\) test$|all: \1|' Makefile
  723. sed -i -- 's|ln -s -f \$(PREFIX)/bin/|ln -s -f |g' Makefile
  724. fi
  725. }
  726. patchCurl() {
  727. if [[ "$PLATFORM" == "AppleTVOS" ]]; then
  728. #(Forcibly) Remove that dirty clock_gettime
  729. #TODO: Determine if this is the best way
  730. sed -i -- 's|#undef HAVE_CLOCK_GETTIME_MONOTONIC||' lib/curl_config.h.in
  731. fi
  732. }
  733. buildXZ() {
  734. PKG_NAME="xz-5.2.3"
  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://tukaani.org/xz/xz-5.2.3.tar.gz http://tukaani.org/xz/xz-5.2.3.tar.gz.sig $RAW_NAME $VERSION
  742. patchXZ
  743. buildProduct $PKG_NAME
  744. fi
  745. }
  746. buildBZip2() {
  747. PKG_NAME="bzip2-1.0.6"
  748. checkBuilt $PKG_NAME
  749. if [[ $? != 0 ]]; then
  750. echo "$PKG_NAME already exists, skipping!"
  751. else
  752. echo "building $PKG_NAME..."
  753. splitName $PKG_NAME
  754. downloadProduct https://gigenet.dl.sourceforge.net/project/bzip2/bzip2-1.0.6.tar.gz - $RAW_NAME $VERSION
  755. patchBZip2
  756. make -j8 install PREFIX="$SKEL_PREFIX/$ROOT_PREFIX"
  757. checkStatus $PKG_NAME $? "true"
  758. cd "$BUILD_ROOT"
  759. fi
  760. }
  761. buildLZ4() {
  762. PKG_NAME="lz4-1.7.5"
  763. checkBuilt $PKG_NAME
  764. if [[ $? != 0 ]]; then
  765. echo "$PKG_NAME already exists, skipping!"
  766. else
  767. echo "building $PKG_NAME..."
  768. splitName $PKG_NAME
  769. downloadProduct https://github.com/lz4/lz4/archive/v1.7.5.tar.gz - $RAW_NAME $VERSION
  770. cd contrib/cmake_unofficial/
  771. mkdirIfNecessary build
  772. cd build
  773. cmake -DCMAKE_INSTALL_NAME_DIR="/$ROOT_PREFIX/lib" -DCMAKE_OSX_SYSROOT="$SDK_PATH/" -DCMAKE_C_FLAGS="-arch $ARCH" -DCMAKE_INSTALL_PREFIX="/$ROOT_PREFIX" ..
  774. checkStatus $PKG_NAME $? "false"
  775. make -j8
  776. make -j8 DESTDIR="$SKEL_PREFIX" install
  777. checkStatus $PKG_NAME $? "true"
  778. cd "$BUILD_ROOT"
  779. fi
  780. }
  781. downloadOpenSSL() {
  782. if [[ ! -d openssl ]]; then
  783. git clone -b OpenSSL_1_1_0-stable https://github.com/openssl/openssl.git
  784. else
  785. echo "Using existing openssl repo"
  786. fi
  787. WORKING_DIR="openssl"
  788. PKG_NAME="openssl"
  789. PKG_VERSION="1.1.0-1"
  790. cd "$WORKING_DIR"
  791. }
  792. buildOpenSSL() {
  793. PKG_NAME="openssl"
  794. checkBuilt $PKG_NAME
  795. if [[ $? != 0 ]]; then
  796. echo "$PKG_NAME already exists, skipping!"
  797. else
  798. LOG_FILE="$ROOT_LOG_FOLDER/openssl.log"
  799. touch $LOG_FILE
  800. downloadOpenSSL
  801. patchOpenSSL
  802. export AR=""
  803. export PLATFORM="$PLATFORM"
  804. export BUILD_TOOLS="$(xcode-select --print-path)"
  805. export CC="clang -fembed-bitcode"
  806. export CROSS_COMPILE="$(xcode-select --print-path)/Toolchains/XcodeDefault.xctoolchain/usr/bin/"
  807. export CROSS_TOP="$(xcode-select --print-path)/Platforms/$PLATFORM.platform/Developer"
  808. export CROSS_SDK="$(echo $SDK_PATH | sed 's/.*\///g')"
  809. sayIfVerbal "Configuring openSSL"
  810. if [[ $LOG_VERBOSE == "verbose"* ]]; then
  811. ./Configure ios64-cross no-dso no-hw no-engine --prefix="/$ROOT_PREFIX" | tee "${LOG_FILE}"
  812. else
  813. (./Configure ios64-cross no-dso no-hw no-engine --prefix="/$ROOT_PREFIX" > "$LOG_FILE" 2>&1)
  814. fi
  815. checkStatus $PKG_NAME $? "false"
  816. echo -e "\n\nPOST CONFIGURE\n\n" >> "$LOG_FILE"
  817. sayIfVerbal "making openSSL"
  818. if [[ $LOG_VERBOSE == "verbose"* ]]; then
  819. make DESTDIR="$SKEL_PREFIX" install | tee -a "${LOG_FILE}"
  820. else
  821. (make DESTDIR="$SKEL_PREFIX" install >> "${LOG_FILE}" 2>&1)
  822. fi
  823. checkStatus $PKG_NAME $? "true"
  824. cd "$BUILD_ROOT"
  825. fi
  826. }
  827. buildCurl() {
  828. PKG_NAME="curl-7.50.1"
  829. checkBuilt $PKG_NAME
  830. if [[ $? != 0 ]]; then
  831. echo "$PKG_NAME already exists, skipping!"
  832. else
  833. echo "building $PKG_NAME..."
  834. splitName $PKG_NAME
  835. downloadProduct https://curl.haxx.se/download/curl-7.50.1.tar.gz - $RAW_NAME $VERSION
  836. patchCurl
  837. buildProduct $PKG_NAME
  838. fi
  839. }
  840. patchBerkeleyDB() {
  841. if [[ "$PLATFORM" == "AppleTVOS" ]]; then
  842. sed -i -- 's|#undef HAVE_CLOCK_GETTIME||' ../dist/config.hin
  843. #if [[ "$PKG_VERSION" == "6.2.23-1" ]]; then
  844. cat ../lang/sql/sqlite/src/shell.c | head -n 14 > shell.patched.c
  845. echo "#include <stdint.h>" >> shell.patched.c
  846. echo "#include <stdio.h>" >> shell.patched.c
  847. echo "#include <stdlib.h>" >> shell.patched.c
  848. echo "#include <spawn.h>" >> shell.patched.c
  849. echo "#include <sys/wait.h>" >> shell.patched.c
  850. echo "#include <sys/stat.h>" >> shell.patched.c
  851. echo "" >> shell.patched.c
  852. echo "extern char **environ;" >> shell.patched.c
  853. echo "" >> shell.patched.c
  854. cat ../lang/sql/sqlite/src/shell.c | tail -n 4847 | head -n 2622 >> shell.patched.c
  855. fixSystem "shell.patched.c"
  856. cat ../lang/sql/sqlite/src/shell.c | tail -n 2226 | sed 's/system(zCmd)/RunCmd(zCmd)/g' >> shell.patched.c
  857. cp shell.patched.c ../lang/sql/sqlite/src/shell.c
  858. #fi
  859. fi
  860. }
  861. buildBerkeleyDB() {
  862. PKG_NAME="db-6.2.23"
  863. checkBuilt $PKG_NAME
  864. if [[ $? != 0 ]]; then
  865. echo "$PKG_NAME already exists, skipping!"
  866. else
  867. echo "building $PKG_NAME..."
  868. LOG_FILE="$ROOT_LOG_FOLDER/$PKG_NAME.log"
  869. touch $LOG_FILE
  870. splitName $PKG_NAME
  871. DOWNLOAD_URL="http://download.oracle.com/berkeley-db/db-6.2.23.tar.gz"
  872. downloadProduct $DOWNLOAD_URL - $RAW_NAME $VERSION
  873. cd build_unix
  874. patchBerkeleyDB
  875. export CPP=""
  876. export CXXCPP=""
  877. export PLATFORM="$PLATFORM" #TODO: Maybe necessary? Need to test.
  878. export BUILD_TOOLS="$(xcode-select --print-path)"
  879. export CC="clang"
  880. export CROSS_COMPILE="$(xcode-select --print-path)/Toolchains/XcodeDefault.xctoolchain/usr/bin/"
  881. export CROSS_TOP="$(xcode-select --print-path)/Platforms/$PLATFORM.platform/Developer"
  882. export CROSS_SDK="$(echo $SDK_PATH | sed 's/.*\///g')"
  883. export CFLAGS="-arch $ARCH -pipe -Os -gdwarf-2 -isysroot $SDK_PATH $MIN_VERSION"
  884. export CXXFLAGS="-arch $ARCH -pipe -Os -gdwarf-2 -isysroot $SDK_PATH $MIN_VERSION"
  885. export LDFLAGS="-arch $ARCH -isysroot $SDK_PATH" # -L${SKEL_PREFIX}/lib"
  886. #buildProduct $PKG_NAME
  887. if [[ $LOG_VERBOSE == "verbose"* ]]; then
  888. ../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}"
  889. else
  890. (../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)
  891. fi
  892. checkStatus $PKG_NAME $? "false"
  893. make DESTDIR="$SKEL_PREFIX" install
  894. checkStatus $PKG_NAME $? "true"
  895. fi
  896. }
  897. buildTar(){
  898. PKG_NAME="tar-1.33"
  899. checkBuilt $PKG_NAME
  900. if [[ $? != 0 ]]; then
  901. echo "$PKG_NAME already exists, skipping!"
  902. else
  903. echo "building $PKG_NAME..."
  904. splitName $PKG_NAME
  905. downloadProduct http://ftp.gnu.org/gnu/tar/tar-1.33.tar.xz - $RAW_NAME $VERSION
  906. patchTar
  907. buildProduct $PKG_NAME
  908. fi
  909. }
  910. #Download dpkg
  911. downloadDpkg() {
  912. if [[ ! -d dpkg ]]; then
  913. echo "Downlading dpkg"
  914. git clone https://git.nito.tv/NitoTV/dpkg.git
  915. else
  916. echo "Using existing dpkg"
  917. fi
  918. WORKING_DIR="dpkg"
  919. PKG_NAME="dpkg"
  920. PKG_VERSION="1.18.23-1" #FIXME
  921. cd "$WORKING_DIR"
  922. }
  923. #dpkg
  924. buildDpkg() {
  925. downloadDpkg
  926. PKG_NAME="dpkg-1.18.23"
  927. checkBuilt $PKG_NAME
  928. LOG_FILE="$ROOT_LOG_FOLDER/$PKG_NAME.log"
  929. touch $LOG_FILE
  930. if [[ $? != 0 ]]; then
  931. echo "$PKG_NAME already exists, skipping!"
  932. else
  933. local dont_die_here=$(./autogen.sh)
  934. # need to clear these preprocessor flags or they get all wonky
  935. export CPP=""
  936. export CXXCPP=""
  937. export LZMA_LIBS="$SKEL_PREFIX/$ROOT_PREFIX/lib/liblzma.dylib"
  938. export CC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
  939. export CXX=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++
  940. export CFLAGS="-isysroot $SDK_PATH -I$SDK_PATH/usr/include -I$SKEL_PREFIX/$ROOT_PREFIX/include/ -arch $ARCH"
  941. export CXXFLAGS=$CFLAGS
  942. export LDFLAGS="-isysroot $SDK_PATH -L$SKEL_PREFIX/$ROOT_PREFIX/lib/ -arch $ARCH"
  943. export CPPFLAGS="-isysroot $SDK_PATH -I$SKEL_PREFIX/$ROOT_PREFIX/include/ -arch $ARCH"
  944. export CXXFLAGS=$CFLAGS
  945. export LDFLAGS="-isysroot $SDK_PATH -L$SKEL_PREFIX/$ROOT_PREFIX/lib/ -arch $ARCH"
  946. if [[ $LOG_VERBOSE == "verbose"* ]]; then
  947. ./configure --prefix="/$ROOT_PREFIX" --disable-start-stop-daemon --host=aarch64-apple-darwin --disable-dependency-tracking PERL_LIBDIR='$(prefix)/lib/' --disable-dselect --localstatedir="/var/" --sysconfdir="/etc" | tee "${LOG_FILE}"
  948. else
  949. (./configure --prefix="/$ROOT_PREFIX" --disable-start-stop-daemon --host=aarch64-apple-darwin --disable-dependency-tracking PERL_LIBDIR='$(prefix)/lib/' --disable-dselect --localstatedir="/var/" --sysconfdir="/etc" > "${LOG_FILE}" 2>&1)
  950. fi
  951. checkStatus $PKG_NAME $? "false"
  952. patchDpkg #Must be after configure for now. I'll deal with this later
  953. if [[ $LOG_VERBOSE == "verbose"* ]]; then
  954. make -j8 DESTDIR="$SKEL_PREFIX" install | tee "${LOG_FILE}"
  955. else
  956. (make -j8 DESTDIR="$SKEL_PREFIX" install > "${LOG_FILE}" 2>&1)
  957. fi
  958. checkStatus $PKG_NAME $? "true"
  959. #lzma conflicts with built in libraries when running in certian conditions.
  960. #we make -j8 a symlink our version of lzma in the xz build process
  961. #here we change dpkg-deb to look for this version instead
  962. #if we do not do this, apt-get/dpkg* will fail from our setuid tool
  963. install_name_tool -change /usr/lib/liblzma.5.dylib /usr/local/lib/liblzma.5.dylib "$SKEL_PREFIX/$ROOT_PREFIX/bin/dpkg-deb"
  964. echo "appletvos-arm64" >> "$BUILD_ROOT/dpkg/deb/var/lib/dpkg/arch"
  965. echo "darwin-arm64" >> "$BUILD_ROOT/dpkg/deb/var/lib/dpkg/arch"
  966. #Get rid of cross-compile artifacts
  967. sed -i -- "s|$SKEL_PREFIX||g" "$BUILD_ROOT/$WORKING_DIR/deb/$ROOT_PREFIX/lib/libdpkg.la"
  968. sed -i -- "s|$SKEL_PREFIX||g" "$BUILD_ROOT/$WORKING_DIR/deb/$ROOT_PREFIX/lib/pkgconfig/libdpkg.pc"
  969. rm -rf "$BUILD_ROOT/$WORKING_DIR/deb/$ROOT_PREFIX/lib/libdpkg.la--"
  970. rm -rf "$BUILD_ROOT/$WORKING_DIR/deb/$ROOT_PREFIX/lib/pkgconfig/libdpkg.pc--"
  971. cd "$BUILD_ROOT"
  972. fi
  973. }
  974. buildDPKGAndDependencies() {
  975. notifyProgress "Building zlib"
  976. buildZLib
  977. notifyProgress "Building xz"
  978. buildXZ
  979. notifyProgress "Building bzip2"
  980. buildBZip2
  981. notifyProgress "Building lz4"
  982. buildLZ4
  983. notifyProgress "Building openSSL"
  984. buildOpenSSL
  985. notifyProgress "Building curl"
  986. buildCurl
  987. notifyProgress "Building BerkeleyDB"
  988. buildBerkeleyDB
  989. notifyProgress "Building tar"
  990. buildTar
  991. notifyProgress "Building dpkg"
  992. buildDpkg
  993. }
  994. buildGpgError() {
  995. PKG_NAME="libgpg-error-1.32"
  996. checkBuilt $PKG_NAME
  997. if [[ $? != 0 ]]; then
  998. echo "$PKG_NAME already exists, skipping!"
  999. else
  1000. echo "building $PKG_NAME..."
  1001. #splitName $PKG_NAME
  1002. DOWNLOAD_URL="https://www.gnupg.org/ftp/gcrypt/libgpg-error/libgpg-error-1.32.tar.bz2"
  1003. downloadProduct $DOWNLOAD_URL $DOWNLOAD_URL.sig libgpg-error 1.32
  1004. #sed -i -- 's|#include <stdlib.h>|\n#if !defined(__arm64__)\n#define __arm64__\n#endif\n\n#include <stdlib.h>|' ncurses/build.priv.h
  1005. #echo -e "\n#if !defined(__arm64__)\n#define __arm64__\n#endif\n\n" >> config.h.in
  1006. export HOST="arm"
  1007. buildProduct $PKG_NAME "--enable-threads=posix"
  1008. export HOST="aarch64"
  1009. fi
  1010. }
  1011. patchGcrypt() {
  1012. if [[ "$PLATFORM" == "AppleTVOS" ]]; then
  1013. #if [[ "$PKG_VERSION" == "1.8.2-1" ]]; then
  1014. cat tests/random.c | head -n 39 > random.patched.c
  1015. echo "#include <stdint.h>" >> random.patched.c
  1016. echo "#include <stdio.h>" >> random.patched.c
  1017. echo "#include <stdlib.h>" >> random.patched.c
  1018. echo "#include <spawn.h>" >> random.patched.c
  1019. echo "#include <sys/wait.h>" >> random.patched.c
  1020. echo "#include <sys/stat.h>" >> random.patched.c
  1021. echo "" >> random.patched.c
  1022. echo "extern char **environ;" >> random.patched.c
  1023. echo "" >> random.patched.c
  1024. fixSystem "random.patched.c"
  1025. cat tests/random.c | tail -n 727 | sed 's/system (cmdline)/RunCmd(cmdline)/g' >> random.patched.c
  1026. cp random.patched.c tests/random.c
  1027. #fi
  1028. fi
  1029. }
  1030. buildGcrypt() {
  1031. PKG_NAME="libgcrypt-1.8.2"
  1032. checkBuilt $PKG_NAME
  1033. if [[ $? != 0 ]]; then
  1034. echo "$PKG_NAME already exists, skipping!"
  1035. else
  1036. echo "building $PKG_NAME..."
  1037. splitName $PKG_NAME
  1038. 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
  1039. patchGcrypt
  1040. export HOST="arm"
  1041. buildProduct $PKG_NAME "--with-libgpg-error-prefix=$SKEL_PREFIX/$ROOT_PREFIX/"
  1042. export HOST="aarch64"
  1043. fi
  1044. }
  1045. buildKSBA() {
  1046. PKG_NAME="libksba-1.3.5"
  1047. checkBuilt $PKG_NAME
  1048. if [[ $? != 0 ]]; then
  1049. echo "$PKG_NAME already exists, skipping!"
  1050. else
  1051. echo "building $PKG_NAME..."
  1052. splitName $PKG_NAME
  1053. DOWNLOAD_URL="https://www.gnupg.org/ftp/gcrypt/libksba/libksba-1.3.5.tar.bz2"
  1054. downloadProduct $DOWNLOAD_URL $DOWNLOAD_URL.sig $RAW_NAME $VERSION
  1055. buildProduct $PKG_NAME "--with-libgpg-error-prefix=$SKEL_PREFIX/$ROOT_PREFIX/"
  1056. fi
  1057. }
  1058. patchNpth() {
  1059. if [[ "$PLATFORM" == "AppleTVOS" ]]; then
  1060. sed -i -- 's|#undef HAVE_CLOCK_GETTIME||' config.h.in
  1061. #if [[ "$PKG_VERSION" == "1.5-1" ]]; then
  1062. cat src/npth.c | head -n 19 > npth.patched.c
  1063. echo "#include <stdint.h>" >> npth.patched.c
  1064. echo "#include <stdio.h>" >> npth.patched.c
  1065. echo "#include <stdlib.h>" >> npth.patched.c
  1066. echo "#include <spawn.h>" >> npth.patched.c
  1067. echo "#include <sys/wait.h>" >> npth.patched.c
  1068. echo "" >> npth.patched.c
  1069. echo "extern char **environ;" >> npth.patched.c
  1070. echo "" >> npth.patched.c
  1071. cat src/npth.c | tail -n 757 | head -n 537 >> npth.patched.c
  1072. fixSystem "npth.patched.c"
  1073. cat src/npth.c | tail -n 220 | sed 's/system(cmd)/RunCmd(cmd)/g' >> npth.patched.c
  1074. cp npth.patched.c src/npth.c
  1075. #fi
  1076. fi
  1077. }
  1078. buildNpth() {
  1079. PKG_NAME="npth-1.5"
  1080. checkBuilt $PKG_NAME
  1081. if [[ $? != 0 ]]; then
  1082. echo "$PKG_NAME already exists, skipping!"
  1083. else
  1084. echo "building $PKG_NAME..."
  1085. splitName $PKG_NAME
  1086. DOWNLOAD_URL="https://www.gnupg.org/ftp/gcrypt/npth/npth-1.5.tar.bz2"
  1087. downloadProduct $DOWNLOAD_URL $DOWNLOAD_URL.sig $RAW_NAME $VERSION
  1088. patchNpth
  1089. buildProduct $PKG_NAME
  1090. fi
  1091. }
  1092. #https://www.gnupg.org/ftp/gcrypt/libassuan/libassuan-2.5.1.tar.bz2
  1093. buildAssuan() {
  1094. PKG_NAME="libassuan-2.5.1"
  1095. checkBuilt $PKG_NAME
  1096. if [[ $? != 0 ]]; then
  1097. echo "$PKG_NAME already exists, skipping!"
  1098. else
  1099. echo "building $PKG_NAME..."
  1100. splitName $PKG_NAME
  1101. DOWNLOAD_URL="https://www.gnupg.org/ftp/gcrypt/libassuan/libassuan-2.5.1.tar.bz2"
  1102. downloadProduct $DOWNLOAD_URL $DOWNLOAD_URL.sig $RAW_NAME $VERSION
  1103. buildProduct $PKG_NAME "--with-libgpg-error-prefix=$SKEL_PREFIX/$ROOT_PREFIX/"
  1104. fi
  1105. }
  1106. patchNtbtls() {
  1107. if [[ "$PLATFORM" == "AppleTVOS" ]]; then
  1108. # this is required because prior dependencies write /$ROOT_PREFIX/lib/libgpg-error.la as a dependency in the .la file
  1109. 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"
  1110. 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"
  1111. rm -f "$SKEL_PREFIX/$ROOT_PREFIX/lib/libgcrypt.la--"
  1112. rm -f "$SKEL_PREFIX/$ROOT_PREFIX/lib/libksba.la--"
  1113. fi
  1114. }
  1115. buildNtbtls() {
  1116. PKG_NAME="ntbtls-0.1.2"
  1117. checkBuilt $PKG_NAME
  1118. if [[ $? != 0 ]]; then
  1119. echo "$PKG_NAME already exists, skipping!"
  1120. else
  1121. echo "building $PKG_NAME..."
  1122. splitName $PKG_NAME
  1123. DOWNLOAD_URL="https://www.gnupg.org/ftp/gcrypt/ntbtls/ntbtls-0.1.2.tar.bz2"
  1124. downloadProduct $DOWNLOAD_URL $DOWNLOAD_URL.sig $RAW_NAME $VERSION
  1125. patchNtbtls
  1126. 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"
  1127. fi
  1128. }
  1129. patchGpg() {
  1130. if [[ "$PLATFORM" == "AppleTVOS" ]]; then
  1131. #if [[ "$PKG_VERSION" == "2.2.3-1" ]]; then
  1132. cat "g10/exec.c" | head -n 54 > "exec.patched.c"
  1133. echo "#include <stdint.h>" >> "exec.patched.c"
  1134. echo "#include <stdio.h>" >> "exec.patched.c"
  1135. echo "#include <stdlib.h>" >> "exec.patched.c"
  1136. echo "#include <spawn.h>" >> "exec.patched.c"
  1137. echo "#include <sys/wait.h>" >> "exec.patched.c"
  1138. echo "" >> "exec.patched.c"
  1139. echo "extern char **environ;" >> "exec.patched.c"
  1140. echo "" >> "exec.patched.c"
  1141. cat "g10/exec.c" | head -n 111 | tail -n 57 >> "exec.patched.c"
  1142. fixSystem "exec.patched.c"
  1143. cat "g10/exec.c" | tail -n 524 | sed 's/=system(info->command)/=RunCmd(info->command)/g' >> "exec.patched.c"
  1144. cp "exec.patched.c" "g10/exec.c"
  1145. #fi
  1146. fi
  1147. }
  1148. #
  1149. buildGpg() {
  1150. PKG_NAME="gnupg-2.2.3"
  1151. checkBuilt $PKG_NAME
  1152. if [[ $? != 0 ]]; then
  1153. echo "$PKG_NAME already exists, skipping!"
  1154. else
  1155. echo "building $PKG_NAME..."
  1156. splitName $PKG_NAME
  1157. DOWNLOAD_URL="https://www.gnupg.org/ftp/gcrypt/gnupg/gnupg-2.2.3.tar.bz2"
  1158. downloadProduct $DOWNLOAD_URL $DOWNLOAD_URL.sig $RAW_NAME $VERSION
  1159. patchGpg
  1160. 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/"
  1161. fi
  1162. }
  1163. patchAPT() {
  1164. if [[ "$PLATFORM" == "AppleTVOS" ]]; then
  1165. sed -i -- '/^INCLUDE_DIRECTORIES/d' ../CMakeLists.txt
  1166. sed -i -- '/^LINK_DIRECTORIES/d' ../CMakeLists.txt
  1167. cat ../CMakeLists.txt | head -n 15 > newCmakeLists.txt
  1168. echo "INCLUDE_DIRECTORIES($SKEL_PREFIX/$ROOT_PREFIX/include)" >> newCmakeLists.txt
  1169. echo "LINK_DIRECTORIES($SKEL_PREFIX/$ROOT_PREFIX/lib)" >> newCmakeLists.txt
  1170. echo "" >> newCmakeLists.txt
  1171. cat ../CMakeLists.txt | tail -n 217 >> newCmakeLists.txt
  1172. mv newCmakeLists.txt ../CmakeLists.txt
  1173. #sed -i -- "s|/Users/jaywalker/RnD/ATV/packages/test/skel/|$SKEL_PREFIX/|g" ../CMakeLists.txt
  1174. fi
  1175. }
  1176. downloadApt() {
  1177. if [[ ! -d apt ]]; then
  1178. echo "Downlading apt"
  1179. git clone https://git.nito.tv/NitoTV/apt.git
  1180. else
  1181. echo "Using existing apt"
  1182. fi
  1183. WORKING_DIR="apt"
  1184. PKG_NAME="apt7"
  1185. PKG_VERSION="0.7.25.3-1"
  1186. cd "$WORKING_DIR"
  1187. removeIfNecessary build
  1188. mkdirIfNecessary build
  1189. cd build
  1190. WORKING_DIR="$WORKING_DIR/build"
  1191. }
  1192. buildAPT() {
  1193. downloadApt
  1194. patchAPT
  1195. 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" ..
  1196. sed -i -- "s|#define COMMON_ARCH \"darwin-amd64\"|#define COMMON_ARCH \"$PLATFORM_LOWER-$ARCH\"|" include/config.h
  1197. make -j8 DESTDIR="$SKEL_PREFIX" install
  1198. #lzma conflicts with built in libraries we make -j8 an extra copy of our version of lzma in the xz build process
  1199. #here we change libapt-pkg*.dylib to look for this version instead
  1200. #if we do not do this, apt-get will fail from our helper tool
  1201. 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
  1202. cd "$BUILD_ROOT"
  1203. }
  1204. buildAPTAndDependencies() {
  1205. notifyProgress "Building gpg-error"
  1206. buildGpgError
  1207. notifyProgress "Building gcrypt"
  1208. buildGcrypt
  1209. notifyProgress "Building KSBA"
  1210. buildKSBA
  1211. notifyProgress "Building npth"
  1212. buildNpth
  1213. notifyProgress "Building Assuan"
  1214. buildAssuan
  1215. notifyProgress "Building ntbtls"
  1216. buildNtbtls
  1217. notifyProgress "Building gpg"
  1218. buildGpg
  1219. notifyProgress "Building apt"
  1220. buildAPT
  1221. }
  1222. prepSDK() {
  1223. if [[ ! -e "$SDK_PATH/usr/include/sys/ttydev.h" ]]; then
  1224. echo "Missing <sys/ttydev.h>. Moving it in from MacOSX SDK (with sudo)"
  1225. sudo cp "$(xcrun --sdk macosx --show-sdk-path)/usr/include/sys/ttydev.h" "$SDK_PATH/usr/include/sys/ttydev.h"
  1226. fi
  1227. if [[ ! -e "$SDK_PATH/usr/include/lockdown.h" ]]; then
  1228. echo "Missing lockdown.h! Generating the bare essentials for apt to build..."
  1229. echo "#ifndef LOCKDOWN_LOCKDOWN_H" >> "$SDK_PATH/usr/include/lockdown.h"
  1230. echo "#define LOCKDOWN_LOCKDOWN_H" >> "$SDK_PATH/usr/include/lockdown.h"
  1231. echo "" >> "$SDK_PATH/usr/include/lockdown.h"
  1232. echo "#include <CoreFoundation/CFString.h>" >> "$SDK_PATH/usr/include/lockdown.h"
  1233. echo "" >> "$SDK_PATH/usr/include/lockdown.h"
  1234. echo "#ifdef __cplusplus" >> "$SDK_PATH/usr/include/lockdown.h"
  1235. echo "extern \"C\" {" >> "$SDK_PATH/usr/include/lockdown.h"
  1236. echo "#endif" >> "$SDK_PATH/usr/include/lockdown.h"
  1237. echo "" >> "$SDK_PATH/usr/include/lockdown.h"
  1238. echo "extern CFStringRef kLockdownUniqueDeviceIDKey;" >> "$SDK_PATH/usr/include/lockdown.h"
  1239. echo "" >> "$SDK_PATH/usr/include/lockdown.h"
  1240. echo "extern void *lockdown_connect(void);" >> "$SDK_PATH/usr/include/lockdown.h"
  1241. echo "extern CFStringRef lockdown_copy_value(void *lockdown, void *null, CFStringRef key);" >> "$SDK_PATH/usr/include/lockdown.h"
  1242. echo "extern void lockdown_disconnect(void *lockdown);" >> "$SDK_PATH/usr/include/lockdown.h"
  1243. echo "" >> "$SDK_PATH/usr/include/lockdown.h"
  1244. echo "#ifdef __cplusplus" >> "$SDK_PATH/usr/include/lockdown.h"
  1245. echo "}" >> "$SDK_PATH/usr/include/lockdown.h"
  1246. echo "#endif" >> "$SDK_PATH/usr/include/lockdown.h"
  1247. echo "" >> "$SDK_PATH/usr/include/lockdown.h"
  1248. echo "#endif/*LOCKDOWN_LOCKDOWN_H*/" >> "$SDK_PATH/usr/include/lockdown.h"
  1249. fi
  1250. IOKIT_MATCH="`find ~/Library/Developer/Xcode/tvOS\ DeviceSupport/ -name IOKit.framework | grep "$SDK_VERSION" -m 1`"
  1251. echo "IOKit match: $IOKIT_MATCH"
  1252. echo "IOKit: $SDK_PATH/System/Library/Frameworks/IOKit.framework"
  1253. if [[ ! -d "$SDK_PATH/System/Library/Frameworks/IOKit.framework" ]]; then
  1254. if [[ ! -z "$IOKIT_MATCH" ]]; then
  1255. echo "we do indeed have an IOKit match and IOKit is missing!!"
  1256. echo "cp -r $IOKIT_MATCH $SDK_PATH/System/Library/Frameworks/"
  1257. cp -r "$IOKIT_MATCH" "$SDK_PATH/System/Library/Frameworks/"
  1258. fi
  1259. fi
  1260. # patch fork to be available in tvOS
  1261. sed -i -- "s|__TVOS_PROHIBITED| |" $SDK_PATH/usr/include/unistd.h
  1262. # patch 'system' in places where it isnt patched out and replaced by our own version (ie cdromtools etc)
  1263. sed -i -- "s|__TVOS_PROHIBITED| |" $SDK_PATH/usr/include/stdlib.h
  1264. sed -i -- "s|__API_AVAILABLE(macos(10.0))|__API_AVAILABLE(macos(10.0), tvos(9.0))|" $SDK_PATH/usr/include/stdlib.h
  1265. }
  1266. if [[ $LOG_VERBOSE == "verbose"* ]]; then
  1267. set -x
  1268. fi
  1269. if [[ "$VERIFY" == "true" ]]; then
  1270. command -v gpg >/dev/null 2>&1 || { echo >&2 "Missing GPG. Cannot verify. Dying."; exit 127 ; }
  1271. echo "Importing necessary PGP keys"
  1272. gpg --recv-key 69184620 7C0135FB088AAF6C66C650B9BB5869F064EA74AB 702353E0F7E48EDB 7FD9FCCB000BEEEE A15B725964A95EE5 D8692123C4065DEA5E0F3AB5249B39D24F25E3B6 031EC2536E580D8EA286A9F22071B08A33BD3F06 9D5EAAF69013B842
  1273. fi
  1274. mkdirIfNecessary $ROOT_LOG_FOLDER
  1275. mkdirIfNecessary $ALREADY_BUILT
  1276. # Ensure our SDK has all the required "extras" installed/setup
  1277. prepSDK
  1278. #buildBashAndFriends
  1279. #buildBasicUtils
  1280. #buildDPKGAndDependencies
  1281. buildAPTAndDependencies