the_memo2.sh 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448
  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"
  182. export CXXCPP="$(xcrun --sdk $PLATFORM_LOWER -f clang++) -E -D__arm__ -D__arm64__ -I$SKEL_PREFIX/$ROOT_PREFIX/include/ -I$SDKROOT/usr/include"
  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. #https://git.elucubratus.com/elucubratus/elucubratus/-/raw/master/data/ncurses/ncurses_6.1+20181013.orig.tar.gz
  471. buildNcurses() {
  472. PKG_NAME="ncurses-6.0"
  473. checkBuilt $PKG_NAME
  474. if [[ $? != 0 ]]; then
  475. echo "$PKG_NAME already exists, skipping!"
  476. else
  477. echo "building $PKG_NAME..."
  478. splitName $PKG_NAME
  479. 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
  480. patchNcurses $PKG_NAME
  481. buildProduct $PKG_NAME
  482. fi
  483. }
  484. #https://git.elucubratus.com/elucubratus/elucubratus/-/raw/master/data/bash/bash-5.0.tar.gz
  485. buildBash() {
  486. PKG_NAME="bash-5.0"
  487. checkBuilt $PKG_NAME
  488. if [[ $? != 0 ]]; then
  489. echo "$PKG_NAME already exists, skipping!"
  490. else
  491. echo "building $PKG_NAME..."
  492. splitName $PKG_NAME
  493. downloadProduct https://git.elucubratus.com/elucubratus/elucubratus/-/raw/master/data/bash/bash-5.0.tar.gz - $RAW_NAME $VERSION
  494. patchBash
  495. 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"
  496. fi
  497. }
  498. buildSed() {
  499. PKG_NAME="sed-4.4"
  500. checkBuilt $PKG_NAME
  501. if [[ $? != 0 ]]; then
  502. echo "$PKG_NAME already exists, skipping!"
  503. else
  504. echo "building $PKG_NAME..."
  505. splitName $PKG_NAME
  506. 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
  507. buildProduct $PKG_NAME
  508. fi
  509. }
  510. buildGrep() {
  511. PKG_NAME="grep-3.0"
  512. checkBuilt $PKG_NAME
  513. if [[ $? != 0 ]]; then
  514. echo "$PKG_NAME already exists, skipping!"
  515. else
  516. echo "building $PKG_NAME..."
  517. splitName $PKG_NAME
  518. downloadProduct https://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
  519. buildProduct $PKG_NAME
  520. fi
  521. }
  522. patchCoreutils() {
  523. if [[ "$PLATFORM" == "AppleTVOS" ]]; then
  524. sed -i -- 's|#undef HAVE_CLOCK_GETTIME||' lib/config.hin
  525. sed -i -- 's|#undef HAVE_CLOCK_SETTIME||' lib/config.hin
  526. sed -i -- 's|#undef HAVE_FDATASYNC||' lib/config.hin
  527. sed -i -- 's|# define __stpncpy stpncpy||' lib/stpncpy.c
  528. if [[ ! -d "$SKEL_PREFIX/$ROOT_PREFIX/include" ]]; then
  529. mkdir -p "$SKEL_PREFIX/$ROOT_PREFIX/include"
  530. fi
  531. if [[ ! -e "$SKEL_PREFIX/$ROOT_PREFIX/include/crt_externs.h" ]]; then
  532. echo "#include <sys/cdefs.h>" >> "$SKEL_PREFIX/$ROOT_PREFIX/include/crt_externs.h"
  533. echo "" >> "$SKEL_PREFIX/$ROOT_PREFIX/include/crt_externs.h"
  534. echo "__BEGIN_DECLS" >> "$SKEL_PREFIX/$ROOT_PREFIX/include/crt_externs.h"
  535. echo "extern char ***_NSGetArgv(void);" >> "$SKEL_PREFIX/$ROOT_PREFIX/include/crt_externs.h"
  536. echo "extern int *_NSGetArgc(void);" >> "$SKEL_PREFIX/$ROOT_PREFIX/include/crt_externs.h"
  537. echo "extern char ***_NSGetEnviron(void);" >> "$SKEL_PREFIX/$ROOT_PREFIX/include/crt_externs.h"
  538. echo "extern char **_NSGetProgname(void);" >> "$SKEL_PREFIX/$ROOT_PREFIX/include/crt_externs.h"
  539. echo "extern struct mach_header *_NSGetMachExecuteHeader(void);" >> "$SKEL_PREFIX/$ROOT_PREFIX/include/crt_externs.h"
  540. echo "__END_DECLS" >> "$SKEL_PREFIX/$ROOT_PREFIX/include/crt_externs.h"
  541. fi
  542. fi
  543. }
  544. buildCoreutils() {
  545. PKG_NAME="coreutils-8.9"
  546. checkBuilt $PKG_NAME
  547. if [[ $? != 0 ]]; then
  548. echo "$PKG_NAME already exists, skipping!"
  549. else
  550. echo "building $PKG_NAME..."
  551. splitName $PKG_NAME
  552. downloadProduct http://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
  553. patchCoreutils
  554. export HOST="arm"
  555. buildProduct $PKG_NAME
  556. export HOST="aarch64"
  557. fi
  558. }
  559. buildFindUtils() {
  560. PKG_NAME="findutils-4.6.0"
  561. checkBuilt $PKG_NAME
  562. if [[ $? != 0 ]]; then
  563. echo "$PKG_NAME already exists, skipping!"
  564. else
  565. echo "building $PKG_NAME..."
  566. splitName $PKG_NAME
  567. downloadProduct http://mirror.keystealth.org/gnu/findutils/findutils-4.6.0.tar.gz - $RAW_NAME $VERSION
  568. buildProduct $PKG_NAME
  569. fi
  570. }
  571. buildDiffUtils() {
  572. PKG_NAME="diffutils-3.6"
  573. checkBuilt $PKG_NAME
  574. if [[ $? != 0 ]]; then
  575. echo "$PKG_NAME already exists, skipping!"
  576. else
  577. echo "building $PKG_NAME..."
  578. splitName $PKG_NAME
  579. 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
  580. buildProduct $PKG_NAME
  581. fi
  582. }
  583. downloadDarwinTools() {
  584. if [[ ! -d DarwinToolsARM ]]; then
  585. echo "Fetching DarwinTools"
  586. mkdir -p DarwinToolsARM
  587. cd DarwinToolsARM
  588. curl -LO https://opensource.apple.com/source/DarwinTools/DarwinTools-1/sw_vers.c
  589. #Not built yet
  590. curl -LO https://opensource.apple.com/source/launchd/launchd-842.92.1/support/launchctl.c
  591. #sw_vers.c
  592. checkSHA256 sw_vers.c 55aab510b465f7687b8ebe23f0e51926606fd5316da138778838b2dac3e7c7e0
  593. else
  594. echo "Using existing DarwinTools"
  595. cd DarwinToolsARM
  596. fi
  597. WORKING_DIR="DarwinToolsARM"
  598. PKG_NAME="darwintools"
  599. PKG_VERSION="1.0-1"
  600. }
  601. patchDarwinTools() {
  602. if [[ "$PLATFORM" == "AppleTVOS" ]]; then
  603. sed -i -- 's|#include <CoreFoundation/CFPriv.h>|extern CFDictionaryRef _CFCopySystemVersionDictionary(void);\
  604. extern CFDictionaryRef _CFCopyServerVersionDictionary(void);|' sw_vers.c
  605. sed -i -- 's|_kCFSystemVersionProductNameKey|CFSTR(\"ProductName\")|g' sw_vers.c
  606. sed -i -- 's|_kCFSystemVersionProductVersionKey|CFSTR(\"ProductVersion\")|g' sw_vers.c
  607. sed -i -- 's|_kCFSystemVersionBuildVersionKey|CFSTR(\"ProductBuildVersion\")|g' sw_vers.c
  608. fi
  609. }
  610. #darwintools
  611. #Notes:
  612. # This only builds a striped down version of the one on iOS
  613. # If you're building for a non-appletv platform, you may need to fix things here.
  614. buildDarwinTools() {
  615. downloadDarwinTools
  616. patchDarwinTools
  617. "$CLANG_PATH" -arch "$ARCH" -isysroot"$SDK_PATH" -framework CoreFoundation "$MIN_VERSION" -o "sw_vers" sw_vers.c
  618. #codesign "$BUILD_ROOT/$WORKING_DIR/sw_vers"
  619. cp sw_vers "$SKEL_PREFIX/$ROOT_PREFIX/bin/"
  620. cd "$BUILD_ROOT"
  621. }
  622. #Download uikittools
  623. downloadUIKitTools() {
  624. if [[ ! -d uikittools ]]; then
  625. echo "Fetching uikittools"
  626. git clone git://git.saurik.com/uikittools.git
  627. else
  628. echo "Using existing uikittools"
  629. fi
  630. WORKING_DIR="uikittools"
  631. PKG_NAME="uikittools"
  632. PKG_VERSION="1.1.12-1"
  633. cd "$WORKING_DIR"
  634. git checkout tags/v1.1.12
  635. }
  636. #uikittools
  637. #Notes:
  638. # This only builds a striped down version of the one on iOS
  639. # If you're building for a non-appletv platform, you may need to fix things here.
  640. buildUIKitTools() {
  641. downloadUIKitTools
  642. "$CLANGPLUS_PATH" -arch "$ARCH" -isysroot"$SDK_PATH" -Os -Werror -framework CoreFoundation -framework Foundation "$MIN_VERSION" -o cfversion cfversion.mm
  643. "$CLANGPLUS_PATH" -arch "$ARCH" -isysroot"$SDK_PATH" -Os -Werror -framework CoreFoundation -framework Foundation "$MIN_VERSION" -o gssc gssc.mm
  644. "$CLANGPLUS_PATH" -arch "$ARCH" -isysroot"$SDK_PATH" -Os -Werror -framework CoreFoundation -framework Foundation -framework UIKit "$MIN_VERSION" -o uiduid uiduid.mm
  645. #odesign "$BUILD_ROOT/$WORKING_DIR/cfversion"
  646. #codesign "$BUILD_ROOT/$WORKING_DIR/gssc"
  647. #codesign "$BUILD_ROOT/$WORKING_DIR/uiduid"
  648. cp gssc cfversion uiduid "$SKEL_PREFIX/$ROOT_PREFIX/bin/"
  649. cd "$BUILD_ROOT"
  650. }
  651. buildBasicUtils() {
  652. notifyProgress "Building sed"
  653. buildSed
  654. notifyProgress "Building grep"
  655. buildGrep
  656. notifyProgress "Building coreutils"
  657. buildCoreutils
  658. notifyProgress "Building findutils"
  659. buildFindUtils
  660. notifyProgress "Building diffutils"
  661. buildDiffUtils
  662. notifyProgress "Building DarwinTools"
  663. buildDarwinTools
  664. notifyProgress "Building UIKitTools"
  665. buildUIKitTools
  666. }
  667. mkdirIfNecessary() {
  668. MK_DIR="$1"
  669. if [[ ! -d $MK_DIR ]]; then
  670. mkdir -p $MK_DIR
  671. fi
  672. }
  673. removeIfNecessary() {
  674. REMOVE_FILE="$1"
  675. if [[ -f $REMOVE_FILE ]]; then
  676. rm -rf $REMOVE_FILE
  677. fi
  678. }
  679. #=====================
  680. #DPKG and Dependencies
  681. #---------------------
  682. #Download zlib
  683. downloadZLib() {
  684. #Download zlib
  685. if [[ ! -d zlib ]]; then
  686. echo "Downloading zlib git"
  687. git clone https://github.com/madler/zlib.git
  688. else
  689. echo "Using existing zlib"
  690. fi
  691. WORKING_DIR="zlib"
  692. PKG_NAME="zlib"
  693. PKG_VERSION="1.2.11-1"
  694. cd "$WORKING_DIR"
  695. git checkout tags/v1.2.11
  696. removeIfNecessary build
  697. mkdirIfNecessary build
  698. cd build
  699. WORKING_DIR="$WORKING_DIR/build"
  700. }
  701. #zlib
  702. buildZLib() {
  703. PKG_NAME="lzib-1.2.11"
  704. checkBuilt $PKG_NAME
  705. if [[ $? != 0 ]]; then
  706. echo "$PKG_NAME already exists, skipping!"
  707. else
  708. downloadZLib
  709. cmake -DCMAKE_INSTALL_NAME_DIR="/$ROOT_PREFIX/lib" -DCMAKE_OSX_SYSROOT="$SDK_PATH/" -DCMAKE_C_FLAGS="-arch $ARCH" -DCMAKE_INSTALL_PREFIX="/$ROOT_PREFIX" ..
  710. checkStatus $PKG_NAME $? "false"
  711. make -j8 DESTDIR="$SKEL_PREFIX" install
  712. checkStatus $PKG_NAME $? "true"
  713. cd "$BUILD_ROOT"
  714. fi
  715. }
  716. patchXZ() {
  717. if [[ "$PLATFORM" == "AppleTVOS" ]]; then
  718. sed -i -- 's|#undef HAVE_CLOCK_GETTIME||' config.h.in
  719. fi
  720. }
  721. patchTar() {
  722. if [[ "$PLATFORM" == "AppleTVOS" ]]; then
  723. sed -i -- 's|#undef HAVE_CLOCK_GETTIME||' config.h.in
  724. fi
  725. }
  726. patchOpenSSL() {
  727. sed -i -- "s|-arch $ARCH -mios-version-min=7.0.0|-arch $ARCH $MIN_VERSION|" Configurations/10-main.conf
  728. }
  729. patchBZip2() {
  730. if [[ "$PLATFORM" == "AppleTVOS" ]]; then
  731. #fix up our makefile...
  732. sed -i -- 's|CC=gcc|CC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang|' Makefile
  733. sed -i -- 's|AR=ar|AR=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar|' Makefile
  734. sed -i -- 's|RANLIB=ranlib|RANLIB=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib|' Makefile
  735. sed -i -- "s|LDFLAGS=|LDFLAGS=$MIN_VERSION -isysroot \"$SDK_PATH\" -arch $ARCH|" Makefile
  736. sed -i -- "s|CFLAGS=|CFLAGS=$MIN_VERSION -isysroot \"$SDK_PATH\" -arch $ARCH |" Makefile
  737. sed -i -- 's|all:\(.*\) test$|all: \1|' Makefile
  738. sed -i -- 's|ln -s -f \$(PREFIX)/bin/|ln -s -f |g' Makefile
  739. fi
  740. }
  741. patchCurl() {
  742. if [[ "$PLATFORM" == "AppleTVOS" ]]; then
  743. #(Forcibly) Remove that dirty clock_gettime
  744. #TODO: Determine if this is the best way
  745. sed -i -- 's|#undef HAVE_CLOCK_GETTIME_MONOTONIC||' lib/curl_config.h.in
  746. fi
  747. }
  748. buildXZ() {
  749. PKG_NAME="xz-5.2.3"
  750. checkBuilt $PKG_NAME
  751. if [[ $? != 0 ]]; then
  752. echo "$PKG_NAME already exists, skipping!"
  753. else
  754. echo "building $PKG_NAME..."
  755. splitName $PKG_NAME
  756. downloadProduct http://tukaani.org/xz/xz-5.2.3.tar.gz http://tukaani.org/xz/xz-5.2.3.tar.gz.sig $RAW_NAME $VERSION
  757. patchXZ
  758. buildProduct $PKG_NAME
  759. fi
  760. }
  761. buildBZip2() {
  762. PKG_NAME="bzip2-1.0.6"
  763. checkBuilt $PKG_NAME
  764. if [[ $? != 0 ]]; then
  765. echo "$PKG_NAME already exists, skipping!"
  766. else
  767. echo "building $PKG_NAME..."
  768. splitName $PKG_NAME
  769. downloadProduct https://gigenet.dl.sourceforge.net/project/bzip2/bzip2-1.0.6.tar.gz - $RAW_NAME $VERSION
  770. patchBZip2
  771. make -j8 install PREFIX="$SKEL_PREFIX/$ROOT_PREFIX"
  772. checkStatus $PKG_NAME $? "true"
  773. cd "$BUILD_ROOT"
  774. fi
  775. }
  776. buildLZ4() {
  777. PKG_NAME="lz4-1.7.5"
  778. checkBuilt $PKG_NAME
  779. if [[ $? != 0 ]]; then
  780. echo "$PKG_NAME already exists, skipping!"
  781. else
  782. echo "building $PKG_NAME..."
  783. splitName $PKG_NAME
  784. downloadProduct https://github.com/lz4/lz4/archive/v1.7.5.tar.gz - $RAW_NAME $VERSION
  785. cd contrib/cmake_unofficial/
  786. mkdirIfNecessary build
  787. cd build
  788. cmake -DCMAKE_INSTALL_NAME_DIR="/$ROOT_PREFIX/lib" -DCMAKE_OSX_SYSROOT="$SDK_PATH/" -DCMAKE_C_FLAGS="-arch $ARCH" -DCMAKE_INSTALL_PREFIX="/$ROOT_PREFIX" ..
  789. checkStatus $PKG_NAME $? "false"
  790. make -j8
  791. make -j8 DESTDIR="$SKEL_PREFIX" install
  792. checkStatus $PKG_NAME $? "true"
  793. cd "$BUILD_ROOT"
  794. fi
  795. }
  796. downloadOpenSSL() {
  797. if [[ ! -d openssl ]]; then
  798. git clone -b OpenSSL_1_1_0-stable https://github.com/openssl/openssl.git
  799. else
  800. echo "Using existing openssl repo"
  801. fi
  802. WORKING_DIR="openssl"
  803. PKG_NAME="openssl"
  804. PKG_VERSION="1.1.0-1"
  805. cd "$WORKING_DIR"
  806. }
  807. buildOpenSSL() {
  808. PKG_NAME="openssl"
  809. checkBuilt $PKG_NAME
  810. if [[ $? != 0 ]]; then
  811. echo "$PKG_NAME already exists, skipping!"
  812. else
  813. LOG_FILE="$ROOT_LOG_FOLDER/openssl.log"
  814. touch $LOG_FILE
  815. downloadOpenSSL
  816. patchOpenSSL
  817. export AR=""
  818. export PLATFORM="$PLATFORM"
  819. export BUILD_TOOLS="$(xcode-select --print-path)"
  820. export CC="clang -fembed-bitcode"
  821. export CROSS_COMPILE="$(xcode-select --print-path)/Toolchains/XcodeDefault.xctoolchain/usr/bin/"
  822. export CROSS_TOP="$(xcode-select --print-path)/Platforms/$PLATFORM.platform/Developer"
  823. export CROSS_SDK="$(echo $SDK_PATH | sed 's/.*\///g')"
  824. notifyProgress "Configuring openSSL"
  825. if [[ $LOG_VERBOSE == "verbose"* ]]; then
  826. ./Configure ios64-cross no-dso no-hw no-engine --prefix="/$ROOT_PREFIX" | tee "${LOG_FILE}"
  827. EC=$(grep "configure: error:" -i "${LOG_FILE}" -c)
  828. checkStatus $PKG_NAME $EC "false"
  829. else
  830. (./Configure ios64-cross no-dso no-hw no-engine --prefix="/$ROOT_PREFIX" > "$LOG_FILE" 2>&1)
  831. checkStatus $PKG_NAME $? "false"
  832. if [[ $OPEN_LOG == "true" ]]; then
  833. open "${LOG_FILE}"
  834. fi
  835. fi
  836. echo -e "\n\nPOST CONFIGURE\n\n" >> "$LOG_FILE"
  837. notifyProgress "making openSSL"
  838. if [[ $LOG_VERBOSE == "verbose"* ]]; then
  839. make DESTDIR="$SKEL_PREFIX" install | tee -a "${LOG_FILE}"
  840. EC=$(grep "fatal error:" -i "${LOG_FILE}" -c)
  841. checkStatus $PKG_NAME $EC "true"
  842. else
  843. (make DESTDIR="$SKEL_PREFIX" install >> "${LOG_FILE}" 2>&1)
  844. checkStatus $PKG_NAME $? "true"
  845. fi
  846. cd "$BUILD_ROOT"
  847. fi
  848. }
  849. buildCurl() {
  850. PKG_NAME="curl-7.50.1"
  851. checkBuilt $PKG_NAME
  852. if [[ $? != 0 ]]; then
  853. echo "$PKG_NAME already exists, skipping!"
  854. else
  855. echo "building $PKG_NAME..."
  856. splitName $PKG_NAME
  857. downloadProduct https://curl.haxx.se/download/curl-7.50.1.tar.gz - $RAW_NAME $VERSION
  858. patchCurl
  859. buildProduct $PKG_NAME
  860. fi
  861. }
  862. patchBerkeleyDB() {
  863. if [[ "$PLATFORM" == "AppleTVOS" ]]; then
  864. sed -i -- 's|#undef HAVE_CLOCK_GETTIME||' ../dist/config.hin
  865. #if [[ "$PKG_VERSION" == "6.2.23-1" ]]; then
  866. cat ../lang/sql/sqlite/src/shell.c | head -n 14 > shell.patched.c
  867. echo "#include <stdint.h>" >> shell.patched.c
  868. echo "#include <stdio.h>" >> shell.patched.c
  869. echo "#include <stdlib.h>" >> shell.patched.c
  870. echo "#include <spawn.h>" >> shell.patched.c
  871. echo "#include <sys/wait.h>" >> shell.patched.c
  872. echo "#include <sys/stat.h>" >> shell.patched.c
  873. echo "" >> shell.patched.c
  874. echo "extern char **environ;" >> shell.patched.c
  875. echo "" >> shell.patched.c
  876. cat ../lang/sql/sqlite/src/shell.c | tail -n 4847 | head -n 2622 >> shell.patched.c
  877. fixSystem "shell.patched.c"
  878. cat ../lang/sql/sqlite/src/shell.c | tail -n 2226 | sed 's/system(zCmd)/RunCmd(zCmd)/g' >> shell.patched.c
  879. cp shell.patched.c ../lang/sql/sqlite/src/shell.c
  880. #fi
  881. fi
  882. }
  883. buildBerkeleyDB() {
  884. PKG_NAME="db-6.2.23"
  885. checkBuilt $PKG_NAME
  886. if [[ $? != 0 ]]; then
  887. echo "$PKG_NAME already exists, skipping!"
  888. else
  889. echo "building $PKG_NAME..."
  890. LOG_FILE="$ROOT_LOG_FOLDER/$PKG_NAME.log"
  891. touch $LOG_FILE
  892. splitName $PKG_NAME
  893. DOWNLOAD_URL="http://download.oracle.com/berkeley-db/db-6.2.23.tar.gz"
  894. downloadProduct $DOWNLOAD_URL - $RAW_NAME $VERSION
  895. cd build_unix
  896. patchBerkeleyDB
  897. export CPP=""
  898. export CXXCPP=""
  899. export PLATFORM="$PLATFORM" #TODO: Maybe necessary? Need to test.
  900. export BUILD_TOOLS="$(xcode-select --print-path)"
  901. export CC="clang"
  902. export CROSS_COMPILE="$(xcode-select --print-path)/Toolchains/XcodeDefault.xctoolchain/usr/bin/"
  903. export CROSS_TOP="$(xcode-select --print-path)/Platforms/$PLATFORM.platform/Developer"
  904. export CROSS_SDK="$(echo $SDK_PATH | sed 's/.*\///g')"
  905. export CFLAGS="-arch $ARCH -pipe -Os -gdwarf-2 -isysroot $SDK_PATH $MIN_VERSION"
  906. export CXXFLAGS="-arch $ARCH -pipe -Os -gdwarf-2 -isysroot $SDK_PATH $MIN_VERSION"
  907. export LDFLAGS="-arch $ARCH -isysroot $SDK_PATH" # -L${SKEL_PREFIX}/lib"
  908. #buildProduct $PKG_NAME
  909. if [[ $LOG_VERBOSE == "verbose"* ]]; then
  910. ../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}"
  911. else
  912. (../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)
  913. if [[ $OPEN_LOG == "true" ]]; then
  914. open "${LOG_FILE}"
  915. fi
  916. fi
  917. checkStatus $PKG_NAME $? "false"
  918. if [[ $LOG_VERBOSE == "verbose"* ]]; then
  919. make DESTDIR="$SKEL_PREFIX" install | tee "${LOG_FILE}"
  920. else
  921. (make DESTDIR="$SKEL_PREFIX" install >> "${LOG_FILE}" 2>&1)
  922. fi
  923. checkStatus $PKG_NAME $? "true"
  924. fi
  925. }
  926. buildTar(){
  927. PKG_NAME="tar-1.33"
  928. checkBuilt $PKG_NAME
  929. if [[ $? != 0 ]]; then
  930. echo "$PKG_NAME already exists, skipping!"
  931. else
  932. echo "building $PKG_NAME..."
  933. splitName $PKG_NAME
  934. downloadProduct http://ftp.gnu.org/gnu/tar/tar-1.33.tar.xz - $RAW_NAME $VERSION
  935. patchTar
  936. buildProduct $PKG_NAME
  937. fi
  938. }
  939. #Download dpkg
  940. downloadDpkg() {
  941. if [[ ! -d dpkg ]]; then
  942. echo "Downlading dpkg"
  943. git clone https://git.nito.tv/NitoTV/dpkg.git
  944. else
  945. echo "Using existing dpkg"
  946. fi
  947. WORKING_DIR="dpkg"
  948. PKG_NAME="dpkg"
  949. PKG_VERSION="1.18.23-1" #FIXME
  950. cd "$WORKING_DIR"
  951. }
  952. #dpkg
  953. buildDpkg() {
  954. PKG_NAME="dpkg-1.18.23"
  955. LOG_FILE="$ROOT_LOG_FOLDER/$PKG_NAME.log"
  956. touch $LOG_FILE
  957. checkBuilt $PKG_NAME
  958. if [[ $? != 0 ]]; then
  959. echo "$PKG_NAME already exists, skipping!"
  960. else
  961. downloadDpkg
  962. local dont_die_here=$(./autogen.sh)
  963. # need to clear these preprocessor flags or they get all wonky
  964. export CPP=""
  965. export CXXCPP=""
  966. export LZMA_LIBS="$SKEL_PREFIX/$ROOT_PREFIX/lib/liblzma.dylib"
  967. export CC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
  968. export CXX=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++
  969. export CFLAGS="-isysroot $SDK_PATH -I$SDK_PATH/usr/include -I$SKEL_PREFIX/$ROOT_PREFIX/include/ -arch $ARCH"
  970. export CXXFLAGS=$CFLAGS
  971. export LDFLAGS="-isysroot $SDK_PATH -L$SKEL_PREFIX/$ROOT_PREFIX/lib/ -arch $ARCH"
  972. export CPPFLAGS="-isysroot $SDK_PATH -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. if [[ $LOG_VERBOSE == "verbose"* ]]; then
  976. ./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}"
  977. EC=$(grep "configure: error:" -i "${LOG_FILE}" -c)
  978. checkStatus $PKG_NAME $EC "false"
  979. else
  980. (./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)
  981. if [[ $OPEN_LOG == "true" ]]; then
  982. open "${LOG_FILE}"
  983. fi
  984. fi
  985. checkStatus $PKG_NAME $? "false"
  986. patchDpkg #Must be after configure for now. I'll deal with this later
  987. if [[ $LOG_VERBOSE == "verbose"* ]]; then
  988. make -j8 DESTDIR="$SKEL_PREFIX" install | tee "${LOG_FILE}"
  989. EC=$(grep "fatal error:" -i "${LOG_FILE}" -c)
  990. checkStatus $PKG_NAME $EC "true"
  991. else
  992. (make -j8 DESTDIR="$SKEL_PREFIX" install >> "${LOG_FILE}" 2>&1)
  993. checkStatus $PKG_NAME $? "true"
  994. fi
  995. #lzma conflicts with built in libraries when running in certian conditions.
  996. #we make -j8 a symlink our version of lzma in the xz build process
  997. #here we change dpkg-deb to look for this version instead
  998. #if we do not do this, apt-get/dpkg* will fail from our setuid tool
  999. install_name_tool -change /usr/lib/liblzma.5.dylib /usr/local/lib/liblzma.5.dylib "$SKEL_PREFIX/$ROOT_PREFIX/bin/dpkg-deb"
  1000. echo "appletvos-arm64" >> "$BUILD_ROOT/dpkg/deb/var/lib/dpkg/arch"
  1001. echo "darwin-arm64" >> "$BUILD_ROOT/dpkg/deb/var/lib/dpkg/arch"
  1002. #Get rid of cross-compile artifacts
  1003. sed -i -- "s|$SKEL_PREFIX||g" "$BUILD_ROOT/$WORKING_DIR/deb/$ROOT_PREFIX/lib/libdpkg.la"
  1004. sed -i -- "s|$SKEL_PREFIX||g" "$BUILD_ROOT/$WORKING_DIR/deb/$ROOT_PREFIX/lib/pkgconfig/libdpkg.pc"
  1005. rm -rf "$BUILD_ROOT/$WORKING_DIR/deb/$ROOT_PREFIX/lib/libdpkg.la--"
  1006. rm -rf "$BUILD_ROOT/$WORKING_DIR/deb/$ROOT_PREFIX/lib/pkgconfig/libdpkg.pc--"
  1007. cd "$BUILD_ROOT"
  1008. fi
  1009. }
  1010. buildDPKGAndDependencies() {
  1011. notifyProgress "Building zlib"
  1012. buildZLib
  1013. notifyProgress "Building xz"
  1014. buildXZ
  1015. notifyProgress "Building bzip2"
  1016. buildBZip2
  1017. notifyProgress "Building lz4"
  1018. buildLZ4
  1019. notifyProgress "Building openSSL"
  1020. buildOpenSSL
  1021. notifyProgress "Building curl"
  1022. buildCurl
  1023. notifyProgress "Building BerkeleyDB"
  1024. buildBerkeleyDB
  1025. notifyProgress "Building tar"
  1026. buildTar
  1027. notifyProgress "Building dpkg"
  1028. buildDpkg
  1029. }
  1030. buildGpgError() {
  1031. PKG_NAME="libgpg-error-1.32"
  1032. checkBuilt $PKG_NAME
  1033. if [[ $? != 0 ]]; then
  1034. echo "$PKG_NAME already exists, skipping!"
  1035. else
  1036. echo "building $PKG_NAME..."
  1037. #splitName $PKG_NAME
  1038. DOWNLOAD_URL="https://www.gnupg.org/ftp/gcrypt/libgpg-error/libgpg-error-1.32.tar.bz2"
  1039. downloadProduct $DOWNLOAD_URL $DOWNLOAD_URL.sig libgpg-error 1.32
  1040. #sed -i -- 's|#include <stdlib.h>|\n#if !defined(__arm64__)\n#define __arm64__\n#endif\n\n#include <stdlib.h>|' ncurses/build.priv.h
  1041. #echo -e "\n#if !defined(__arm64__)\n#define __arm64__\n#endif\n\n" >> config.h.in
  1042. #export HOST="arm"
  1043. buildProduct $PKG_NAME "--enable-threads=posix"
  1044. #export HOST="aarch64"
  1045. fi
  1046. }
  1047. patchGcrypt() {
  1048. if [[ "$PLATFORM" == "AppleTVOS" ]]; then
  1049. #if [[ "$PKG_VERSION" == "1.8.2-1" ]]; then
  1050. cat tests/random.c | head -n 39 > random.patched.c
  1051. echo "#include <stdint.h>" >> random.patched.c
  1052. echo "#include <stdio.h>" >> random.patched.c
  1053. echo "#include <stdlib.h>" >> random.patched.c
  1054. echo "#include <spawn.h>" >> random.patched.c
  1055. echo "#include <sys/wait.h>" >> random.patched.c
  1056. echo "#include <sys/stat.h>" >> random.patched.c
  1057. echo "" >> random.patched.c
  1058. echo "extern char **environ;" >> random.patched.c
  1059. echo "" >> random.patched.c
  1060. fixSystem "random.patched.c"
  1061. cat tests/random.c | tail -n 727 | sed 's/system (cmdline)/RunCmd(cmdline)/g' >> random.patched.c
  1062. cp random.patched.c tests/random.c
  1063. #fi
  1064. fi
  1065. }
  1066. buildGcrypt() {
  1067. PKG_NAME="libgcrypt-1.8.2"
  1068. checkBuilt $PKG_NAME
  1069. if [[ $? != 0 ]]; then
  1070. echo "$PKG_NAME already exists, skipping!"
  1071. else
  1072. echo "building $PKG_NAME..."
  1073. splitName $PKG_NAME
  1074. 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
  1075. patchGcrypt
  1076. export HOST="arm"
  1077. buildProduct $PKG_NAME "--with-libgpg-error-prefix=$SKEL_PREFIX/$ROOT_PREFIX/"
  1078. export HOST="aarch64"
  1079. fi
  1080. }
  1081. patchKSBA() {
  1082. sed -i -- 's|#include <stdarg.h>|#include <stdarg.h>\n#include "ksba.h"\n|' src/asn1-gentables.c
  1083. sed -i -- "s|$(CC_FOR_BUILD) -I$(srcdir)|$(CC_FOR_BUILD) -I$(srcdir) -I$SKEL_PREFIX/$ROOT_PREFIX/include/|" src/Makefile.in
  1084. sed -i -- 's|const char \*gpg_strerror|//const char \*gpg_strerror|' src/gen-help.h
  1085. }
  1086. buildKSBA() {
  1087. PKG_NAME="libksba-1.3.5"
  1088. checkBuilt $PKG_NAME
  1089. if [[ $? != 0 ]]; then
  1090. echo "$PKG_NAME already exists, skipping!"
  1091. else
  1092. echo "building $PKG_NAME..."
  1093. splitName $PKG_NAME
  1094. DOWNLOAD_URL="https://www.gnupg.org/ftp/gcrypt/libksba/libksba-1.3.5.tar.bz2"
  1095. downloadProduct $DOWNLOAD_URL $DOWNLOAD_URL.sig $RAW_NAME $VERSION
  1096. patchKSBA
  1097. buildProduct $PKG_NAME "--with-libgpg-error-prefix=$SKEL_PREFIX/$ROOT_PREFIX/"
  1098. fi
  1099. }
  1100. patchNpth() {
  1101. if [[ "$PLATFORM" == "AppleTVOS" ]]; then
  1102. sed -i -- 's|#undef HAVE_CLOCK_GETTIME||' config.h.in
  1103. #if [[ "$PKG_VERSION" == "1.5-1" ]]; then
  1104. cat src/npth.c | head -n 19 > npth.patched.c
  1105. echo "#include <stdint.h>" >> npth.patched.c
  1106. echo "#include <stdio.h>" >> npth.patched.c
  1107. echo "#include <stdlib.h>" >> npth.patched.c
  1108. echo "#include <spawn.h>" >> npth.patched.c
  1109. echo "#include <sys/wait.h>" >> npth.patched.c
  1110. echo "" >> npth.patched.c
  1111. echo "extern char **environ;" >> npth.patched.c
  1112. echo "" >> npth.patched.c
  1113. cat src/npth.c | tail -n 757 | head -n 537 >> npth.patched.c
  1114. fixSystem "npth.patched.c"
  1115. cat src/npth.c | tail -n 220 | sed 's/system(cmd)/RunCmd(cmd)/g' >> npth.patched.c
  1116. cp npth.patched.c src/npth.c
  1117. #fi
  1118. fi
  1119. }
  1120. buildNpth() {
  1121. PKG_NAME="npth-1.5"
  1122. checkBuilt $PKG_NAME
  1123. if [[ $? != 0 ]]; then
  1124. echo "$PKG_NAME already exists, skipping!"
  1125. else
  1126. echo "building $PKG_NAME..."
  1127. splitName $PKG_NAME
  1128. DOWNLOAD_URL="https://www.gnupg.org/ftp/gcrypt/npth/npth-1.5.tar.bz2"
  1129. downloadProduct $DOWNLOAD_URL $DOWNLOAD_URL.sig $RAW_NAME $VERSION
  1130. patchNpth
  1131. buildProduct $PKG_NAME
  1132. fi
  1133. }
  1134. #https://www.gnupg.org/ftp/gcrypt/libassuan/libassuan-2.5.1.tar.bz2
  1135. buildAssuan() {
  1136. PKG_NAME="libassuan-2.5.1"
  1137. checkBuilt $PKG_NAME
  1138. if [[ $? != 0 ]]; then
  1139. echo "$PKG_NAME already exists, skipping!"
  1140. else
  1141. echo "building $PKG_NAME..."
  1142. splitName $PKG_NAME
  1143. DOWNLOAD_URL="https://www.gnupg.org/ftp/gcrypt/libassuan/libassuan-2.5.1.tar.bz2"
  1144. downloadProduct $DOWNLOAD_URL $DOWNLOAD_URL.sig $RAW_NAME $VERSION
  1145. buildProduct $PKG_NAME "--with-libgpg-error-prefix=$SKEL_PREFIX/$ROOT_PREFIX/"
  1146. fi
  1147. }
  1148. patchNtbtls() {
  1149. if [[ "$PLATFORM" == "AppleTVOS" ]]; then
  1150. # this is required because prior dependencies write /$ROOT_PREFIX/lib/libgpg-error.la as a dependency in the .la file
  1151. 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"
  1152. 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"
  1153. rm -f "$SKEL_PREFIX/$ROOT_PREFIX/lib/libgcrypt.la--"
  1154. rm -f "$SKEL_PREFIX/$ROOT_PREFIX/lib/libksba.la--"
  1155. fi
  1156. }
  1157. buildNtbtls() {
  1158. PKG_NAME="ntbtls-0.1.2"
  1159. checkBuilt $PKG_NAME
  1160. if [[ $? != 0 ]]; then
  1161. echo "$PKG_NAME already exists, skipping!"
  1162. else
  1163. echo "building $PKG_NAME..."
  1164. splitName $PKG_NAME
  1165. DOWNLOAD_URL="https://www.gnupg.org/ftp/gcrypt/ntbtls/ntbtls-0.1.2.tar.bz2"
  1166. downloadProduct $DOWNLOAD_URL $DOWNLOAD_URL.sig $RAW_NAME $VERSION
  1167. patchNtbtls
  1168. 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"
  1169. fi
  1170. }
  1171. patchGpg() {
  1172. if [[ "$PLATFORM" == "AppleTVOS" ]]; then
  1173. #if [[ "$PKG_VERSION" == "2.2.3-1" ]]; then
  1174. cat "g10/exec.c" | head -n 54 > "exec.patched.c"
  1175. echo "#include <stdint.h>" >> "exec.patched.c"
  1176. echo "#include <stdio.h>" >> "exec.patched.c"
  1177. echo "#include <stdlib.h>" >> "exec.patched.c"
  1178. echo "#include <spawn.h>" >> "exec.patched.c"
  1179. echo "#include <sys/wait.h>" >> "exec.patched.c"
  1180. echo "" >> "exec.patched.c"
  1181. echo "extern char **environ;" >> "exec.patched.c"
  1182. echo "" >> "exec.patched.c"
  1183. cat "g10/exec.c" | head -n 111 | tail -n 57 >> "exec.patched.c"
  1184. fixSystem "exec.patched.c"
  1185. cat "g10/exec.c" | tail -n 524 | sed 's/=system(info->command)/=RunCmd(info->command)/g' >> "exec.patched.c"
  1186. cp "exec.patched.c" "g10/exec.c"
  1187. #fi
  1188. fi
  1189. }
  1190. #
  1191. buildGpg() {
  1192. PKG_NAME="gnupg-2.2.3"
  1193. checkBuilt $PKG_NAME
  1194. if [[ $? != 0 ]]; then
  1195. echo "$PKG_NAME already exists, skipping!"
  1196. else
  1197. echo "building $PKG_NAME..."
  1198. splitName $PKG_NAME
  1199. DOWNLOAD_URL="https://www.gnupg.org/ftp/gcrypt/gnupg/gnupg-2.2.3.tar.bz2"
  1200. downloadProduct $DOWNLOAD_URL $DOWNLOAD_URL.sig $RAW_NAME $VERSION
  1201. patchGpg
  1202. 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/"
  1203. fi
  1204. }
  1205. patchAPT() {
  1206. if [[ "$PLATFORM" == "AppleTVOS" ]]; then
  1207. sed -i -- '/^INCLUDE_DIRECTORIES/d' ../CMakeLists.txt
  1208. sed -i -- '/^LINK_DIRECTORIES/d' ../CMakeLists.txt
  1209. cat ../CMakeLists.txt | head -n 15 > newCmakeLists.txt
  1210. echo "INCLUDE_DIRECTORIES($SKEL_PREFIX/$ROOT_PREFIX/include)" >> newCmakeLists.txt
  1211. echo "LINK_DIRECTORIES($SKEL_PREFIX/$ROOT_PREFIX/lib)" >> newCmakeLists.txt
  1212. echo "" >> newCmakeLists.txt
  1213. cat ../CMakeLists.txt | tail -n 217 >> newCmakeLists.txt
  1214. mv newCmakeLists.txt ../CmakeLists.txt
  1215. #sed -i -- "s|/Users/jaywalker/RnD/ATV/packages/test/skel/|$SKEL_PREFIX/|g" ../CMakeLists.txt
  1216. fi
  1217. }
  1218. downloadApt() {
  1219. if [[ ! -d apt ]]; then
  1220. echo "Downlading apt"
  1221. git clone https://git.nito.tv/NitoTV/apt.git
  1222. else
  1223. echo "Using existing apt"
  1224. fi
  1225. WORKING_DIR="apt"
  1226. cd "$WORKING_DIR"
  1227. removeIfNecessary build
  1228. mkdirIfNecessary build
  1229. cd build
  1230. WORKING_DIR="$WORKING_DIR/build"
  1231. }
  1232. buildAPT() {
  1233. PKG_NAME="apt7-0.7.25.3"
  1234. LOG_FILE="$ROOT_LOG_FOLDER/$PKG_NAME.log"
  1235. touch $LOG_FILE
  1236. checkBuilt $PKG_NAME
  1237. if [[ $? != 0 ]]; then
  1238. echo "$PKG_NAME already exists, skipping!"
  1239. else
  1240. downloadApt
  1241. patchAPT
  1242. echo "build output going to: " $LOG_FILE
  1243. if [[ $LOG_VERBOSE == "verbose"* ]]; then
  1244. 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}"
  1245. #FIXME : need status / error checking here!
  1246. else
  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" .. > "${LOG_FILE}" 2>&1)
  1248. checkStatus $PKG_NAME $? "false"
  1249. if [[ $OPEN_LOG == "true" ]]; then
  1250. open "${LOG_FILE}"
  1251. fi
  1252. fi
  1253. sed -i -- "s|#define COMMON_ARCH \"darwin-amd64\"|#define COMMON_ARCH \"$PLATFORM_LOWER-$ARCH\"|" include/config.h
  1254. if [[ $LOG_VERBOSE == "verbose"* ]]; then
  1255. make -j8 DESTDIR="$SKEL_PREFIX" install | tee "${LOG_FILE}"
  1256. EC=$(grep "fatal error:" -i "${LOG_FILE}" -c)
  1257. checkStatus $PKG_NAME $EC "true"
  1258. else
  1259. (make -j8 DESTDIR="$SKEL_PREFIX" install >> "${LOG_FILE}" 2>&1)
  1260. checkStatus $PKG_NAME $? "true"
  1261. fi
  1262. #lzma conflicts with built in libraries we make -j8 an extra copy of our version of lzma in the xz build process
  1263. #here we change libapt-pkg*.dylib to look for this version instead
  1264. #if we do not do this, apt-get will fail from our helper tool
  1265. 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
  1266. cd "$BUILD_ROOT"
  1267. fi
  1268. }
  1269. buildAPTAndDependencies() {
  1270. notifyProgress "Building gpg-error"
  1271. buildGpgError
  1272. notifyProgress "Building gcrypt"
  1273. buildGcrypt
  1274. notifyProgress "Building KSBA"
  1275. buildKSBA
  1276. notifyProgress "Building npth"
  1277. buildNpth
  1278. notifyProgress "Building Assuan"
  1279. buildAssuan
  1280. notifyProgress "Building ntbtls"
  1281. buildNtbtls
  1282. notifyProgress "Building gpg"
  1283. buildGpg
  1284. notifyProgress "Building apt"
  1285. buildAPT
  1286. }
  1287. prepSDK() {
  1288. if [[ ! -e "$SDK_PATH/usr/include/sys/ttydev.h" ]]; then
  1289. echo "Missing <sys/ttydev.h>. Moving it in from MacOSX SDK (with sudo)"
  1290. sudo cp "$(xcrun --sdk macosx --show-sdk-path)/usr/include/sys/ttydev.h" "$SDK_PATH/usr/include/sys/ttydev.h"
  1291. fi
  1292. if [[ ! -e "$SDK_PATH/usr/include/lockdown.h" ]]; then
  1293. echo "Missing lockdown.h! Generating the bare essentials for apt to build..."
  1294. echo "#ifndef LOCKDOWN_LOCKDOWN_H" >> "$SDK_PATH/usr/include/lockdown.h"
  1295. echo "#define LOCKDOWN_LOCKDOWN_H" >> "$SDK_PATH/usr/include/lockdown.h"
  1296. echo "" >> "$SDK_PATH/usr/include/lockdown.h"
  1297. echo "#include <CoreFoundation/CFString.h>" >> "$SDK_PATH/usr/include/lockdown.h"
  1298. echo "" >> "$SDK_PATH/usr/include/lockdown.h"
  1299. echo "#ifdef __cplusplus" >> "$SDK_PATH/usr/include/lockdown.h"
  1300. echo "extern \"C\" {" >> "$SDK_PATH/usr/include/lockdown.h"
  1301. echo "#endif" >> "$SDK_PATH/usr/include/lockdown.h"
  1302. echo "" >> "$SDK_PATH/usr/include/lockdown.h"
  1303. echo "extern CFStringRef kLockdownUniqueDeviceIDKey;" >> "$SDK_PATH/usr/include/lockdown.h"
  1304. echo "" >> "$SDK_PATH/usr/include/lockdown.h"
  1305. echo "extern void *lockdown_connect(void);" >> "$SDK_PATH/usr/include/lockdown.h"
  1306. echo "extern CFStringRef lockdown_copy_value(void *lockdown, void *null, CFStringRef key);" >> "$SDK_PATH/usr/include/lockdown.h"
  1307. echo "extern void lockdown_disconnect(void *lockdown);" >> "$SDK_PATH/usr/include/lockdown.h"
  1308. echo "" >> "$SDK_PATH/usr/include/lockdown.h"
  1309. echo "#ifdef __cplusplus" >> "$SDK_PATH/usr/include/lockdown.h"
  1310. echo "}" >> "$SDK_PATH/usr/include/lockdown.h"
  1311. echo "#endif" >> "$SDK_PATH/usr/include/lockdown.h"
  1312. echo "" >> "$SDK_PATH/usr/include/lockdown.h"
  1313. echo "#endif/*LOCKDOWN_LOCKDOWN_H*/" >> "$SDK_PATH/usr/include/lockdown.h"
  1314. fi
  1315. IOKIT_MATCH="`find ~/Library/Developer/Xcode/tvOS\ DeviceSupport/ -name IOKit.framework | grep "$SDK_VERSION" -m 1`"
  1316. echo "IOKit match: $IOKIT_MATCH"
  1317. echo "IOKit: $SDK_PATH/System/Library/Frameworks/IOKit.framework"
  1318. if [[ ! -d "$SDK_PATH/System/Library/Frameworks/IOKit.framework" ]]; then
  1319. if [[ ! -z "$IOKIT_MATCH" ]]; then
  1320. echo "we do indeed have an IOKit match and IOKit is missing!!"
  1321. echo "cp -r $IOKIT_MATCH $SDK_PATH/System/Library/Frameworks/"
  1322. cp -r "$IOKIT_MATCH" "$SDK_PATH/System/Library/Frameworks/"
  1323. fi
  1324. fi
  1325. # patch fork to be available in tvOS
  1326. sed -i -- "s|__TVOS_PROHIBITED| |" $SDK_PATH/usr/include/unistd.h
  1327. # patch 'system' in places where it isnt patched out and replaced by our own version (ie cdromtools etc)
  1328. sed -i -- "s|__TVOS_PROHIBITED| |" $SDK_PATH/usr/include/stdlib.h
  1329. sed -i -- "s|__API_AVAILABLE(macos(10.0))|__API_AVAILABLE(macos(10.0), tvos(9.0))|" $SDK_PATH/usr/include/stdlib.h
  1330. }
  1331. if [[ $LOG_VERBOSE == "verbose"* ]]; then
  1332. set -x
  1333. fi
  1334. if [[ "$VERIFY" == "true" ]]; then
  1335. command -v gpg >/dev/null 2>&1 || { echo >&2 "Missing GPG. Cannot verify. Dying."; exit 127 ; }
  1336. echo "Importing necessary PGP keys"
  1337. gpg --recv-key 69184620 7C0135FB088AAF6C66C650B9BB5869F064EA74AB 702353E0F7E48EDB 7FD9FCCB000BEEEE A15B725964A95EE5 D8692123C4065DEA5E0F3AB5249B39D24F25E3B6 031EC2536E580D8EA286A9F22071B08A33BD3F06 9D5EAAF69013B842
  1338. fi
  1339. mkdirIfNecessary $ROOT_LOG_FOLDER
  1340. mkdirIfNecessary $ALREADY_BUILT
  1341. # Ensure our SDK has all the required "extras" installed/setup
  1342. prepSDK
  1343. buildBashAndFriends
  1344. buildBasicUtils
  1345. buildDPKGAndDependencies
  1346. buildAPTAndDependencies
  1347. echo -e "\nDone!\n"
  1348. sayIfVerbal "Finished!"