| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190 |
- #!/bin/bash -x
- BUILD_ROOT="$(pwd)"
- ROOT_LOG_FOLDER="$BUILD_ROOT/Logs"
- VERIFY="true"
- PLATFORM="AppleTVOS"
- PLATFORM_LOWER="appletvos"
- SDK_VERSION="$(xcrun --show-sdk-version --sdk $PLATFORM_LOWER)"
- ROOT_PREFIX="fs/jb/usr"
- SKEL_PREFIX="$BUILD_ROOT/skel"
- ALREADY_BUILT="$BUILD_ROOT/tracked"
- CLANG_PATH="$(xcrun -f clang)"
- CLANGPLUS_PATH="$(xcrun -f clang++)"
- MIN_VERSION="-mappletvos-version-min=13.0"
- ARCH="arm64"
- SDK_PATH="$(xcrun --sdk $PLATFORM_LOWER --show-sdk-path)"
- SPEAK="true"
- EXTRA_LD_FLAGS=""
- HOST="aarch64"
- if [[ ! -d $ALREADY_BUILT ]]; then
- mkdir -p $ALREADY_BUILT
- fi
- sayIfVerbal() {
- if [[ $SPEAK == "true" ]]; then
- say $1
- fi
- }
- spinner() {
- local pid=$!
- local delay=0.75
- local spinstr='|/-\'
- while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do
- local temp=${spinstr#?}
- printf " [%c]" "$spinstr"
- local spinstr=$temp${spinstr%"$temp"}
- sleep $delay
- printf "\b\b\b\b\b"
- done
- wait $pid
- return $?
- }
- setBuilt() {
- DIRECTORY_NAME=$1
- FULL=$ALREADY_BUILT/$DIRECTORY_NAME
- touch "$FULL"
- }
- checkStatus() {
- PKG=$1
- STATUS=$2
- FINISHED=$3
- if [[ $STATUS != 0 ]]; then
- echo "configure or make $PKG returned with non zero: $STATUS check $LOG_FILE for errors!"
- open $LOG_FILE
- exit $STATUS
- else
- echo "make returned with zero"
- if [[ $FINISHED == "true" ]]; then
- setBuilt $PKG
- fi
- fi
- }
- checkBuilt() {
- DIRECTORY_NAME=$1
- FULL=$ALREADY_BUILT/$DIRECTORY_NAME
- if [[ ! -f $FULL ]]; then
- echo 0
- return 0
- fi
- echo 1
- return 1
- }
- notifyProgress() {
- echo "$1"
- sayIfVerbal "$1"
- }
- checkSHA256() {
- if [[ "$VERIFY" == "true" ]]; then
- FILE="$1"
- VALID_SHA="$2"
- VERIFY_TEST="`shasum -a 256 $FILE | cut -c 1-64`"
- if [[ "$VERIFY_TEST" != "$VALID_SHA" ]]; then
- echo "Failed to validate SHA256 signature for $FILE"
- trap - INT TERM EXIT
- exit 127
- fi
- echo "*** VALID SIGNATURE"
- fi
- }
- checkPGPSig() {
- if [[ "$VERIFY" == "true" ]]; then
- SIGFILE="$1"
- FILE="$2"
- local VERIFY_TEST="`gpg --verify $SIGFILE $FILE 2>&1 | grep 'Good signature'`"
- if [[ "$VERIFY_TEST" == "" ]]; then
- echo "Failed to validate PGP signature for $FILE"
- trap - INT TERM EXIT
- exit 127
- fi
- echo "*** VALID SIGNATURE"
- fi
- }
- buildProduct() {
- PKG_NAME=$1
- EXTRA_CFG=$2
- LOG_FILE="$ROOT_LOG_FOLDER/$PKG_NAME.log"
- touch $LOG_FILE
- echo $PKG_NAME
- echo "build output going to: " $LOG_FILE
- echo $EXTRA_CFG
- export SDKROOT=$(xcrun --sdk $PLATFORM_LOWER --show-sdk-path)
- export VER_MIN=13.0
- export CC=$(xcrun --sdk $PLATFORM_LOWER --find clang)
- export CXX=$(xcrun --sdk $PLATFORM_LOWER --find clang++)
- export LD=$(xcrun --sdk $PLATFORM_LOWER --find ld)
- export AR=$(xcrun --sdk $PLATFORM_LOWER --find ar)
- export CPP="$(xcrun --sdk $PLATFORM_LOWER -f clang) -E -D__arm__ -D__arm64__"
- export CXXCPP="$(xcrun --sdk $PLATFORM_LOWER -f clang++) -E -D__arm__ -D__arm64__"
- export RANLIB=$(xcrun --sdk $PLATFORM_LOWER --find ranlib)
- export LIBTOOL=$(xcrun --sdk $PLATFORM_LOWER --find libtool)
- export STRIP=$(xcrun --sdk $PLATFORM_LOWER --find strip)
- 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"
- export CXXFLAGS=$CFLAGS
- export LDFLAGS="-arch arm64 -isysroot $SDKROOT -L$SKEL_PREFIX/$ROOT_PREFIX/lib/ $EXTRA_LD_FLAGS"
- sayIfVerbal "configuring $PKG_NAME"
- ./configure --prefix=/$ROOT_PREFIX --host=$HOST-apple-darwin --target=$HOST-apple-darwin --disable-dependency-tracking --without-manpages --disable-tests $EXTRA_CFG
- #(./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
- checkStatus $PKG_NAME $? "false"
- sayIfVerbal "making $PKG_NAME"
- echo "\n\nPOST CONFIGURE\n\n" >> "$LOG_FILE"
- make -j8 DESTDIR="$SKEL_PREFIX" install
- #(make -j8 DESTDIR="$SKEL_PREFIX" install >> "${LOG_FILE}" 2>&1) #& spinner
- checkStatus $PKG_NAME $? "true"
- #if [[ $? != 0 ]]; then
- # echo "make returned with non zero: $?"
- # exit $?
- #else
- # echo "make returned with zero"
- # setBuilt $PKG_NAME
- #fi
- cd "$BUILD_ROOT"
- }
- downloadProduct() {
- DOWNLOAD_LINK=$1
- FILENAME=$(basename $DOWNLOAD_LINK)
- SIG_DOWNLOAD=$2
- RAW_NAME=$3
- VERSION=$4
- FILE_EXTENSION="${FILENAME##*.}"
- DIRECTORY_NAME="$RAW_NAME-$VERSION"
- SIG_FILE=$(basename $SIG_DOWNLOAD)
- if [[ ! -e $FILENAME ]]; then
- echo "Downloading $FILENAME"
- curl -LO $DOWNLOAD_LINK
- if [[ ! $SIG_FILE == "-" ]]; then
- curl -LO $SIG_DOWNLOAD
- checkPGPSig $SIG_FILE $FILENAME
- fi
- else
- echo "Using existing $FILENAME"
- fi
- rm -rf $DIRECTORY_NAME
- if [[ $FILE_EXTENSION == "gz" ]]; then
- echo "is gz file!"
- tar xzvf $FILENAME
- fi
- if [[ $FILE_EXTENSION == "xz" ]]; then
- echo "is lzma file!"
- tar xJvf $FILENAME
- fi
- if [[ $FILE_EXTENSION == "bz2" ]]; then
- echo "is bzip2 file!"
- tar xjvf $FILENAME
- fi
- WORKING_DIR=$DIRECTORY_NAME
- PKG_VERSION=$VERSION-1
- cd "$WORKING_DIR"
- #buildProduct
- }
- patchBash() {
- if [[ "$PLATFORM" == "AppleTVOS" ]]; then
- sed -i -- 's|^#undef HAVE_SYS_SIGLIST$|#define HAVE_SYS_SIGLIST 1|' config.h.in
- fi
- }
- patchDpkg() {
- if [[ "$PLATFORM" == "AppleTVOS" ]]; then
- sed -i -- "s|#define ARCHITECTURE \"darwin-arm\"|#define ARCHITECTURE \"$PLATFORM_LOWER-$ARCH\"|" config.h
- sed -i -- 's|gtar|tar|' config.h
- fi
- }
- # DONT USE UNLESS YOU ARE ON 11+; OVERWRITE BASH (or any other apple-signed file, for that matter), LEAD TO BRICK
- # 10.2 and up
- buildBashAndFriends() {
- notifyProgress "Building readline"
- buildReadline
- notifyProgress "Building ncurses"
- buildNcurses
- #notifyProgress "Building bash"
- #buildBash
- }
- buildReadline() {
- PKG_NAME="readline-7.0"
- checkBuilt $PKG_NAME
- if [[ $? != 0 ]]; then
- echo "$PKG_NAME already exists, skipping!"
- else
- echo "building $PKG_NAME..."
- 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
- buildProduct $PKG_NAME
- fi
- }
- fixSystem() {
- FILE="$1"
- echo '#define PROC_PIDPATHINFO_MAXSIZE (1024)' >> "$FILE"
- echo 'static int file_exist(const char *filename) {' >> "$FILE"
- echo ' struct stat buffer;' >> "$FILE"
- echo ' int r = stat(filename, &buffer);' >> "$FILE"
- echo ' return (r == 0);' >> "$FILE"
- echo '}' >> "$FILE"
- echo '' >> "$FILE"
- echo 'static char *searchpath(const char *binaryname){' >> "$FILE"
- echo ' if (strstr(binaryname, "/") != NULL){' >> "$FILE"
- echo ' if (file_exist(binaryname)){' >> "$FILE"
- echo ' char *foundpath = malloc((strlen(binaryname) + 1) * (sizeof(char)));' >> "$FILE"
- echo ' strcpy(foundpath, binaryname);' >> "$FILE"
- echo ' return foundpath;' >> "$FILE"
- echo ' } else {' >> "$FILE"
- echo ' return NULL;' >> "$FILE"
- echo ' }' >> "$FILE"
- echo ' }' >> "$FILE"
- echo ' ' >> "$FILE"
- echo ' char *pathvar = getenv("PATH");' >> "$FILE"
- echo ' ' >> "$FILE"
- echo ' char *dir = strtok(pathvar,":");' >> "$FILE"
- echo ' while (dir != NULL){' >> "$FILE"
- echo ' char searchpth[PROC_PIDPATHINFO_MAXSIZE];' >> "$FILE"
- echo ' strcpy(searchpth, dir);' >> "$FILE"
- echo ' strcat(searchpth, "/");' >> "$FILE"
- echo ' strcat(searchpth, binaryname);' >> "$FILE"
- echo ' ' >> "$FILE"
- echo ' if (file_exist(searchpth)){' >> "$FILE"
- echo ' char *foundpath = malloc((strlen(searchpth) + 1) * (sizeof(char)));' >> "$FILE"
- echo ' strcpy(foundpath, searchpth);' >> "$FILE"
- echo ' return foundpath;' >> "$FILE"
- echo ' }' >> "$FILE"
- echo ' ' >> "$FILE"
- echo ' dir = strtok(NULL, ":");' >> "$FILE"
- echo ' }' >> "$FILE"
- echo ' return NULL;' >> "$FILE"
- echo '}' >> "$FILE"
- echo '' >> "$FILE"
- echo 'static int isShellScript(const char *path){' >> "$FILE"
- echo ' FILE *file = fopen(path, "r");' >> "$FILE"
- echo ' uint8_t header[2];' >> "$FILE"
- echo ' if (fread(header, sizeof(uint8_t), 2, file) == 2){' >> "$FILE"
- echo " if (header[0] == '#' && header[1] == '!'){" >> "$FILE"
- echo ' fclose(file);' >> "$FILE"
- echo ' return 1;' >> "$FILE"
- echo ' }' >> "$FILE"
- echo ' }' >> "$FILE"
- echo ' fclose(file);' >> "$FILE"
- echo ' return -1;' >> "$FILE"
- echo '}' >> "$FILE"
- echo '' >> "$FILE"
- echo 'static char *getInterpreter(char *path){' >> "$FILE"
- echo ' FILE *file = fopen(path, "r");' >> "$FILE"
- echo ' char *interpreterLine = NULL;' >> "$FILE"
- echo ' unsigned long lineSize = 0;' >> "$FILE"
- echo ' getline(&interpreterLine, &lineSize, file);' >> "$FILE"
- echo ' ' >> "$FILE"
- echo ' char *rawInterpreter = (interpreterLine+2);' >> "$FILE"
- echo ' rawInterpreter = strtok(rawInterpreter, " ");' >> "$FILE"
- echo ' rawInterpreter = strtok(rawInterpreter, "\n");' >> "$FILE"
- echo ' ' >> "$FILE"
- echo ' char *interpreter = malloc((strlen(rawInterpreter)+1) * sizeof(char));' >> "$FILE"
- echo ' strcpy(interpreter, rawInterpreter);' >> "$FILE"
- echo ' ' >> "$FILE"
- echo ' free(interpreterLine);' >> "$FILE"
- echo ' fclose(file);' >> "$FILE"
- echo ' return interpreter;' >> "$FILE"
- echo '}' >> "$FILE"
- echo '' >> "$FILE"
- echo 'static char *fixedCmd(const char *cmdStr){' >> "$FILE"
- echo ' char *cmdCpy = malloc((strlen(cmdStr)+1) * sizeof(char));' >> "$FILE"
- echo ' strcpy(cmdCpy, cmdStr);' >> "$FILE"
- echo ' ' >> "$FILE"
- echo ' char *cmd = strtok(cmdCpy, " ");' >> "$FILE"
- echo ' ' >> "$FILE"
- echo ' uint8_t size = strlen(cmd) + 1;' >> "$FILE"
- echo ' ' >> "$FILE"
- echo ' char *args = cmdCpy + size;' >> "$FILE"
- echo ' if ((strlen(cmdStr) - strlen(cmd)) == 0)' >> "$FILE"
- echo ' args = NULL;' >> "$FILE"
- echo ' ' >> "$FILE"
- echo ' char *abs_path = searchpath(cmd);' >> "$FILE"
- echo ' if (abs_path){' >> "$FILE"
- echo ' int isScript = isShellScript(abs_path);' >> "$FILE"
- echo ' if (isScript == 1){' >> "$FILE"
- echo ' char *interpreter = getInterpreter(abs_path);' >> "$FILE"
- echo ' ' >> "$FILE"
- echo ' uint8_t commandSize = strlen(interpreter) + 1 + strlen(abs_path);' >> "$FILE"
- echo ' ' >> "$FILE"
- echo ' if (args){' >> "$FILE"
- echo ' commandSize += 1 + strlen(args);' >> "$FILE"
- echo ' }' >> "$FILE"
- echo ' ' >> "$FILE"
- echo ' char *rawCommand = malloc(sizeof(char) * (commandSize + 1));' >> "$FILE"
- echo ' strcpy(rawCommand, interpreter);' >> "$FILE"
- echo ' strcat(rawCommand, " ");' >> "$FILE"
- echo ' strcat(rawCommand, abs_path);' >> "$FILE"
- echo ' ' >> "$FILE"
- echo ' if (args){' >> "$FILE"
- echo ' strcat(rawCommand, " ");' >> "$FILE"
- echo ' strcat(rawCommand, args);' >> "$FILE"
- echo ' }' >> "$FILE"
- echo ' rawCommand[(commandSize)+1] = "\0";' >> "$FILE"
- echo ' ' >> "$FILE"
- echo ' free(interpreter);' >> "$FILE"
- echo ' free(abs_path);' >> "$FILE"
- echo ' free(cmdCpy);' >> "$FILE"
- echo ' ' >> "$FILE"
- echo ' return rawCommand;' >> "$FILE"
- echo ' } else {' >> "$FILE"
- echo ' uint8_t commandSize = strlen(abs_path);' >> "$FILE"
- echo ' ' >> "$FILE"
- echo ' if (args){' >> "$FILE"
- echo ' commandSize += 1 + strlen(args);' >> "$FILE"
- echo ' }' >> "$FILE"
- echo ' ' >> "$FILE"
- echo ' char *rawCommand = malloc(sizeof(char) * (commandSize + 1));' >> "$FILE"
- echo ' strcat(rawCommand, abs_path);' >> "$FILE"
- echo ' ' >> "$FILE"
- echo ' if (args){' >> "$FILE"
- echo ' strcat(rawCommand, " ");' >> "$FILE"
- echo ' strcat(rawCommand, args);' >> "$FILE"
- echo ' }' >> "$FILE"
- echo ' rawCommand[(commandSize)+1] = "\0";' >> "$FILE"
- echo ' ' >> "$FILE"
- echo ' free(abs_path);' >> "$FILE"
- echo ' free(cmdCpy);' >> "$FILE"
- echo ' ' >> "$FILE"
- echo ' return rawCommand;' >> "$FILE"
- echo ' }' >> "$FILE"
- echo ' }' >> "$FILE"
- echo ' return cmdCpy;' >> "$FILE"
- echo '}' >> "$FILE"
- echo '' >> "$FILE"
- echo 'int RunCmd(const char *cmd) {' >> "$FILE"
- echo ' pid_t pid;' >> "$FILE"
- echo ' char *rawCmd = fixedCmd(cmd);' >> "$FILE"
- echo ' char *argv[] = {"sh", "-c", (char*)rawCmd, NULL};' >> "$FILE"
- echo ' int status;' >> "$FILE"
- echo ' status = posix_spawn(&pid, "/bin/sh", NULL, NULL, argv, environ);' >> "$FILE"
- echo ' if (status == 0) {' >> "$FILE"
- echo ' if (waitpid(pid, &status, 0) == -1) {' >> "$FILE"
- echo ' perror("waitpid");' >> "$FILE"
- echo ' }' >> "$FILE"
- echo ' } else {' >> "$FILE"
- echo ' printf("posix_spawn: %s\n", strerror(status));' >> "$FILE"
- echo ' }' >> "$FILE"
- echo ' free(rawCmd);' >> "$FILE"
- echo ' return status;' >> "$FILE"
- echo '}' >> "$FILE"
- }
- patchNcurses() {
- PKG_NAME=$1
- echo "patchNCurses PKG_NAME: $PKG_NAME"
- if [[ "$PLATFORM" == "AppleTVOS" ]]; then
- #if [[ "$PKG_VERSION" == "6.0-1" ]]; then
- # LEFT ERROR ON environ)' no ;
- # For some reason, building never fails on the error...
- # But still, tput is in /usr/bin... so.... ??
- cat progs/tput.c | head -n 55 > tput.patched.c
- echo "#include <stdint.h>" >> tput.patched.c
- echo "#include <stdio.h>" >> tput.patched.c
- echo "#include <stdlib.h>" >> tput.patched.c
- echo "#include <spawn.h>" >> tput.patched.c
- echo "#include <sys/wait.h>" >> tput.patched.c
- echo "" >> tput.patched.c
- echo "extern char **environ;" >> tput.patched.c
- echo "" >> tput.patched.c
- cat progs/tput.c | tail -n 350 | head -n 50 >> tput.patched.c
- fixSystem "tput.patched.c"
- cat progs/tput.c | tail -n 301 | sed 's/system(init_prog)/RunCmd(init_prog)/g' >> tput.patched.c
- cp tput.patched.c progs/tput.c
- #fi
- fi
- sed -i -- 's|#include <stdlib.h>|\n#if !defined(__arm64__)\n#define __arm64__\n#endif\n\n#include <stdlib.h>|' ncurses/build.priv.h
- #CURSES_PRIV="$SKEL_PREFIX/$ROOT_PREFIX/include/curses.priv.h"
- #FIFO="$SKEL_PREFIX/$ROOT_PREFIX/include/fifo_defs.h"
- #BUILD_P="$SKEL_PREFIX/$ROOT_PREFIX/include/build.priv.h"
- #if [[ ! -f "$CURSES_PRIV" ]]; then
- # cp $BUILD_ROOT/$1/ncurses/*.h "$SKEL_PREFIX/$ROOT_PREFIX/include/"
- #cp "$BUILD_ROOT/$1/ncurses/fifo_defs.h" "$FIFO"
- #cp "$BUILD_ROOT/$1/ncurses/build.priv.h" "$BUILD_P"
- #fi
- }
- #https://git.elucubratus.com/elucubratus/elucubratus/-/raw/master/data/ncurses/ncurses_6.1+20181013.orig.tar.gz
- buildNcurses() {
- PKG_NAME="ncurses-6.1-20181013"
- checkBuilt $PKG_NAME
- if [[ $? != 0 ]]; then
- echo "$PKG_NAME already exists, skipping!"
- else
- echo "building $PKG_NAME..."
- downloadProduct https://git.elucubratus.com/elucubratus/elucubratus/-/raw/master/data/ncurses/ncurses_6.1+20181013.orig.tar.gz - ncurses 6.1-20181013
- patchNcurses $PKG_NAME
- buildProduct $PKG_NAME
- fi
- }
- #https://git.elucubratus.com/elucubratus/elucubratus/-/raw/master/data/bash/bash-5.0.tar.gz
- buildBash() {
- PKG_NAME="bash-5.0"
- checkBuilt $PKG_NAME
- if [[ $? != 0 ]]; then
- echo "$PKG_NAME already exists, skipping!"
- else
- echo "building $PKG_NAME..."
- downloadProduct https://git.elucubratus.com/elucubratus/elucubratus/-/raw/master/data/bash/bash-5.0.tar.gz - bash 5.0
- patchBash
- 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"
- fi
- }
- buildSed() {
- PKG_NAME="sed-4.4"
- checkBuilt $PKG_NAME
- if [[ $? != 0 ]]; then
- echo "$PKG_NAME already exists, skipping!"
- else
- echo "building $PKG_NAME..."
- 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
- buildProduct $PKG_NAME
- fi
- }
- buildGrep() {
- PKG_NAME="grep-3.0"
- checkBuilt $PKG_NAME
- if [[ $? != 0 ]]; then
- echo "$PKG_NAME already exists, skipping!"
- else
- echo "building $PKG_NAME..."
- 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
- buildProduct $PKG_NAME
- fi
- }
- patchCoreutils() {
- if [[ "$PLATFORM" == "AppleTVOS" ]]; then
- sed -i -- 's|#undef HAVE_CLOCK_GETTIME||' lib/config.hin
- sed -i -- 's|#undef HAVE_CLOCK_SETTIME||' lib/config.hin
- sed -i -- 's|#undef HAVE_FDATASYNC||' lib/config.hin
- sed -i -- 's|# define __stpncpy stpncpy||' lib/stpncpy.c
- if [[ ! -d "$SKEL_PREFIX/$ROOT_PREFIX/include" ]]; then
- mkdir -p "$SKEL_PREFIX/$ROOT_PREFIX/include"
- fi
- if [[ ! -e "$SKEL_PREFIX/$ROOT_PREFIX/include/crt_externs.h" ]]; then
- echo "#include <sys/cdefs.h>" >> "$SKEL_PREFIX/$ROOT_PREFIX/include/crt_externs.h"
- echo "" >> "$SKEL_PREFIX/$ROOT_PREFIX/include/crt_externs.h"
- echo "__BEGIN_DECLS" >> "$SKEL_PREFIX/$ROOT_PREFIX/include/crt_externs.h"
- echo "extern char ***_NSGetArgv(void);" >> "$SKEL_PREFIX/$ROOT_PREFIX/include/crt_externs.h"
- echo "extern int *_NSGetArgc(void);" >> "$SKEL_PREFIX/$ROOT_PREFIX/include/crt_externs.h"
- echo "extern char ***_NSGetEnviron(void);" >> "$SKEL_PREFIX/$ROOT_PREFIX/include/crt_externs.h"
- echo "extern char **_NSGetProgname(void);" >> "$SKEL_PREFIX/$ROOT_PREFIX/include/crt_externs.h"
- echo "extern struct mach_header *_NSGetMachExecuteHeader(void);" >> "$SKEL_PREFIX/$ROOT_PREFIX/include/crt_externs.h"
- echo "__END_DECLS" >> "$SKEL_PREFIX/$ROOT_PREFIX/include/crt_externs.h"
- fi
- fi
- }
- buildCoreutils() {
- PKG_NAME="coreutils-8.9"
- checkBuilt $PKG_NAME
- if [[ $? != 0 ]]; then
- echo "$PKG_NAME already exists, skipping!"
- else
- echo "building $PKG_NAME..."
- 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
- patchCoreutils
- export HOST="arm"
- buildProduct $PKG_NAME
- export HOST="aarch64"
- fi
- }
- buildFindUtils() {
- PKG_NAME="findutils-4.6.0"
- checkBuilt $PKG_NAME
- if [[ $? != 0 ]]; then
- echo "$PKG_NAME already exists, skipping!"
- else
- echo "building $PKG_NAME..."
- downloadProduct http://mirror.keystealth.org/gnu/findutils/findutils-4.6.0.tar.gz - findutils 4.6.0
- buildProduct $PKG_NAME
- fi
- }
- buildDiffUtils() {
- PKG_NAME="diffutils-3.6"
- checkBuilt $PKG_NAME
- if [[ $? != 0 ]]; then
- echo "$PKG_NAME already exists, skipping!"
- else
- echo "building $PKG_NAME..."
- 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
- buildProduct $PKG_NAME
- fi
- }
- downloadDarwinTools() {
- if [[ ! -d DarwinToolsARM ]]; then
- echo "Fetching DarwinTools"
- mkdir -p DarwinToolsARM
- cd DarwinToolsARM
- curl -LO https://opensource.apple.com/source/DarwinTools/DarwinTools-1/sw_vers.c
- #Not built yet
- curl -LO https://opensource.apple.com/source/launchd/launchd-842.92.1/support/launchctl.c
- #sw_vers.c
- checkSHA256 sw_vers.c 55aab510b465f7687b8ebe23f0e51926606fd5316da138778838b2dac3e7c7e0
- else
- echo "Using existing DarwinTools"
- cd DarwinToolsARM
- fi
- WORKING_DIR="DarwinToolsARM"
- PKG_NAME="darwintools"
- PKG_VERSION="1.0-1"
- }
- patchDarwinTools() {
- if [[ "$PLATFORM" == "AppleTVOS" ]]; then
- sed -i -- 's|#include <CoreFoundation/CFPriv.h>|extern CFDictionaryRef _CFCopySystemVersionDictionary(void);\
- extern CFDictionaryRef _CFCopyServerVersionDictionary(void);|' sw_vers.c
- sed -i -- 's|_kCFSystemVersionProductNameKey|CFSTR(\"ProductName\")|g' sw_vers.c
- sed -i -- 's|_kCFSystemVersionProductVersionKey|CFSTR(\"ProductVersion\")|g' sw_vers.c
- sed -i -- 's|_kCFSystemVersionBuildVersionKey|CFSTR(\"ProductBuildVersion\")|g' sw_vers.c
- fi
- }
- #darwintools
- #Notes:
- # This only builds a striped down version of the one on iOS
- # If you're building for a non-appletv platform, you may need to fix things here.
- buildDarwinTools() {
- downloadDarwinTools
- patchDarwinTools
- "$CLANG_PATH" -arch "$ARCH" -isysroot"$SDK_PATH" -framework CoreFoundation "$MIN_VERSION" -o "sw_vers" sw_vers.c
- #codesign "$BUILD_ROOT/$WORKING_DIR/sw_vers"
- cp sw_vers "$SKEL_PREFIX/$ROOT_PREFIX/bin/"
- cd "$BUILD_ROOT"
- }
- #Download uikittools
- downloadUIKitTools() {
- if [[ ! -d uikittools ]]; then
- echo "Fetching uikittools"
- git clone git://git.saurik.com/uikittools.git
- else
- echo "Using existing uikittools"
- fi
- WORKING_DIR="uikittools"
- PKG_NAME="uikittools"
- PKG_VERSION="1.1.12-1"
- cd "$WORKING_DIR"
- git checkout tags/v1.1.12
- }
- #uikittools
- #Notes:
- # This only builds a striped down version of the one on iOS
- # If you're building for a non-appletv platform, you may need to fix things here.
- buildUIKitTools() {
- downloadUIKitTools
- "$CLANGPLUS_PATH" -arch "$ARCH" -isysroot"$SDK_PATH" -Os -Werror -framework CoreFoundation -framework Foundation "$MIN_VERSION" -o cfversion cfversion.mm
- "$CLANGPLUS_PATH" -arch "$ARCH" -isysroot"$SDK_PATH" -Os -Werror -framework CoreFoundation -framework Foundation "$MIN_VERSION" -o gssc gssc.mm
- "$CLANGPLUS_PATH" -arch "$ARCH" -isysroot"$SDK_PATH" -Os -Werror -framework CoreFoundation -framework Foundation -framework UIKit "$MIN_VERSION" -o uiduid uiduid.mm
- #odesign "$BUILD_ROOT/$WORKING_DIR/cfversion"
- #codesign "$BUILD_ROOT/$WORKING_DIR/gssc"
- #codesign "$BUILD_ROOT/$WORKING_DIR/uiduid"
- cp gssc cfversion uiduid "$SKEL_PREFIX/$ROOT_PREFIX/bin/"
- cd "$BUILD_ROOT"
- }
- buildBasicUtils() {
- notifyProgress "Building sed"
- buildSed
- notifyProgress "Building grep"
- buildGrep
- notifyProgress "Building coreutils"
- buildCoreutils
- notifyProgress "Building findutils"
- buildFindUtils
- notifyProgress "Building diffutils"
- buildDiffUtils
- notifyProgress "Building DarwinTools"
- buildDarwinTools
- notifyProgress "Building UIKitTools"
- buildUIKitTools
- }
- mkdirIfNecessary() {
- MK_DIR="$1"
- if [[ ! -d $MK_DIR ]]; then
- mkdir -p $MK_DIR
- fi
- }
- removeIfNecessary() {
- REMOVE_FILE="$1"
- if [[ -f $REMOVE_FILE ]]; then
- rm -rf $REMOVE_FILE
- fi
- }
- #=====================
- #DPKG and Dependencies
- #---------------------
- #Download zlib
- downloadZLib() {
- #Download zlib
- if [[ ! -d zlib ]]; then
- echo "Downloading zlib git"
- git clone https://github.com/madler/zlib.git
- else
- echo "Using existing zlib"
- fi
- WORKING_DIR="zlib"
- PKG_NAME="zlib"
- PKG_VERSION="1.2.11-1"
- cd "$WORKING_DIR"
- git checkout tags/v1.2.11
- removeIfNecessary build
- mkdirIfNecessary build
- cd build
- WORKING_DIR="$WORKING_DIR/build"
- }
- #zlib
- buildZLib() {
- PKG_NAME="lzib-1.2.11"
- checkBuilt $PKG_NAME
- if [[ $? != 0 ]]; then
- echo "$PKG_NAME already exists, skipping!"
- else
- downloadZLib
- cmake -DCMAKE_INSTALL_NAME_DIR="/$ROOT_PREFIX/lib" -DCMAKE_OSX_SYSROOT="$SDK_PATH/" -DCMAKE_C_FLAGS="-arch $ARCH" -DCMAKE_INSTALL_PREFIX="/$ROOT_PREFIX" ..
- checkStatus $PKG_NAME $? "false"
- make -j8 DESTDIR="$SKEL_PREFIX" install
- checkStatus $PKG_NAME $? "true"
- cd "$BUILD_ROOT"
- fi
- }
- patchXZ() {
- if [[ "$PLATFORM" == "AppleTVOS" ]]; then
- sed -i -- 's|#undef HAVE_CLOCK_GETTIME||' config.h.in
- fi
- }
- patchTar() {
- if [[ "$PLATFORM" == "AppleTVOS" ]]; then
- sed -i -- 's|#undef HAVE_CLOCK_GETTIME||' config.h.in
- fi
- }
- patchOpenSSL() {
- sed -i -- "s|-arch $ARCH -mios-version-min=7.0.0|-arch $ARCH $MIN_VERSION|" Configurations/10-main.conf
- }
- patchBZip2() {
- if [[ "$PLATFORM" == "AppleTVOS" ]]; then
- #fix up our makefile...
- sed -i -- 's|CC=gcc|CC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang|' Makefile
- sed -i -- 's|AR=ar|AR=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar|' Makefile
- sed -i -- 's|RANLIB=ranlib|RANLIB=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib|' Makefile
- sed -i -- "s|LDFLAGS=|LDFLAGS=$MIN_VERSION -isysroot \"$SDK_PATH\" -arch $ARCH|" Makefile
- sed -i -- "s|CFLAGS=|CFLAGS=$MIN_VERSION -isysroot \"$SDK_PATH\" -arch $ARCH |" Makefile
- sed -i -- 's|all:\(.*\) test$|all: \1|' Makefile
- sed -i -- 's|ln -s -f \$(PREFIX)/bin/|ln -s -f |g' Makefile
- fi
- }
- patchCurl() {
- if [[ "$PLATFORM" == "AppleTVOS" ]]; then
- #(Forcibly) Remove that dirty clock_gettime
- #TODO: Determine if this is the best way
- sed -i -- 's|#undef HAVE_CLOCK_GETTIME_MONOTONIC||' lib/curl_config.h.in
- fi
- }
- buildXZ() {
- PKG_NAME="xz-5.2.3"
- checkBuilt $PKG_NAME
- if [[ $? != 0 ]]; then
- echo "$PKG_NAME already exists, skipping!"
- else
- echo "building $PKG_NAME..."
- 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
- patchXZ
- buildProduct $PKG_NAME
- fi
- }
- buildBZip2() {
- PKG_NAME="bzip2-1.0.6"
- checkBuilt $PKG_NAME
- if [[ $? != 0 ]]; then
- echo "$PKG_NAME already exists, skipping!"
- else
- echo "building $PKG_NAME..."
- downloadProduct https://gigenet.dl.sourceforge.net/project/bzip2/bzip2-1.0.6.tar.gz - bzip2 1.0.6
- patchBZip2
- make -j8 install PREFIX="$SKEL_PREFIX/$ROOT_PREFIX"
- checkStatus $PKG_NAME $? "true"
- cd "$BUILD_ROOT"
- fi
- }
- buildLZ4() {
- PKG_NAME="lz4-1.7.5"
- checkBuilt $PKG_NAME
- if [[ $? != 0 ]]; then
- echo "$PKG_NAME already exists, skipping!"
- else
- echo "building $PKG_NAME..."
- downloadProduct https://github.com/lz4/lz4/archive/v1.7.5.tar.gz - lz4 1.7.5
- cd contrib/cmake_unofficial/
- mkdirIfNecessary build
- cd build
- cmake -DCMAKE_INSTALL_NAME_DIR="/$ROOT_PREFIX/lib" -DCMAKE_OSX_SYSROOT="$SDK_PATH/" -DCMAKE_C_FLAGS="-arch $ARCH" -DCMAKE_INSTALL_PREFIX="/$ROOT_PREFIX" ..
- checkStatus $PKG_NAME $? "false"
- make -j8
- make -j8 DESTDIR="$SKEL_PREFIX" install
- checkStatus $PKG_NAME $? "true"
- cd "$BUILD_ROOT"
- fi
- }
- downloadOpenSSL() {
- if [[ ! -d openssl ]]; then
- git clone -b OpenSSL_1_1_0-stable https://github.com/openssl/openssl.git
- else
- echo "Using existing openssl repo"
- fi
- WORKING_DIR="openssl"
- PKG_NAME="openssl"
- PKG_VERSION="1.1.0-1"
- cd "$WORKING_DIR"
- }
- buildOpenSSL() {
- checkBuilt $PKG_NAME
- if [[ $? != 0 ]]; then
- echo "$PKG_NAME already exists, skipping!"
- else
- LOG_FILE="$ROOT_LOG_FOLDER/openssl.log"
- touch $LOG_FILE
- downloadOpenSSL
- patchOpenSSL
- export AR=""
- export PLATFORM="$PLATFORM"
- export BUILD_TOOLS="$(xcode-select --print-path)"
- export CC="clang -fembed-bitcode"
- export CROSS_COMPILE="$(xcode-select --print-path)/Toolchains/XcodeDefault.xctoolchain/usr/bin/"
- export CROSS_TOP="$(xcode-select --print-path)/Platforms/$PLATFORM.platform/Developer"
- export CROSS_SDK="$(echo $SDK_PATH | sed 's/.*\///g')"
- sayIfVerbal "Configuring openSSL"
- (./Configure ios64-cross no-dso no-hw no-engine --prefix="/$ROOT_PREFIX" > "$LOG_FILE" 2>&1)
- checkStatus $PKG_NAME $? "false"
- echo "\n\nPOST CONFIGURE\n\n" >> "$LOG_FILE"
- sayIfVerbal "making openSSL"
- (make DESTDIR="$SKEL_PREFIX" install >> "${LOG_FILE}" 2>&1)
- checkStatus $PKG_NAME $? "true"
- cd "$BUILD_ROOT"
- fi
- }
- buildCurl() {
- PKG_NAME="curl-7.50.1"
- checkBuilt $PKG_NAME
- if [[ $? != 0 ]]; then
- echo "$PKG_NAME already exists, skipping!"
- else
- echo "building $PKG_NAME..."
- downloadProduct https://curl.haxx.se/download/curl-7.50.1.tar.gz - curl 7.50.1
- patchCurl
- buildProduct $PKG_NAME
- fi
- }
- buildTar(){
- PKG_NAME="tar-1.33"
- checkBuilt $PKG_NAME
- if [[ $? != 0 ]]; then
- echo "$PKG_NAME already exists, skipping!"
- else
- echo "building $PKG_NAME..."
- downloadProduct http://ftp.gnu.org/gnu/tar/tar-1.33.tar.xz - tar 1.33
- patchTar
- buildProduct $PKG_NAME
- fi
- }
- #Download dpkg
- downloadDpkg() {
- if [[ ! -d dpkg ]]; then
- echo "Downlading dpkg"
- git clone https://git.nito.tv/NitoTV/dpkg.git
- else
- echo "Using existing dpkg"
- fi
- WORKING_DIR="dpkg"
- PKG_NAME="dpkg"
- PKG_VERSION="1.18.23-1" #FIXME
- cd "$WORKING_DIR"
- }
- #dpkg
- buildDpkg() {
- downloadDpkg
- local dont_die_here=$(./autogen.sh)
- 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"
- patchDpkg #Must be after configure for now. I'll deal with this later
- make -j8 DESTDIR="$SKEL_PREFIX" install
- #lzma conflicts with built in libraries when running in certian conditions.
- #we make -j8 a symlink our version of lzma in the xz build process
- #here we change dpkg-deb to look for this version instead
- #if we do not do this, apt-get/dpkg* will fail from our setuid tool
- install_name_tool -change /usr/lib/liblzma.5.dylib /usr/local/lib/liblzma.5.dylib "$SKEL_PREFIX/$ROOT_PREFIX/bin/dpkg-deb"
- echo "appletvos-arm64" >> "$BUILD_ROOT/dpkg/deb/var/lib/dpkg/arch"
- echo "darwin-arm64" >> "$BUILD_ROOT/dpkg/deb/var/lib/dpkg/arch"
- #Get rid of cross-compile artifacts
- sed -i -- "s|$SKEL_PREFIX||g" "$BUILD_ROOT/$WORKING_DIR/deb/$ROOT_PREFIX/lib/libdpkg.la"
- sed -i -- "s|$SKEL_PREFIX||g" "$BUILD_ROOT/$WORKING_DIR/deb/$ROOT_PREFIX/lib/pkgconfig/libdpkg.pc"
- rm -rf "$BUILD_ROOT/$WORKING_DIR/deb/$ROOT_PREFIX/lib/libdpkg.la--"
- rm -rf "$BUILD_ROOT/$WORKING_DIR/deb/$ROOT_PREFIX/lib/pkgconfig/libdpkg.pc--"
- cd "$BUILD_ROOT"
- }
- buildDPKGAndDependencies() {
- notifyProgress "Building zlib"
- buildZLib
- notifyProgress "Building xz"
- buildXZ
- notifyProgress "Building bzip2"
- buildBZip2
- notifyProgress "Building lz4"
- buildLZ4
- notifyProgress "Building openSSL"
- buildOpenSSL
- notifyProgress "Building curl"
- buildCurl
- #notifyProgress "Building BerkeleyDB"
- #buildBerkeleyDB
- notifyProgress "Building tar"
- buildTar
- #notifyProgress "Building dpkg"
- #buildDpkg
- }
- buildGpgError() {
- PKG_NAME="libgpg-error-1.27"
- checkBuilt $PKG_NAME
- if [[ $? != 0 ]]; then
- echo "$PKG_NAME already exists, skipping!"
- else
- echo "building $PKG_NAME..."
- 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
- export HOST="arm"
- buildProduct $PKG_NAME "--enable-threads=posix"
- export HOST="aarch64"
- fi
- }
- patchGcrypt() {
- if [[ "$PLATFORM" == "AppleTVOS" ]]; then
- #if [[ "$PKG_VERSION" == "1.8.2-1" ]]; then
- cat tests/random.c | head -n 39 > random.patched.c
- echo "#include <stdint.h>" >> random.patched.c
- echo "#include <stdio.h>" >> random.patched.c
- echo "#include <stdlib.h>" >> random.patched.c
- echo "#include <spawn.h>" >> random.patched.c
- echo "#include <sys/wait.h>" >> random.patched.c
- echo "#include <sys/stat.h>" >> random.patched.c
- echo "" >> random.patched.c
- echo "extern char **environ;" >> random.patched.c
- echo "" >> random.patched.c
- fixSystem "random.patched.c"
- cat tests/random.c | tail -n 727 | sed 's/system (cmdline)/RunCmd(cmdline)/g' >> random.patched.c
- cp random.patched.c tests/random.c
- #fi
- fi
- }
- buildGcrypt() {
- PKG_NAME="libgcrypt-1.8.2"
- checkBuilt $PKG_NAME
- if [[ $? != 0 ]]; then
- echo "$PKG_NAME already exists, skipping!"
- else
- echo "building $PKG_NAME..."
- 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
- patchGcrypt
- export HOST="arm"
- buildProduct $PKG_NAME "--with-libgpg-error-prefix=$SKEL_PREFIX/$ROOT_PREFIX/"
- export HOST="aarch64"
- fi
- }
- buildKSBA() {
- PKG_NAME="libksba-1.3.5"
- checkBuilt $PKG_NAME
- if [[ $? != 0 ]]; then
- echo "$PKG_NAME already exists, skipping!"
- else
- echo "building $PKG_NAME..."
- DOWNLOAD_URL="https://www.gnupg.org/ftp/gcrypt/libksba/libksba-1.3.5.tar.bz2"
- downloadProduct $DOWNLOAD_URL $DOWNLOAD_URL.sig libksba 1.3.5
- buildProduct $PKG_NAME "--with-libgpg-error-prefix=$SKEL_PREFIX/$ROOT_PREFIX/"
- fi
- }
- patchNpth() {
- if [[ "$PLATFORM" == "AppleTVOS" ]]; then
- sed -i -- 's|#undef HAVE_CLOCK_GETTIME||' config.h.in
- #if [[ "$PKG_VERSION" == "1.5-1" ]]; then
- cat src/npth.c | head -n 19 > npth.patched.c
- echo "#include <stdint.h>" >> npth.patched.c
- echo "#include <stdio.h>" >> npth.patched.c
- echo "#include <stdlib.h>" >> npth.patched.c
- echo "#include <spawn.h>" >> npth.patched.c
- echo "#include <sys/wait.h>" >> npth.patched.c
- echo "" >> npth.patched.c
- echo "extern char **environ;" >> npth.patched.c
- echo "" >> npth.patched.c
- cat src/npth.c | tail -n 757 | head -n 537 >> npth.patched.c
- fixSystem "npth.patched.c"
- cat src/npth.c | tail -n 220 | sed 's/system(cmd)/RunCmd(cmd)/g' >> npth.patched.c
- cp npth.patched.c src/npth.c
- #fi
- fi
- }
- buildNpth() {
- PKG_NAME="npth-1.5"
- checkBuilt $PKG_NAME
- if [[ $? != 0 ]]; then
- echo "$PKG_NAME already exists, skipping!"
- else
- echo "building $PKG_NAME..."
- DOWNLOAD_URL="https://www.gnupg.org/ftp/gcrypt/npth/npth-1.5.tar.bz2"
- downloadProduct $DOWNLOAD_URL $DOWNLOAD_URL.sig npth 1.5
- patchNpth
- buildProduct $PKG_NAME
- fi
- }
- #https://www.gnupg.org/ftp/gcrypt/libassuan/libassuan-2.5.1.tar.bz2
- buildAssuan() {
- PKG_NAME="libassuan-2.5.1"
- checkBuilt $PKG_NAME
- if [[ $? != 0 ]]; then
- echo "$PKG_NAME already exists, skipping!"
- else
- echo "building $PKG_NAME..."
- DOWNLOAD_URL="https://www.gnupg.org/ftp/gcrypt/libassuan/libassuan-2.5.1.tar.bz2"
- downloadProduct $DOWNLOAD_URL $DOWNLOAD_URL.sig libassuan 2.5.1
- buildProduct $PKG_NAME "--with-libgpg-error-prefix=$SKEL_PREFIX/$ROOT_PREFIX/"
- fi
- }
- patchNtbtls() {
- if [[ "$PLATFORM" == "AppleTVOS" ]]; then
- # this is required because prior dependencies write /$ROOT_PREFIX/lib/libgpg-error.la as a dependency in the .la file
- 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"
- 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"
- rm -f "$SKEL_PREFIX/$ROOT_PREFIX/lib/libgcrypt.la--"
- rm -f "$SKEL_PREFIX/$ROOT_PREFIX/lib/libksba.la--"
- fi
- }
- buildNtbtls() {
- PKG_NAME="ntbtls-0.1.2"
- checkBuilt $PKG_NAME
- if [[ $? != 0 ]]; then
- echo "$PKG_NAME already exists, skipping!"
- else
- echo "building $PKG_NAME..."
- DOWNLOAD_URL="https://www.gnupg.org/ftp/gcrypt/ntbtls/ntbtls-0.1.2.tar.bz2"
- downloadProduct $DOWNLOAD_URL $DOWNLOAD_URL.sig ntbtls 0.1.2
- patchNtbtls
- 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"
- fi
- }
- patchGpg() {
- if [[ "$PLATFORM" == "AppleTVOS" ]]; then
- #if [[ "$PKG_VERSION" == "2.2.3-1" ]]; then
- cat "g10/exec.c" | head -n 54 > "exec.patched.c"
- echo "#include <stdint.h>" >> "exec.patched.c"
- echo "#include <stdio.h>" >> "exec.patched.c"
- echo "#include <stdlib.h>" >> "exec.patched.c"
- echo "#include <spawn.h>" >> "exec.patched.c"
- echo "#include <sys/wait.h>" >> "exec.patched.c"
- echo "" >> "exec.patched.c"
- echo "extern char **environ;" >> "exec.patched.c"
- echo "" >> "exec.patched.c"
- cat "g10/exec.c" | head -n 111 | tail -n 57 >> "exec.patched.c"
- fixSystem "exec.patched.c"
- cat "g10/exec.c" | tail -n 524 | sed 's/=system(info->command)/=RunCmd(info->command)/g' >> "exec.patched.c"
- cp "exec.patched.c" "g10/exec.c"
- #fi
- fi
- }
- #
- buildGpg() {
- PKG_NAME="gpg-2.2.3"
- checkBuilt $PKG_NAME
- if [[ $? != 0 ]]; then
- echo "$PKG_NAME already exists, skipping!"
- else
- echo "building $PKG_NAME..."
- DOWNLOAD_URL="https://www.gnupg.org/ftp/gcrypt/gnupg/gnupg-2.2.3.tar.bz2"
- downloadProduct $DOWNLOAD_URL $DOWNLOAD_URL.sig gpg 2.2.3
- patchGpg
- 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/"
- fi
- }
- patchAPT() {
- if [[ "$PLATFORM" == "AppleTVOS" ]]; then
- sed -i -- '/^INCLUDE_DIRECTORIES/d' ../CMakeLists.txt
- sed -i -- '/^LINK_DIRECTORIES/d' ../CMakeLists.txt
- cat ../CMakeLists.txt | head -n 15 > newCmakeLists.txt
- echo "INCLUDE_DIRECTORIES($SKEL_PREFIX/$ROOT_PREFIX/include)" >> newCmakeLists.txt
- echo "LINK_DIRECTORIES($SKEL_PREFIX/$ROOT_PREFIX/lib)" >> newCmakeLists.txt
- echo "" >> newCmakeLists.txt
- cat ../CMakeLists.txt | tail -n 217 >> newCmakeLists.txt
- mv newCmakeLists.txt ../CmakeLists.txt
- #sed -i -- "s|/Users/jaywalker/RnD/ATV/packages/test/skel/|$SKEL_PREFIX/|g" ../CMakeLists.txt
- fi
- }
- downloadApt() {
- if [[ ! -d apt ]]; then
- echo "Downlading apt"
- git clone https://git.nito.tv/NitoTV/apt.git
- else
- echo "Using existing apt"
- fi
- WORKING_DIR="apt"
- PKG_NAME="apt7"
- PKG_VERSION="0.7.25.3-1"
- cd "$WORKING_DIR"
- removeIfNecessary build
- mkdirIfNecessary build
- cd build
- WORKING_DIR="$WORKING_DIR/build"
- }
- buildAPT() {
- downloadApt
- patchAPT
- 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" ..
- sed -i -- "s|#define COMMON_ARCH \"darwin-amd64\"|#define COMMON_ARCH \"$PLATFORM_LOWER-$ARCH\"|" include/config.h
- make -j8 DESTDIR="$SKEL_PREFIX" install
- #lzma conflicts with built in libraries we make -j8 an extra copy of our version of lzma in the xz build process
- #here we change libapt-pkg*.dylib to look for this version instead
- #if we do not do this, apt-get will fail from our helper tool
- 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
- cd "$BUILD_ROOT"
- }
- buildAPTAndDependencies() {
- notifyProgress "Building gpg-error"
- buildGpgError
- notifyProgress "Building gcrypt"
- buildGcrypt
- notifyProgress "Building KSBA"
- buildKSBA
- notifyProgress "Building npth"
- buildNpth
- notifyProgress "Building Assuan"
- buildAssuan
- notifyProgress "Building ntbtls"
- buildNtbtls
- notifyProgress "Building gpg"
- buildGpg
- #notifyProgress "Building apt"
- #buildAPT
- }
- prepSDK() {
- if [[ ! -e "$SDK_PATH/usr/include/sys/ttydev.h" ]]; then
- echo "Missing <sys/ttydev.h>. Moving it in from MacOSX SDK (with sudo)"
- sudo cp "$(xcrun --sdk macosx --show-sdk-path)/usr/include/sys/ttydev.h" "$SDK_PATH/usr/include/sys/ttydev.h"
- fi
- if [[ ! -e "$SDK_PATH/usr/include/lockdown.h" ]]; then
- echo "Missing lockdown.h! Generating the bare essentials for apt to build..."
- echo "#ifndef LOCKDOWN_LOCKDOWN_H" >> "$SDK_PATH/usr/include/lockdown.h"
- echo "#define LOCKDOWN_LOCKDOWN_H" >> "$SDK_PATH/usr/include/lockdown.h"
- echo "" >> "$SDK_PATH/usr/include/lockdown.h"
- echo "#include <CoreFoundation/CFString.h>" >> "$SDK_PATH/usr/include/lockdown.h"
- echo "" >> "$SDK_PATH/usr/include/lockdown.h"
- echo "#ifdef __cplusplus" >> "$SDK_PATH/usr/include/lockdown.h"
- echo "extern \"C\" {" >> "$SDK_PATH/usr/include/lockdown.h"
- echo "#endif" >> "$SDK_PATH/usr/include/lockdown.h"
- echo "" >> "$SDK_PATH/usr/include/lockdown.h"
- echo "extern CFStringRef kLockdownUniqueDeviceIDKey;" >> "$SDK_PATH/usr/include/lockdown.h"
- echo "" >> "$SDK_PATH/usr/include/lockdown.h"
- echo "extern void *lockdown_connect(void);" >> "$SDK_PATH/usr/include/lockdown.h"
- echo "extern CFStringRef lockdown_copy_value(void *lockdown, void *null, CFStringRef key);" >> "$SDK_PATH/usr/include/lockdown.h"
- echo "extern void lockdown_disconnect(void *lockdown);" >> "$SDK_PATH/usr/include/lockdown.h"
- echo "" >> "$SDK_PATH/usr/include/lockdown.h"
- echo "#ifdef __cplusplus" >> "$SDK_PATH/usr/include/lockdown.h"
- echo "}" >> "$SDK_PATH/usr/include/lockdown.h"
- echo "#endif" >> "$SDK_PATH/usr/include/lockdown.h"
- echo "" >> "$SDK_PATH/usr/include/lockdown.h"
- echo "#endif/*LOCKDOWN_LOCKDOWN_H*/" >> "$SDK_PATH/usr/include/lockdown.h"
- fi
- IOKIT_MATCH="`find ~/Library/Developer/Xcode/tvOS\ DeviceSupport/ -name IOKit.framework | grep "$SDK_VERSION" -m 1`"
- echo "IOKit match: $IOKIT_MATCH"
- echo "IOKit: $SDK_PATH/System/Library/Frameworks/IOKit.framework"
- if [[ ! -d "$SDK_PATH/System/Library/Frameworks/IOKit.framework" ]]; then
- if [[ ! -z "$IOKIT_MATCH" ]]; then
- echo "we do indeed have an IOKit match and IOKIt is missing!!"
- echo "cp -r $IOKIT_MATCH $SDK_PATH/System/Library/Frameworks/"
- cp -r "$IOKIT_MATCH" "$SDK_PATH/System/Library/Frameworks/"
- fi
- fi
- }
- mkdirIfNecessary $ROOT_LOG_FOLDER
- # Ensure our SDK has all the required "extras" installed/setup
- prepSDK
- #buildBashAndFriends
- buildBasicUtils
- buildDPKGAndDependencies
- buildAPTAndDependencies
|