the_memo2.sh 58 KB

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