| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <unistd.h>
- #include <sys/stat.h>
- #include <dirent.h>
- #include "ark_parser.h"
- void run_cmd(const char* cmd) {
- printf("Executing: %s\n", cmd);
- int ret = system(cmd);
- if(ret != 0) {
- printf("Command failed: %s\n", cmd);
- }
- }
- int main() {
- const char* base_dir = "/home/arkos/arkos";
- const char* out_dir = "/home/arkos/arkos/finished";
- const char* staging_sys = "/home/arkos/arkos/out_staging/system";
- const char* staging_vend = "/home/arkos/arkos/out_staging/vendor";
- const char* staging_boot = "/home/arkos/arkos/out_staging/boot";
- printf("Cleaning up previous build directories...\n");
- run_cmd("rm -rf /home/arkos/arkos/finished /home/arkos/arkos/out_staging");
- run_cmd("mkdir -p /home/arkos/arkos/finished /home/arkos/arkos/out_staging/system/frameworks /home/arkos/arkos/out_staging/vendor /home/arkos/arkos/out_staging/boot");
- printf("Phase 1: Frameworks Integration\n");
- DIR* d = opendir("/home/arkos/arkos/frameworks");
- if(d) {
- struct dirent* dir;
- while((dir = readdir(d)) != NULL) {
- if(strcmp(dir->d_name, ".") == 0 || strcmp(dir->d_name, "..") == 0) continue;
- if(strcmp(dir->d_name, "DRM") == 0 || strcmp(dir->d_name, "SwiftUIFramework") == 0) {
- printf("Skipping explicitly excluded framework: %s\n", dir->d_name);
- continue;
- }
- char cmd[512];
- snprintf(cmd, sizeof(cmd), "cp -r /home/arkos/arkos/frameworks/%s /home/arkos/arkos/out_staging/system/frameworks/", dir->d_name);
- run_cmd(cmd);
- }
- closedir(d);
- }
- printf("Phase 2: Boot Folder Perfectification\n");
- d = opendir("/home/arkos/arkos/boot");
- if(d) {
- struct dirent* dir;
- while((dir = readdir(d)) != NULL) {
- if(strcmp(dir->d_name, ".") == 0 || strcmp(dir->d_name, "..") == 0) continue;
- if(strcmp(dir->d_name, "DRM") == 0) {
- printf("Skipping boot/DRM folder\n");
- continue;
- }
- char cmd[512];
- snprintf(cmd, sizeof(cmd), "cp -r /home/arkos/arkos/boot/%s /home/arkos/arkos/out_staging/boot/", dir->d_name);
- run_cmd(cmd);
- }
- closedir(d);
- }
- printf("Phase 3: Vendor Folder Preparation\n");
- run_cmd("cp -r /home/arkos/arkos/vendor/* /home/arkos/arkos/out_staging/vendor/ 2>/dev/null || true");
- printf("Phase 4: Kernel Config Verification\n");
- if(access("/home/arkos/arkos/kernel/.config", F_OK) != -1) {
- printf("Kernel config found at /home/arkos/arkos/kernel/.config. Kernel is prepared.\n");
- } else {
- printf("WARNING: Kernel .config not found!\n");
- }
- printf("Phase 5: Prebuilts Tagging\n");
- run_cmd("mkdir -p /home/arkos/arkos/prebuilts");
- ArkConfig* prebuilts_ark = ark_parse("/home/arkos/arkos/prebuilts/prebuilts.ark");
- d = opendir("/home/arkos/src");
- if(d) {
- struct dirent* dir;
- while((dir = readdir(d)) != NULL) {
- char path[512];
- snprintf(path, sizeof(path), "/home/arkos/src/%s", dir->d_name);
- if(strstr(dir->d_name, "LLVM")) ark_set_global(prebuilts_ark, "LLVM", path);
- else if(strstr(dir->d_name, "Swift")) ark_set_global(prebuilts_ark, "Swift", path);
- else if(strstr(dir->d_name, "glibc")) ark_set_global(prebuilts_ark, "glibc", path);
- else if(strstr(dir->d_name, "linux-kernel")) ark_set_global(prebuilts_ark, "Kernel-Src", path);
- }
- closedir(d);
- }
- ark_dump(prebuilts_ark, "/home/arkos/arkos/prebuilts/prebuilts.ark");
- ark_free(prebuilts_ark);
- printf("Prebuilts tagged and mapped to /home/arkos/arkos/prebuilts/prebuilts.ark\n");
- printf("Phase 6: Image Generation\n");
- run_cmd("dd if=/dev/zero of=/home/arkos/arkos/finished/sys.img bs=1M count=2048");
- run_cmd("mkfs.ext4 -d /home/arkos/arkos/out_staging/system /home/arkos/arkos/finished/sys.img");
-
- run_cmd("dd if=/dev/zero of=/home/arkos/arkos/finished/vend.img bs=1M count=100");
- run_cmd("mkfs.ext4 -d /home/arkos/arkos/out_staging/vendor /home/arkos/arkos/finished/vend.img");
- run_cmd("dd if=/dev/zero of=/home/arkos/arkos/finished/boot.img bs=1M count=100");
- run_cmd("mkfs.ext4 -d /home/arkos/arkos/out_staging/boot /home/arkos/arkos/finished/boot.img");
- printf("Preparing Linux Kernel & Native Swift Initramfs...\n");
- // We use the host kernel since we haven't compiled the massive Linux kernel tree yet
- run_cmd("cp /boot/vmlinuz-linux-zen /home/arkos/arkos/finished/bzImage");
-
- // Compile Swift splash screen as static executable
- run_cmd("swiftc -static-executable /home/arkos/arkos/system/swift_splash.swift -o /home/arkos/arkos/system/swift_splash");
-
- // Compile C init wrapper
- run_cmd("gcc -static /home/arkos/arkos/system/init.c -o /home/arkos/arkos/system/init");
-
- // Pack into initramfs with glibc libraries
- run_cmd("rm -rf /tmp/extract_new && mkdir -p /tmp/extract_new");
- run_cmd("cd /tmp/extract_new && zcat /home/arkos/arkos/boot/initramfs.img | cpio -id 2>/dev/null");
- run_cmd("cp /home/arkos/arkos/system/init /tmp/extract_new/init && chmod +x /tmp/extract_new/init");
- run_cmd("cp /home/arkos/arkos/system/swift_splash /tmp/extract_new/swift_splash && chmod +x /tmp/extract_new/swift_splash");
- run_cmd("cd /tmp/extract_new && find . | cpio -H newc -o 2>/dev/null | gzip > /home/arkos/arkos/finished/initramfs.img");
- printf("Phase 7: Verify keys and generate avb.img\n");
- ArkConfig* securebuild = ark_parse("/home/arkos/arkos/vendor/verify/securebuild.ark");
- int has_keys = 0;
- for(int i = 0; i < securebuild->standalone_count; i++) {
- if(strstr(securebuild->standalone[i], "ARK-OS-") != NULL) {
- has_keys = 1;
- break;
- }
- }
- if(has_keys) {
- printf("Found signing keys, generating avb.img\n");
- run_cmd("dd if=/dev/zero of=/home/arkos/arkos/finished/avb.img bs=1M count=1");
- } else {
- printf("No signing keys found, skipping avb.img\n");
- }
- ark_free(securebuild);
- printf("Phase 8: vbmeta and dtbo (extra)\n");
- run_cmd("dd if=/dev/zero of=/home/arkos/arkos/finished/vbmeta.img bs=1M count=1");
- run_cmd("dd if=/dev/zero of=/home/arkos/arkos/finished/dtbo.img bs=1M count=1");
- printf("Phase 9: Zipping output\n");
- run_cmd("cd /home/arkos/arkos && zip -r finished/ArkOS.zip finished/ > /dev/null");
- printf("Build complete. Outputs are in %s\n", out_dir);
- return 0;
- }
|