the_memo2.sh 41 KB

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