From ded58231fbad23ff41c5e18a91ce559459dc2885 Mon Sep 17 00:00:00 2001 From: Nick Chan Date: Sun, 5 Nov 2023 23:34:07 +0800 Subject: [PATCH] makefile structure changes --- .github/workflows/build.yml | 137 ++++++++++++++++++++------------ Makefile | 6 +- include/xxd-embedded.h | 2 +- src/Makefile | 108 +++++++++++++------------ src/gen/.gitignore | 1 + src/gen/resources | 1 + src/main.c | 2 +- src/obj/.gitignore | 1 + src/obj/gen | 1 + src/resources/.gitignore | 2 + src/tui_main.c | 5 ++ src/tui_screen_enter_dfu.c | 6 ++ src/tui_screen_enter_recovery.c | 6 ++ src/tui_screen_jailbreak.c | 6 ++ src/tui_screen_main.c | 6 ++ src/tui_screen_options.c | 6 ++ src/usb_iokit.c | 5 ++ src/usb_libusb.c | 3 + 18 files changed, 198 insertions(+), 106 deletions(-) create mode 100644 src/gen/.gitignore create mode 120000 src/gen/resources create mode 100644 src/obj/.gitignore create mode 120000 src/obj/gen create mode 100644 src/resources/.gitignore diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9a8c7c8..d9e007f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -36,8 +36,8 @@ jobs: - name: Build Documentation run: | make -j$(nproc) docs - mkdir ready - cp docs/*.html docs/mandoc.css docs/palera1n.1 ready + mkdir -p ready/docs + cp docs/*.html docs/mandoc.css docs/palera1n.1 ready/docs - name: Get branch name id: branch-name @@ -317,17 +317,25 @@ jobs: find dep_root -name '*.dylib' -delete find dep_root -name '*.la' -delete gmake -j$(sysctl -n hw.ncpu) - mkdir -p ready - mv src/palera1n palera1n-${{ matrix.os }}-${{ matrix.arch }} + cp src/palera1n palera1n-${{ matrix.os }}-${{ matrix.arch }} dsymutil palera1n-${{ matrix.os }}-${{ matrix.arch }} strip palera1n-${{ matrix.os }}-${{ matrix.arch }} + + - name: Build palera1n (Development) + run: | + CC="${{ matrix.triple }}-gcc" gmake -j$(sysctl -n hw.ncpu) clean + CC="${{ matrix.triple }}-gcc" gmake -j$(sysctl -n hw.ncpu) DEV_BUILD=1 TUI=1 ROOTFUL=1 + cp src/palera1n palera1n-${{ matrix.os }}-${{ matrix.arch }}.development + + - name: Prepare artifact + run: | + mkdir -p ready/build_depends + tar -zcf ready/build_depends/dep_root-${{ matrix.os }}-${{ matrix.arch }}.tgz dep_root if [ "${{ matrix.os }}" == "macosx" ]; then - ldid -S palera1n-${{ matrix.os }}-${{ matrix.arch }} + ldid -S palera1n-${{ matrix.os }}-${{ matrix.arch }}{,.development} else - ldid -Ssrc/usb.xml palera1n-${{ matrix.os }}-${{ matrix.arch }} + ldid -Ssrc/usb.xml palera1n-${{ matrix.os }}-${{ matrix.arch }}{,.development} fi - mkdir -p ready - tar -zcf ready/dep_root-${{ matrix.os }}-${{ matrix.arch }}.tgz dep_root - name: Get branch name id: branch-name @@ -354,6 +362,15 @@ jobs: path: palera1n-${{ matrix.os }}-${{ matrix.arch }} retention-days: 1 + - name: Upload ${{ matrix.os }} thin ${{ matrix.arch }} build (Development) + if: ${{ github.event_name != 'pull_request' }} + uses: actions/upload-artifact@v3 + with: + name: palera1n-${{ matrix.os }}-${{ matrix.arch }}.development + path: palera1n-${{ matrix.os }}-${{ matrix.arch }}.development + retention-days: 1 + + - name: Upload ${{ matrix.os }} thin ${{ matrix.arch }} debug symbols if: ${{ github.event_name != 'pull_request' }} uses: actions/upload-artifact@v3 @@ -384,18 +401,24 @@ jobs: - name: Prepare artifact run: | - find . lipo -create -arch arm64 ./palera1n-macosx-arm64/palera1n-macosx-arm64 -arch x86_64 ./palera1n-macosx-x86_64/palera1n-macosx-x86_64 -output palera1n-macos + lipo -create -arch arm64 ./palera1n-macosx-arm64.development/palera1n-macosx-arm64.development -arch x86_64 ./palera1n-macosx-x86_64.development/palera1n-macosx-x86_64.development -output palera1n-macos.development mkdir -p palera1n-macos.dSYM/Contents/Resources/DWARF cp ./palera1n-macosx-x86_64.dSYM/Contents/Info.plist palera1n-macos.dSYM/Contents lipo -create -arch arm64 palera1n-macosx-arm64.dSYM/Contents/Resources/DWARF/palera1n-macosx-arm64 -arch x86_64 palera1n-macosx-x86_64.dSYM/Contents/Resources/DWARF/palera1n-macosx-x86_64 -output palera1n-macos.dSYM/Contents/Resources/DWARF/palera1n-macos - mkdir ready - cp palera1n-macos ready/palera1n-macos-universal - cp ./palera1n-macosx-x86_64/palera1n-macosx-x86_64 ready/palera1n-macos-x86_64 - cp ./palera1n-macosx-arm64/palera1n-macosx-arm64 ready/palera1n-macos-arm64 - cp ./palera1n-iphoneos-arm64/palera1n-iphoneos-arm64 ready/palera1n-iphoneos-arm64 - zip -r9 ready/palera1n-iphoneos-arm64.dSYM.zip palera1n-iphoneos-arm64.dSYM - zip -r9 ready/palera1n-macos.dSYM.zip palera1n-macos.dSYM + mkdir -p ready/{debian,binaries,debug_symbols,binaries_development} + cp palera1n-macos.development ready/binaries_development/palera1n-macos-universal.development + cp palera1n-macos ready/binaries/palera1n-macos-universal + cp ./palera1n-macosx-x86_64/palera1n-macosx-x86_64 ready/binaries/palera1n-macos-x86_64 + cp ./palera1n-macosx-arm64/palera1n-macosx-arm64 ready/binaries/palera1n-macos-arm64 + cp ./palera1n-iphoneos-arm64/palera1n-iphoneos-arm64 ready/binaries/palera1n-iphoneos-arm64 + cp ./palera1n-macosx-x86_64.development/palera1n-macosx-x86_64.development ready/binaries_development/palera1n-macos-x86_64.development + cp ./palera1n-macosx-arm64.development/palera1n-macosx-arm64.development ready/binaries_development/palera1n-macos-arm64.development + cp ./palera1n-iphoneos-arm64.development/palera1n-iphoneos-arm64.development ready/binaries_development/palera1n-iphoneos-arm64.development + zip -r9 ready/debug_symbols/palera1n-iphoneos-arm64.dSYM.zip palera1n-iphoneos-arm64.dSYM + zip -r9 ready/debug_symbols/palera1n-macosx-arm64.dSYM.zip palera1n-macosx-arm64.dSYM + zip -r9 ready/debug_symbols/palera1n-macosx-x86_64.dSYM.zip palera1n-macosx-x86_64.dSYM + zip -r9 ready/debug_symbols/palera1n-macos.dSYM.zip palera1n-macos.dSYM - name: Build debs run: | @@ -411,12 +434,12 @@ jobs: gsed 's|@DEB_ARCH@|darwin-amd64|g' -i stage/DEBIAN/control gsed "s|@DEB_VERSION@|$version|g" -i stage/DEBIAN/control - ginstall -Dm644 ready/palera1n-macos-x86_64 stage/opt/procursus/bin/palera1n - ginstall -Dm644 docs/palera1n.1 stage/opt/procursus/usr/share/man/man1/palera1n.1 - chmod +x stage/opt/procursus/bin/palera1n + ginstall -Dm644 ready/binaries/palera1n-macos-x86_64 stage/opt/procursus/bin/palera1n + zstd -c19 docs/palera1n.1 > stage/opt/procursus/usr/share/man/man1/palera1n.1.zst + chmod 644 stage/opt/procursus/usr/share/man/man1/palera1n.1.zst + chmod 755 stage/opt/procursus/bin/palera1n - dpkg-deb -Zzstd -b stage palera1n_darwin-amd64.deb - mv palera1n*.deb ready/ + dpkg-deb --root-owner-group -Zzstd -b stage palera1n_darwin-amd64.deb rm -rf stage # Darwin arm64 @@ -428,12 +451,12 @@ jobs: gsed 's|@DEB_ARCH@|darwin-arm64|g' -i stage/DEBIAN/control gsed "s|@DEB_VERSION@|$version|g" -i stage/DEBIAN/control - ginstall -Dm644 ready/palera1n-macos-arm64 stage/opt/procursus/bin/palera1n - ginstall -Dm644 docs/palera1n.1 stage/opt/procursus/usr/share/man/man1/palera1n.1 - chmod +x stage/opt/procursus/bin/palera1n + ginstall -Dm644 ready/binaries/palera1n-macos-arm64 stage/opt/procursus/bin/palera1n + zstd -c19 docs/palera1n.1 > stage/opt/procursus/usr/share/man/man1/palera1n.1.zst + chmod 644 stage/opt/procursus/usr/share/man/man1/palera1n.1.zst + chmod 755 stage/opt/procursus/bin/palera1n - dpkg-deb -Zzstd -b stage palera1n_darwin-arm64.deb - mv palera1n*.deb ready/ + dpkg-deb --root-owner-group -Zzstd -b stage palera1n_darwin-arm64.deb rm -rf stage # iPhoneOS @@ -445,12 +468,12 @@ jobs: gsed 's|@DEB_ARCH@|iphoneos-arm|g' -i stage/DEBIAN/control gsed "s|@DEB_VERSION@|$version|g" -i stage/DEBIAN/control - ginstall -Dm644 ready/palera1n-iphoneos-arm64 stage/usr/bin/palera1n - ginstall -Dm644 docs/palera1n.1 stage/usr/share/man/man1/palera1n.1 - chmod +x stage/usr/bin/palera1n + ginstall -Dm644 ready/binaries/palera1n-iphoneos-arm64 stage/usr/bin/palera1n + zstd -c19 docs/palera1n.1 > stage/usr/share/man/man1/palera1n.1.zst + chmod 644 stage/usr/share/man/man1/palera1n.1.zst + chmod 755 stage/usr/bin/palera1n - dpkg-deb -Zzstd -b stage palera1n_iphoneos-arm.deb - mv palera1n*.deb ready/ + dpkg-deb --root-owner-group -Zzstd -b stage palera1n_iphoneos-arm.deb rm -rf stage # iPhoneOS (rootless) @@ -462,13 +485,15 @@ jobs: gsed 's|@DEB_ARCH@|iphoneos-arm64|g' -i stage/DEBIAN/control gsed "s|@DEB_VERSION@|$version|g" -i stage/DEBIAN/control - ginstall -Dm644 ready/palera1n-iphoneos-arm64 stage/var/jb/usr/bin/palera1n - ginstall -Dm644 docs/palera1n.1 stage/var/jb/usr/share/man/man1/palera1n.1 - chmod +x stage/var/jb/usr/bin/palera1n + ginstall -Dm644 ready/binaries/palera1n-iphoneos-arm64 stage/var/jb/usr/bin/palera1n + zstd -c19 docs/palera1n.1 > stage/var/jb/usr/share/man/man1/palera1n.1.zst + chmod 644 stage/var/jb/usr/share/man/man1/palera1n.1.zst + chmod 755 stage/var/jb/usr/bin/palera1n - dpkg-deb -Zzstd -b stage palera1n_iphoneos-arm64.deb - mv palera1n*.deb ready/ + dpkg-deb --root-owner-group -Zzstd -b stage palera1n_iphoneos-arm64.deb rm -rf stage + + mv palera1n*.deb ready/debian - name: Save build tag run: echo "$(git describe --dirty --tags --abbrev=7 | sed 's|-dirty||')" > build-tag.txt @@ -774,20 +799,28 @@ jobs: find dep_root -name '*.so' -delete find dep_root -name '*.la' -delete CC="${{ matrix.triple }}-gcc" make -j$(nproc) + cp src/palera1n palera1n.release - name: Seperate debug symbols run: | - ${{ matrix.triple }}-objcopy --only-keep-debug src/palera1n palera1n.debug - ${{ matrix.triple }}-strip --strip-debug --strip-unneeded src/palera1n - ${{ matrix.triple }}-objcopy --add-gnu-debuglink=palera1n.debug src/palera1n + ${{ matrix.triple }}-objcopy --only-keep-debug palera1n.release palera1n.debug + ${{ matrix.triple }}-strip --strip-debug --strip-unneeded palera1n.release + ${{ matrix.triple }}-objcopy --add-gnu-debuglink=palera1n.debug palera1n.release chmod -x palera1n.debug + + - name: Build palera1n (Development) + run: | + CC="${{ matrix.triple }}-gcc" make -j$(nproc) clean + CC="${{ matrix.triple }}-gcc" make -j$(nproc) DEV_BUILD=1 TUI=1 ROOTFUL=1 + cp src/palera1n palera1n.development - name: Prepare artifact run: | - mkdir ready usbmuxd-static - mv palera1n.debug ready/palera1n-${{ env.CHECKRA1N_NAME }}.debug - mv src/palera1n ready/palera1n-${{ env.CHECKRA1N_NAME }} - tar -zcf ready/dep_root_${{ matrix.triple }}.tgz dep_root + mkdir -p ready/{binaries,debian,binaries_development,build_depends,debug_symbols} usbmuxd-static + mv palera1n.debug ready/debug_symbols/palera1n-${{ env.CHECKRA1N_NAME }}.debug + mv palera1n.release ready/binaries/palera1n-${{ env.CHECKRA1N_NAME }} + mv palera1n.development ready/binaries_development/palera1n-${{ env.CHECKRA1N_NAME }}.development + tar -zcf ready/build_depends/dep_root_${{ matrix.triple }}.tgz dep_root install -m755 sysroot/${{ env.PREFIX }}/sbin/usbmuxd usbmuxd-static/usbmuxd-${{ env.CHECKRA1N_NAME }} install -m755 sysroot/${{ env.PREFIX }}/sbin/usbmuxd.debug usbmuxd-static/usbmuxd-${{ env.CHECKRA1N_NAME }}.debug @@ -804,12 +837,13 @@ jobs: sed 's|@DEB_ARCH@|${{ env.ARCH_NAME }}|g' -i stage/DEBIAN/control sed "s|@DEB_VERSION@|$version|g" -i stage/DEBIAN/control - install -Dm644 ready/palera1n-${{ env.CHECKRA1N_NAME }} stage/usr/bin/palera1n - install -Dm644 docs/palera1n.1 stage/usr/share/man/man1/palera1n.1 - chmod +x stage/usr/bin/palera1n + install -Dm644 ready/binaries/palera1n-${{ env.CHECKRA1N_NAME }} stage/usr/bin/palera1n + gzip -c9 docs/palera1n.1 > stage/usr/share/man/man1/palera1n.1.gz + chmod 755 stage/usr/bin/palera1n + chmod 644 stage/usr/share/man/man1/palera1n.1.gz - dpkg-deb -b stage palera1n_${{ env.ARCH_NAME }}.deb - mv palera1n*.deb ready/ + dpkg-deb --root-owner-group -b stage palera1n_${{ env.ARCH_NAME }}.deb + mv palera1n*.deb ready/debian rm -rf stage - name: Get branch name @@ -859,8 +893,13 @@ jobs: with: name: build-tag + - uses: geekyeggo/delete-artifact@v2 + with: + name: '*' + failOnError: false + - name: Send Discord build message run: | COMMITMESSAGE=`git log --pretty=format:'- \`%h\` %s' -1 --reverse` && - (curl "${{ secrets.DISCORD_WEBHOOK }}" -sS -H "Content-Type:application/json" -X POST -d "{\"content\":null,\"embeds\":[{\"title\":\"[palera1n:${{ steps.branch-name.outputs.ref_branch }}] Nightly Build ${{ github.run_number }}\",\"url\":\"https://github.com/palera1n/palera1n/actions/runs/${GITHUB_RUN_ID}\",\"color\":2829617,\"fields\":[{\"name\":\"Build tag\",\"value\":\"- \`$(cat build-tag.txt | sed 's|\n||')\`\"},{\"name\":\"Destination\",\"value\":\"- https://cdn.nickchan.lol/palera1n/artifacts/c-rewrite/${{ steps.branch-name.outputs.ref_branch }}/${{ github.run_number }}\"},{\"name\":\"Documentation\",\"value\":\"- [palera1n.1.html](https://cdn.nickchan.lol/palera1n/artifacts/c-rewrite/${{ steps.branch-name.outputs.ref_branch }}/${{ github.run_number }}/palera1n.1.html)\"},{\"name\":\"Main Artifacts\",\"value\":\"- [palera1n-iphoneos-arm64](https://cdn.nickchan.lol/palera1n/artifacts/c-rewrite/${{ steps.branch-name.outputs.ref_branch }}/${{ github.run_number }}/palera1n-iphoneos-arm64)\n- [palera1n-linux-arm64](https://cdn.nickchan.lol/palera1n/artifacts/c-rewrite/${{ steps.branch-name.outputs.ref_branch }}/${{ github.run_number }}/palera1n-linux-arm64)\n- [palera1n-linux-armel](https://cdn.nickchan.lol/palera1n/artifacts/c-rewrite/${{ steps.branch-name.outputs.ref_branch }}/${{ github.run_number }}/palera1n-linux-armel)\n- [palera1n-linux-x86](https://cdn.nickchan.lol/palera1n/artifacts/c-rewrite/$${{ steps.branch-name.outputs.ref_branch }}/${{ github.run_number }}/palera1n-linux-x86)\n- [palera1n-linux-x86_64](https://cdn.nickchan.lol/palera1n/artifacts/c-rewrite/${{ steps.branch-name.outputs.ref_branch }}/${{ github.run_number }}/palera1n-linux-x86_64)\n- [palera1n-macos-universal](https://cdn.nickchan.lol/palera1n/artifacts/c-rewrite/${{ steps.branch-name.outputs.ref_branch }}/${{ github.run_number }}/palera1n-macos-universal)\"}],\"footer\":{\"text\":\"${{ github.actor }}\", \"icon_url\": \"https://github.com/${{ github.actor }}.png\",\"timestamp\":\"$(date -u +"%FT%TZ")\"}}],\"username\":\"GitHub Actions\",\"avatar_url\":\"https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png\"}") + (curl "${{ secrets.DISCORD_WEBHOOK }}" -sS -H "Content-Type:application/json" -X POST -d "{\"content\":null,\"embeds\":[{\"title\":\"[palera1n:${{ steps.branch-name.outputs.ref_branch }}] Nightly Build ${{ github.run_number }}\",\"url\":\"https://github.com/palera1n/palera1n/actions/runs/${GITHUB_RUN_ID}\",\"color\":2829617,\"fields\":[{\"name\":\"Build tag\",\"value\":\"- \`$(cat build-tag.txt | sed 's|\n||')\`\"},{\"name\":\"Destination\",\"value\":\"- https://cdn.nickchan.lol/palera1n/artifacts/c-rewrite/${{ steps.branch-name.outputs.ref_branch }}/${{ github.run_number }}\"},{\"name\":\"Documentation\",\"value\":\"- [palera1n.1.html](https://cdn.nickchan.lol/palera1n/artifacts/c-rewrite/${{ steps.branch-name.outputs.ref_branch }}/${{ github.run_number }}/docs/palera1n.1.html)\"},{\"name\":\"Main Artifacts\",\"value\":\"- [palera1n-iphoneos-arm64](https://cdn.nickchan.lol/palera1n/artifacts/c-rewrite/${{ steps.branch-name.outputs.ref_branch }}/${{ github.run_number }}/binaries/palera1n-iphoneos-arm64)\n- [palera1n-linux-arm64](https://cdn.nickchan.lol/palera1n/artifacts/c-rewrite/${{ steps.branch-name.outputs.ref_branch }}/${{ github.run_number }}/binaries/palera1n-linux-arm64)\n- [palera1n-linux-armel](https://cdn.nickchan.lol/palera1n/artifacts/c-rewrite/${{ steps.branch-name.outputs.ref_branch }}/${{ github.run_number }}/binaries/palera1n-linux-armel)\n- [palera1n-linux-x86](https://cdn.nickchan.lol/palera1n/artifacts/c-rewrite/${{ steps.branch-name.outputs.ref_branch }}/${{ github.run_number }}/binaries/palera1n-linux-x86)\n- [palera1n-linux-x86_64](https://cdn.nickchan.lol/palera1n/artifacts/c-rewrite/${{ steps.branch-name.outputs.ref_branch }}/${{ github.run_number }}/binaries/palera1n-linux-x86_64)\n- [palera1n-macos-universal](https://cdn.nickchan.lol/palera1n/artifacts/c-rewrite/${{ steps.branch-name.outputs.ref_branch }}/${{ github.run_number }}/binaries/palera1n-macos-universal)\"}],\"footer\":{\"text\":\"${{ github.actor }}\", \"icon_url\": \"https://github.com/${{ github.actor }}.png\",\"timestamp\":\"$(date -u +"%FT%TZ")\"}}],\"username\":\"GitHub Actions\",\"avatar_url\":\"https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png\"}") diff --git a/Makefile b/Makefile index a1b96a8..c27631a 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ SRC = $(shell pwd) DEP = $(SRC)/dep_root STRIP = strip CC ?= cc -CFLAGS += -I$(DEP)/include -I$(SRC)/include -I$(SRC) -D_XOPEN_SOURCE=500 +CFLAGS += -isystem $(DEP)/include -I$(SRC)/include -I$(SRC) -D_XOPEN_SOURCE=500 CFLAGS += -Wall -Wextra -Wno-unused-parameter -DPALERAIN_VERSION=\"2.0.0\" CFLAGS += -Wno-unused-variable -I$(SRC)/src -std=c99 -pedantic-errors -D_C99_SOURCE -D_POSIX_C_SOURCE=200112L LIBS += $(DEP)/lib/libimobiledevice-1.0.a $(DEP)/lib/libirecovery-1.0.a $(DEP)/lib/libusbmuxd-2.0.a @@ -74,13 +74,13 @@ clean: $(MAKE) -C docs clean download-deps: - $(MAKE) -C src checkra1n-macos checkra1n-linux-arm64 checkra1n-linux-armel checkra1n-linux-x86 checkra1n-linux-x86_64 checkra1n-kpf-pongo ramdisk.dmg binpack.dmg Pongo.bin + $(MAKE) -C src $(patsubst %, resources/%, checkra1n-macos checkra1n-linux-arm64 checkra1n-linux-armel checkra1n-linux-x86 checkra1n-linux-x86_64 checkra1n-kpf-pongo ramdisk.dmg binpack.dmg Pongo.bin) docs: $(MAKE) -C docs distclean: clean - rm -rf palera1n-* palera1n*.dSYM src/checkra1n-* src/checkra1n-kpf-pongo src/ramdisk.dmg src/binpack.dmg src/Pongo.bin + $(MAKE) -C src distclean .PHONY: all palera1n clean docs distclean diff --git a/include/xxd-embedded.h b/include/xxd-embedded.h index ef04123..2c1b44a 100644 --- a/include/xxd-embedded.h +++ b/include/xxd-embedded.h @@ -20,7 +20,7 @@ extern unsigned int binpack_dmg_len; extern unsigned char Pongo_bin[]; extern unsigned int Pongo_bin_len; -#if defined(__APPLE__) && (TARGET_OS_IPHONE || defined(DEV_BUILD)) +#if defined(__APPLE__) && (TARGET_OS_IPHONE || defined(DEV_BUILD) || defined(FORCE_HELPER)) extern unsigned char libcheckra1nhelper_dylib[]; extern unsigned int libcheckra1nhelper_dylib_len; #endif diff --git a/src/Makefile b/src/Makefile index 273eaf9..d276616 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,57 +1,57 @@ all: palera1n -OBJECTS = main.o dfuhelper.o devhelper.o lockdown_helper.o -OBJECTS += optparse.o override_file.o log.o lock_vars.o credits.o -OBJECTS += fake_embedded.o exec_checkra1n.o pongo_helper.o -OBJECTS += boyermoore_memmem.o +OBJDIR = obj +GENDIR = gen +RESOURCES_DIR = resources + +C_SRC = $(wildcard *.c) +OBJS = $(patsubst %,$(OBJDIR)/%,$(C_SRC:.c=.c.o)) ifeq (,$(findstring macosx, $(CFLAGS))) ifneq (,$(findstring version-min=, $(CFLAGS))) -OBJECTS += xxd-libcheckra1nhelper.dylib.o +C_SRC += $(GENDIR)/gen-libcheckra1nhelper.dylib.c endif endif ifeq ($(FORCE_HELPER),1) -OBJECTS += xxd-libcheckra1nhelper.dylib.o +C_SRC += $(GENDIR)/gen-libcheckra1nhelper.dylib.c CFLAGS += -DFORCE_HELPER BUILD_OPTIONS += FORCE_HELPER endif ifneq ($(NO_RAMDISK),1) -OBJECTS += xxd-ramdisk.dmg.lzma.o +C_SRC += $(GENDIR)/gen-ramdisk.dmg.lzma.c else CFLAGS += -DNO_RAMDISK -DRAMDISK_COMPRESSED_SIZE=\"0\" BUILD_OPTIONS += NO_RAMDISK endif ifneq ($(NO_KPF),1) -OBJECTS += xxd-checkra1n-kpf-pongo.lzma.o +C_SRC += $(GENDIR)/gen-checkra1n-kpf-pongo.lzma.c else CFLAGS += -DNO_KPF BUILD_OPTIONS += NO_KPF endif ifneq ($(NO_OVERLAY),1) -OBJECTS += xxd-binpack.dmg.o +C_SRC += $(GENDIR)/gen-binpack.dmg.c else CFLAGS += -DNO_OVERLAY BUILD_OPTIONS += NO_OVERLAY endif ifneq ($(NO_CHECKRAIN),1) -OBJECTS += xxd-checkra1n.o +C_SRC += $(GENDIR)/gen-checkra1n.c else CFLAGS += -DNO_CHECKRAIN BUILD_OPTIONS += NO_CHECKRAIN endif ifneq ($(NO_CUSTOM_PONGO),1) -OBJECTS += xxd-Pongo.bin.o +C_SRC += $(GENDIR)/gen-Pongo.bin.c else CFLAGS += -DNO_CUSTOM_PONGO BUILD_OPTIONS += NO_CUSTOM_PONGO endif ifeq ($(TUI),1) -OBJECTS += tui_screen_enter_recovery.o tui_screen_enter_dfu.o tui_main.o -OBJECTS += tui_screen_jailbreak.o tui_screen_main.o tui_screen_options.o BUILD_OPTIONS += TUI CFLAGS += -DTUI endif @@ -62,20 +62,18 @@ LDID = ldid ifeq ($(TARGET_OS),Darwin) ifneq ($(USE_LIBUSB),1) -OBJECTS += usb_iokit.o else LIBS += -framework SystemConfiguration -framework Security BUILD_OPTIONS += USE_LIBUSB endif # add lto and debug symbols for lto CFLAGS += -flto=full -g -LDFLAGS += -Wl,-object_path_lto,lto.o +LDFLAGS += -Wl,-object_path_lto,obj/lto.o else USE_LIBUSB = 1 endif ifeq ($(USE_LIBUSB),1) -OBJECTS += usb_libusb.o CFLAGS += -DUSE_LIBUSB=1 LIBS += $(DEP)/lib/libusb-1.0.a endif @@ -91,73 +89,79 @@ endif CFLAGS += -DBUILD_OPTIONS=\""$(BUILD_OPTIONS)"\" -checkra1n-%: - curl -LO https://assets.checkra.in/downloads/preview/$(CHECKRA1N_VERSION)/$@ +$(RESOURCES_DIR)/checkra1n-%: + curl -Lfo $@ https://assets.checkra.in/downloads/preview/$(CHECKRA1N_VERSION)/$$(echo $@ | cut -d/ -f2) chmod 755 $@ -checkra1n: checkra1n-macos usb.xml +$(RESOURCES_DIR)/checkra1n: $(RESOURCES_DIR)/checkra1n-macos usb.xml ifeq ($(TARGET_OS),Darwin) ifneq (,$(findstring arm64, $(CFLAGS))) - $(LIPO) -thin arm64 -output checkra1n checkra1n-macos + $(LIPO) -thin arm64 -output $(RESOURCES_DIR)/checkra1n $(RESOURCES_DIR)/checkra1n-macos else ifneq (,$(findstring x86_64, $(CFLAGS))) - $(LIPO) -thin x86_64 -output checkra1n checkra1n-macos + $(LIPO) -thin x86_64 -output $(RESOURCES_DIR)/checkra1n $(RESOURCES_DIR)/checkra1n-macos else ifeq ($(shell arch),i386) - $(LIPO) -thin x86_64 -output checkra1n checkra1n-macos + $(LIPO) -thin x86_64 -output $(RESOURCES_DIR)/checkra1n $(RESOURCES_DIR)/checkra1n-macos else - $(LIPO) -thin $(shell arch) -output checkra1n checkra1n-macos + $(LIPO) -thin $(shell arch) -output $(RESOURCES_DIR)/checkra1n $(RESOURCES_DIR)/checkra1n-macos endif ifeq (,$(findstring macosx, $(CFLAGS))) ifneq (,$(findstring version-min=, $(CFLAGS))) - vtool -remove-build-version 1 -replace -output checkra1n checkra1n - vtool -set-build-version $(FAKE_PLATFORM) $(FAKE_MINOS) $(FAKE_SDK) -replace -output checkra1n checkra1n - install_name_tool -change /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit /System/Library/Frameworks/IOKit.framework/IOKit checkra1n - install_name_tool -change /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation checkra1n - $(LDID) -Susb.xml checkra1n + vtool -remove-build-version 1 -replace -output $(RESOURCES_DIR)/checkra1n $(RESOURCES_DIR)/checkra1n + vtool -set-build-version $(FAKE_PLATFORM) $(FAKE_MINOS) $(FAKE_SDK) -replace -output $(RESOURCES_DIR)/checkra1n $(RESOURCES_DIR)/checkra1n + install_name_tool -change /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit /System/Library/Frameworks/IOKit.framework/IOKit $(RESOURCES_DIR)/checkra1n + install_name_tool -change /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation $(RESOURCES_DIR)/checkra1n + $(LDID) -Susb.xml $(RESOURCES_DIR)/checkra1n endif endif else - cp checkra1n-$(CHECKRA1N_NAME) checkra1n + cp $(RESOURCES_DIR)/checkra1n-$(CHECKRA1N_NAME) $(RESOURCES_DIR)/checkra1n endif -xxd-%.c: % - xxd -iC $< > $@ +$(GENDIR)/gen-%.c: $(RESOURCES_DIR)/% + cd $(RESOURCES_DIR) && xxd -iC $$(echo $< | cut -d/ -f2) > ../$@ -pongo_helper.o: pongo_helper.c $(wildcard ../include/*.h) ramdisk.dmg checkra1n-kpf-pongo - $(CC) -c $(CFLAGS) -DRAMDISK_UNCOMPRESSED_SIZE="\"$$(wc -c < ramdisk.dmg | tr -d ' ')\"" -DKPF_UNCOMPRESSED_SIZE="\"$$(wc -c < checkra1n-kpf-pongo | tr -d ' ')\"" $< +$(OBJDIR)/pongo_helper.c.o: pongo_helper.c $(wildcard ../include/*.h) $(RESOURCES_DIR)/ramdisk.dmg $(RESOURCES_DIR)/checkra1n-kpf-pongo + $(CC) -c -o $@ $(CFLAGS) -DRAMDISK_UNCOMPRESSED_SIZE="\"$$(wc -c < $(RESOURCES_DIR)/ramdisk.dmg | tr -d ' ')\"" -DKPF_UNCOMPRESSED_SIZE="\"$$(wc -c < $(RESOURCES_DIR)/checkra1n-kpf-pongo | tr -d ' ')\"" $< -%.o: %.c $(wildcard ../include/*.h) - $(CC) -c $(CFLAGS) $< +$(OBJDIR)/%.c.o: $(GENDIR)/gen-%.c $(wildcard ../include/*.h) + $(CC) $(CFLAGS) -c -o $< -palera1n: $(OBJECTS) - $(CC) $(CFLAGS) $(LDFLAGS) $(OBJECTS) $(LIBS) -o palera1n +$(OBJDIR)/%.c.o: %.c $(wildcard ../include/*.h) + $(CC) $(CFLAGS) -c -o $@ $< + +palera1n: $(OBJS) + $(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) $(LIBS) -o palera1n ifeq (,$(findstring macosx, $(CFLAGS))) ifneq (,$(findstring version-min=, $(CFLAGS))) $(LDID) -Susb.xml palera1n endif endif -libcheckra1nhelper.dylib: chkstk.S - $(CC) $(CFLAGS) $(LDFLAGS) -shared chkstk.S -o libcheckra1nhelper.dylib +$(RESOURCES_DIR)/libcheckra1nhelper.dylib: chkstk.S + $(CC) $(CFLAGS) $(LDFLAGS) -shared chkstk.S -o $@ -checkra1n-kpf-pongo: - curl -LO https://cdn.nickchan.lol/palera1n/artifacts/kpf/iOS15/checkra1n-kpf-pongo +$(RESOURCES_DIR)/checkra1n-kpf-pongo: + curl -Lfo $@ https://cdn.nickchan.lol/palera1n/artifacts/kpf/iOS15/checkra1n-kpf-pongo -%.lzma: % - xz --format=lzma -vf6ekT 0 $< +$(RESOURCES_DIR)/ramdisk.dmg.lzma: $(RESOURCES_DIR)/ramdisk.dmg + xz --format=lzma -vfc6ekT 0 $< > $@ -checkra1n-kpf-pongo.lzma: checkra1n-kpf-pongo - xz --format=lzma -vf6ekT 0 checkra1n-kpf-pongo +$(RESOURCES_DIR)/checkra1n-kpf-pongo.lzma: $(RESOURCES_DIR)/checkra1n-kpf-pongo + xz --format=lzma -vfc6ekT 0 $< > $@ -ramdisk.dmg: - curl -LO https://cdn.nickchan.lol/palera1n/c-rewrite/deps/ramdisk.dmg +$(RESOURCES_DIR)/ramdisk.dmg: + curl -Lfo $@ https://cdn.nickchan.lol/palera1n/c-rewrite/deps/ramdisk.dmg -binpack.dmg: - curl -LO https://cdn.nickchan.lol/palera1n/c-rewrite/deps/binpack.dmg +$(RESOURCES_DIR)/binpack.dmg: + curl -Lfo $@ https://cdn.nickchan.lol/palera1n/c-rewrite/deps/binpack.dmg -Pongo.bin: - curl -LO https://cdn.nickchan.lol/palera1n/artifacts/kpf/iOS15/Pongo.bin +$(RESOURCES_DIR)/Pongo.bin: + curl -Lfo $@ https://cdn.nickchan.lol/palera1n/artifacts/kpf/iOS15/Pongo.bin clean: - rm -rf *.o palera1n checkra1n checkra1n.c palera1n.dSYM ramdisk.dmg.lzma libcheckra1nhelper.dylib + rm -rf $(OBJDIR)/*.o $(GENDIR)/*.c $(GENDIR)/*.o palera1n palera1n.dSYM libcheckra1nhelper.dylib + +distclean: clean + rm -rf $(RESOURCES_DIR)/* .PHONY: all clean diff --git a/src/gen/.gitignore b/src/gen/.gitignore new file mode 100644 index 0000000..5761abc --- /dev/null +++ b/src/gen/.gitignore @@ -0,0 +1 @@ +*.o diff --git a/src/gen/resources b/src/gen/resources new file mode 120000 index 0000000..945c9b4 --- /dev/null +++ b/src/gen/resources @@ -0,0 +1 @@ +. \ No newline at end of file diff --git a/src/main.c b/src/main.c index b49368c..2d85940 100644 --- a/src/main.c +++ b/src/main.c @@ -122,7 +122,7 @@ int palera1n(int argc, char *argv[]) { if (!(palerain_flags & palerain_option_device_info)) LOG(LOG_INFO, "Waiting for devices"); - if (access("/var/run/usbmuxd", F_OK) != 0) + if (getenv("USBMUXD_SOCKET_ADDRESS") == NULL && access("/var/run/usbmuxd", F_OK) != 0) LOG(LOG_WARNING, "/var/run/usbmuxd not found, normal mode device detection will not work."); pthread_create(&pongo_thread, NULL, pongo_helper, NULL); diff --git a/src/obj/.gitignore b/src/obj/.gitignore new file mode 100644 index 0000000..5761abc --- /dev/null +++ b/src/obj/.gitignore @@ -0,0 +1 @@ +*.o diff --git a/src/obj/gen b/src/obj/gen new file mode 120000 index 0000000..945c9b4 --- /dev/null +++ b/src/obj/gen @@ -0,0 +1 @@ +. \ No newline at end of file diff --git a/src/resources/.gitignore b/src/resources/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/src/resources/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/src/tui_main.c b/src/tui_main.c index 8086122..64e49a0 100644 --- a/src/tui_main.c +++ b/src/tui_main.c @@ -1,3 +1,4 @@ +#ifdef TUI #include #include #include @@ -99,3 +100,7 @@ out: tui_started = false; return 0; } +#else +/* ISO C forbids an empty translation unit */ +extern char** environ; +#endif diff --git a/src/tui_screen_enter_dfu.c b/src/tui_screen_enter_dfu.c index 92d3db3..f6ef518 100644 --- a/src/tui_screen_enter_dfu.c +++ b/src/tui_screen_enter_dfu.c @@ -1,3 +1,4 @@ +#ifdef TUI #include #include #include @@ -13,3 +14,8 @@ #include tui_screen_t tui_screen_enter_dfu(void) { return JAILBREAKING_SCREEN; } + +#else +/* ISO C forbids an empty translation unit */ +extern char** environ; +#endif diff --git a/src/tui_screen_enter_recovery.c b/src/tui_screen_enter_recovery.c index db07ca8..f1e1d5f 100644 --- a/src/tui_screen_enter_recovery.c +++ b/src/tui_screen_enter_recovery.c @@ -1,3 +1,4 @@ +#ifdef TUI #include #include #include @@ -13,3 +14,8 @@ #include tui_screen_t tui_screen_enter_recovery(void) { return ENTER_DFU_SCREEN; } + +#else +/* ISO C forbids an empty translation unit */ +extern char** environ; +#endif diff --git a/src/tui_screen_jailbreak.c b/src/tui_screen_jailbreak.c index 6d6e453..c533180 100644 --- a/src/tui_screen_jailbreak.c +++ b/src/tui_screen_jailbreak.c @@ -1,3 +1,4 @@ +#ifdef TUI #include #include #include @@ -13,3 +14,8 @@ #include tui_screen_t tui_screen_jailbreak(void) { return EXIT_SCREEN; } + +#else +/* ISO C forbids an empty translation unit */ +extern char** environ; +#endif diff --git a/src/tui_screen_main.c b/src/tui_screen_main.c index d3e614a..c74f9ad 100644 --- a/src/tui_screen_main.c +++ b/src/tui_screen_main.c @@ -1,3 +1,4 @@ +#ifdef TUI #include #include #include @@ -45,3 +46,8 @@ tui_screen_t tui_screen_main(void) { newtFormDestroy(form); return ret; } + +#else +/* ISO C forbids an empty translation unit */ +extern char** environ; +#endif diff --git a/src/tui_screen_options.c b/src/tui_screen_options.c index e00eaff..e5f17d2 100644 --- a/src/tui_screen_options.c +++ b/src/tui_screen_options.c @@ -1,3 +1,4 @@ +#ifdef TUI #include #include #include @@ -73,3 +74,8 @@ tui_screen_t tui_screen_options(void) { newtFormDestroy(form); return ret; } + +#else +/* ISO C forbids an empty translation unit */ +extern char** environ; +#endif diff --git a/src/usb_iokit.c b/src/usb_iokit.c index 3481939..59cf59a 100644 --- a/src/usb_iokit.c +++ b/src/usb_iokit.c @@ -24,6 +24,7 @@ * SOFTWARE. * */ +#ifndef USE_LIBUSB #include #include // open #include @@ -250,3 +251,7 @@ int wait_for_pongo(void) { CFRelease(cfdict); return 0; } +#else +/* ISO C forbids an empty translation unit */ +extern char** environ; +#endif diff --git a/src/usb_libusb.c b/src/usb_libusb.c index 3685379..1e8696c 100644 --- a/src/usb_libusb.c +++ b/src/usb_libusb.c @@ -264,4 +264,7 @@ int wait_for_pongo(void) libusb_exit(ctx); return 0; } +#else +/* ISO C forbids an empty translation unit */ +extern char** environ; #endif