the_memo2.sh 43 KB

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