the_memo2.sh 55 KB

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