123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472 |
- let
- system = "x86_64-linux";
- ARCH_DIR = "AMD64";
- ARCH = "amd64";
- stage0-src = builtins.fetchGit {
- url = "https://github.com/oriansj/stage0-posix.git";
- rev = "74f1e36f35c28d7854eddfde963917c404764ede";
- submodules = true;
- };
- arch-src = "${stage0-src}/${ARCH_DIR}";
- out = builtins.placeholder "out";
- run = name: args: derivation {
- inherit name system;
- builder = builtins.head args;
- args = builtins.tail args;
- };
- hex0 = run "hex0" [
- "${stage0-src}/bootstrap-seeds/POSIX/${ARCH_DIR}/hex0-seed"
- "${arch-src}/hex0_AMD64.hex0"
- out
- ];
- hex1 = run "hex1" [
- hex0
- "${arch-src}/hex1_AMD64.hex0"
- out
- ];
- catm = run "catm" [
- hex0
- "${arch-src}/catm_AMD64.hex0"
- out
- ];
- hex2-0 = run "hex2-0" [
- hex1
- "${arch-src}/hex2_AMD64.hex1"
- out
- ];
- arch-elf-hex2 = "${arch-src}/ELF-amd64.hex2";
- cat = name: args: run name ([
- catm
- out
- ] ++ args);
- buildHex2 = name: elf: src: run name [
- hex2-0
- (cat "${name}-src" [ elf src ])
- out
- ];
- M0 = buildHex2 "M0" arch-elf-hex2 "${arch-src}/M0_AMD64.hex2";
- buildM0 = name: elf: src: buildHex2 name elf (run "${name}-m0" [
- M0
- src
- out
- ]);
- cc_amd64 = buildM0 "cc_amd64" arch-elf-hex2 "${arch-src}/cc_amd64.M1";
- M2 =
- let
- M2-0-c = cat "M2-0.c" [
- "${stage0-src}/M2libc/amd64/linux/bootstrap.c"
- "${stage0-src}/M2-Planet/cc.h"
- "${stage0-src}/M2libc/bootstrappable.c"
- "${stage0-src}/M2-Planet/cc_globals.c"
- "${stage0-src}/M2-Planet/cc_reader.c"
- "${stage0-src}/M2-Planet/cc_strings.c"
- "${stage0-src}/M2-Planet/cc_types.c"
- "${stage0-src}/M2-Planet/cc_core.c"
- "${stage0-src}/M2-Planet/cc_macro.c"
- "${stage0-src}/M2-Planet/cc.c"
- ];
- M2-0-M1 = run "M2-0.M1" [
- cc_amd64
- M2-0-c
- out
- ];
- M2-0-0-M1 = cat "M2-0-0.m1" [
- "${arch-src}/amd64_defs.M1"
- "${arch-src}/libc-core.M1"
- M2-0-M1
- ];
- in
- buildM0 "M2" arch-elf-hex2 M2-0-0-M1;
- libc-elf-hex2 = "${stage0-src}/M2libc/amd64/ELF-amd64.hex2";
- libc-elf-debug-hex2 = "${stage0-src}/M2libc/amd64/ELF-amd64-debug.hex2";
- blood-elf-0 =
- let
- blood-elf-0-M1 = run "blood-elf-0.M1" [
- M2
- "--architecture" "amd64"
- "-f" "${stage0-src}/M2libc/amd64/linux/bootstrap.c"
- "-f" "${stage0-src}/M2libc/bootstrappable.c"
- "-f" "${stage0-src}/mescc-tools/stringify.c"
- "-f" "${stage0-src}/mescc-tools/blood-elf.c"
- "--bootstrap-mode"
- "-o" out
- ];
- blood-elf-0-0-M1 = cat "blood-elf-0-0.M1" [
- "${arch-src}/amd64_defs.M1"
- "${arch-src}/libc-core.M1"
- blood-elf-0-M1
- ];
- in
- buildM0 "blood-elf-0" libc-elf-hex2 blood-elf-0-0-M1;
- runBloodelf = blood-elf: name: src: run name [
- blood-elf
- "--64" "--little-endian"
- "-f" src
- "-o" out
- ];
- M1-0 =
- let
- M1-macro-0-M1 = run "M1-macro-0.M1" [
- M2
- "--architecture" "amd64"
- "-f" "${stage0-src}/M2libc/amd64/linux/bootstrap.c"
- "-f" "${stage0-src}/M2libc/bootstrappable.c"
- "-f" "${stage0-src}/mescc-tools/stringify.c"
- "-f" "${stage0-src}/mescc-tools/M1-macro.c"
- "--bootstrap-mode"
- "--debug"
- "-o" out
- ];
- M1-macro-0-footer-M1 = runBloodelf blood-elf-0 "M1-macro-0-footer.M1" M1-macro-0-M1;
- M1-macro-0-0-M1 = cat "M1-macro-0-0.M1" [
- "${arch-src}/amd64_defs.M1"
- "${arch-src}/libc-core.M1"
- M1-macro-0-M1
- M1-macro-0-footer-M1
- ];
- in
- buildM0 "M1-0" libc-elf-debug-hex2 M1-macro-0-0-M1;
- hex2-1 =
- let
- hex2_linker-1-M1 = run "hex2_linker-1.M1" [
- M2
- "--architecture" "amd64"
- "-f" "${stage0-src}/M2libc/sys/types.h"
- "-f" "${stage0-src}/M2libc/stddef.h"
- "-f" "${stage0-src}/M2libc/amd64/linux/fcntl.c"
- "-f" "${stage0-src}/M2libc/amd64/linux/unistd.c"
- "-f" "${stage0-src}/M2libc/amd64/linux/sys/stat.c"
- "-f" "${stage0-src}/M2libc/stdlib.c"
- "-f" "${stage0-src}/M2libc/stdio.c"
- "-f" "${stage0-src}/M2libc/bootstrappable.c"
- "-f" "${stage0-src}/mescc-tools/hex2.h"
- "-f" "${stage0-src}/mescc-tools/hex2_linker.c"
- "-f" "${stage0-src}/mescc-tools/hex2_word.c"
- "-f" "${stage0-src}/mescc-tools/hex2.c"
- "--debug"
- "-o" out
- ];
- hex2_linker-1-footer-M1 = runBloodelf blood-elf-0 "hex2_linker-1-footer.M1" hex2_linker-1-M1;
- hex2_linker-1-hex2 = run "hex2_linker-1.hex2" [
- M1-0
- "--architecture" "amd64"
- "--little-endian"
- "-f" "${stage0-src}/M2libc/amd64/amd64_defs.M1"
- "-f" "${stage0-src}/M2libc/amd64/libc-full.M1"
- "-f" hex2_linker-1-M1
- "-f" hex2_linker-1-footer-M1
- "-o" out
- ];
- in
- buildHex2 "hex2-1" libc-elf-debug-hex2 hex2_linker-1-hex2;
- buildM1 = deps: name: srcs:
- let
- M1-src = run "${name}.M1" (
- [ M2 "--architecture" "amd64" ]
- ++ (builtins.concatMap (x: [ "-f" x ]) srcs)
- ++ [ "--debug" "-o" out ]
- );
- M1-footer-src = runBloodelf deps.blood-elf "${name}-footer.M1" M1-src;
- hex2-src = run "${name}.hex2" [
- deps.M1
- "--architecture" "amd64"
- "--little-endian"
- "-f" "${stage0-src}/M2libc/amd64/amd64_defs.M1"
- "-f" "${stage0-src}/M2libc/amd64/libc-full.M1"
- "-f" M1-src
- "-f" M1-footer-src
- "-o" out
- ];
- in
- run name [
- deps.hex2
- "--architecture" "amd64"
- "--little-endian"
- "--base-address" "0x00600000"
- "-f" libc-elf-debug-hex2
- "-f" hex2-src
- "-o" out
- ];
- M1 = buildM1 {
- M1 = M1-0;
- hex2 = hex2-1;
- blood-elf = blood-elf-0;
- } "M1" [
- "${stage0-src}/M2libc/sys/types.h"
- "${stage0-src}/M2libc/stddef.h"
- "${stage0-src}/M2libc/amd64/linux/fcntl.c"
- "${stage0-src}/M2libc/amd64/linux/unistd.c"
- "${stage0-src}/M2libc/string.c"
- "${stage0-src}/M2libc/stdlib.c"
- "${stage0-src}/M2libc/stdio.c"
- "${stage0-src}/M2libc/bootstrappable.c"
- "${stage0-src}/mescc-tools/stringify.c"
- "${stage0-src}/mescc-tools/M1-macro.c"
- ];
- hex2 = buildM1 {
- inherit M1;
- hex2 = hex2-1;
- blood-elf = blood-elf-0;
- } "hex2" [
- "${stage0-src}/M2libc/sys/types.h"
- "${stage0-src}/M2libc/stddef.h"
- "${stage0-src}/M2libc/amd64/linux/fcntl.c"
- "${stage0-src}/M2libc/amd64/linux/unistd.c"
- "${stage0-src}/M2libc/amd64/linux/sys/stat.c"
- "${stage0-src}/M2libc/stdlib.c"
- "${stage0-src}/M2libc/stdio.c"
- "${stage0-src}/M2libc/bootstrappable.c"
- "${stage0-src}/mescc-tools/hex2.h"
- "${stage0-src}/mescc-tools/hex2_linker.c"
- "${stage0-src}/mescc-tools/hex2_word.c"
- "${stage0-src}/mescc-tools/hex2.c"
- ];
- buildPhase11 = buildM1 {
- inherit M1 hex2;
- blood-elf = blood-elf-0;
- };
- kaem = buildPhase11 "kaem" [
- "${stage0-src}/M2libc/sys/types.h"
- "${stage0-src}/M2libc/stddef.h"
- "${stage0-src}/M2libc/string.c"
- "${stage0-src}/M2libc/amd64/linux/fcntl.c"
- "${stage0-src}/M2libc/amd64/linux/unistd.c"
- "${stage0-src}/M2libc/stdlib.c"
- "${stage0-src}/M2libc/stdio.c"
- "${stage0-src}/M2libc/bootstrappable.c"
- "${stage0-src}/mescc-tools/Kaem/kaem.h"
- "${stage0-src}/mescc-tools/Kaem/variable.c"
- "${stage0-src}/mescc-tools/Kaem/kaem_globals.c"
- "${stage0-src}/mescc-tools/Kaem/kaem.c"
- ];
- M2-Mesoplanet = buildPhase11 "M2-Mesoplanet" [
- "${stage0-src}/M2libc/sys/types.h"
- "${stage0-src}/M2libc/stddef.h"
- "${stage0-src}/M2libc/${ARCH}/linux/fcntl.c"
- "${stage0-src}/M2libc/${ARCH}/linux/unistd.c"
- "${stage0-src}/M2libc/${ARCH}/linux/sys/stat.c"
- "${stage0-src}/M2libc/stdlib.c"
- "${stage0-src}/M2libc/stdio.c"
- "${stage0-src}/M2libc/string.c"
- "${stage0-src}/M2libc/bootstrappable.c"
- "${stage0-src}/M2-Mesoplanet/cc.h"
- "${stage0-src}/M2-Mesoplanet/cc_globals.c"
- "${stage0-src}/M2-Mesoplanet/cc_env.c"
- "${stage0-src}/M2-Mesoplanet/cc_reader.c"
- "${stage0-src}/M2-Mesoplanet/cc_spawn.c"
- "${stage0-src}/M2-Mesoplanet/cc_core.c"
- "${stage0-src}/M2-Mesoplanet/cc_macro.c"
- "${stage0-src}/M2-Mesoplanet/cc.c"
- ];
- blood-elf = buildPhase11 "blood-elf" [
- "${stage0-src}/M2libc/sys/types.h"
- "${stage0-src}/M2libc/stddef.h"
- "${stage0-src}/M2libc/${ARCH}/linux/fcntl.c"
- "${stage0-src}/M2libc/${ARCH}/linux/unistd.c"
- "${stage0-src}/M2libc/stdlib.c"
- "${stage0-src}/M2libc/stdio.c"
- "${stage0-src}/M2libc/bootstrappable.c"
- "${stage0-src}/mescc-tools/stringify.c"
- "${stage0-src}/mescc-tools/blood-elf.c"
- ];
- buildPhase14 = buildM1 {
- inherit M1 hex2 blood-elf;
- };
- get_machine = buildPhase14 "get_machine" [
- "${stage0-src}/M2libc/sys/types.h"
- "${stage0-src}/M2libc/stddef.h"
- "${stage0-src}/M2libc/${ARCH}/linux/fcntl.c"
- "${stage0-src}/M2libc/${ARCH}/linux/unistd.c"
- "${stage0-src}/M2libc/stdlib.c"
- "${stage0-src}/M2libc/stdio.c"
- "${stage0-src}/M2libc/bootstrappable.c"
- "${stage0-src}/mescc-tools/get_machine.c"
- ];
- M2-Planet = buildPhase14 "M2-Planet" [
- "${stage0-src}/M2libc/sys/types.h"
- "${stage0-src}/M2libc/stddef.h"
- "${stage0-src}/M2libc/${ARCH}/linux/fcntl.c"
- "${stage0-src}/M2libc/${ARCH}/linux/unistd.c"
- "${stage0-src}/M2libc/stdlib.c"
- "${stage0-src}/M2libc/stdio.c"
- "${stage0-src}/M2libc/bootstrappable.c"
- "${stage0-src}/M2-Planet/cc.h"
- "${stage0-src}/M2-Planet/cc_globals.c"
- "${stage0-src}/M2-Planet/cc_reader.c"
- "${stage0-src}/M2-Planet/cc_strings.c"
- "${stage0-src}/M2-Planet/cc_types.c"
- "${stage0-src}/M2-Planet/cc_core.c"
- "${stage0-src}/M2-Planet/cc_macro.c"
- "${stage0-src}/M2-Planet/cc.c"
- ];
- # after this point, we rely on PATH so we have to build up a bin dir that we
- # can use for that so we need mkdir, chmod and cp
- mkdir0 = buildPhase14 "mkdir0" [
- "${stage0-src}/M2libc/sys/types.h"
- "${stage0-src}/M2libc/stddef.h"
- "${stage0-src}/M2libc/string.c"
- "${stage0-src}/M2libc/amd64/linux/fcntl.c"
- "${stage0-src}/M2libc/amd64/linux/unistd.c"
- "${stage0-src}/M2libc/amd64/linux/sys/stat.c"
- "${stage0-src}/M2libc/stdlib.c"
- "${stage0-src}/M2libc/stdio.c"
- "${stage0-src}/M2libc/bootstrappable.c"
- "${stage0-src}/mescc-tools-extra/mkdir.c"
- ];
- chmod0 = buildPhase14 "chmod0" [
- "${stage0-src}/M2libc/sys/types.h"
- "${stage0-src}/M2libc/stddef.h"
- "${stage0-src}/M2libc/string.c"
- "${stage0-src}/M2libc/amd64/linux/fcntl.c"
- "${stage0-src}/M2libc/amd64/linux/unistd.c"
- "${stage0-src}/M2libc/amd64/linux/sys/stat.c"
- "${stage0-src}/M2libc/stdlib.c"
- "${stage0-src}/M2libc/stdio.c"
- "${stage0-src}/M2libc/bootstrappable.c"
- "${stage0-src}/mescc-tools-extra/chmod.c"
- ];
- cp0 = buildPhase14 "cp0" [
- "${stage0-src}/M2libc/sys/types.h"
- "${stage0-src}/M2libc/stddef.h"
- "${stage0-src}/M2libc/string.c"
- "${stage0-src}/M2libc/amd64/linux/fcntl.c"
- "${stage0-src}/M2libc/amd64/linux/unistd.c"
- "${stage0-src}/M2libc/stdlib.c"
- "${stage0-src}/M2libc/stdio.c"
- "${stage0-src}/M2libc/bootstrappable.c"
- "${stage0-src}/mescc-tools-extra/cp.c"
- ];
- makeBin = name: attrs:
- let
- getEnv = builtins.replaceStrings ["-"] [""];
- script = map
- (x: ''
- ''${cp0} ''${${getEnv x}} ''${out}/bin/${x}
- ''${chmod0} 0700 ''${out}/bin/${x}
- '')
- (builtins.attrNames attrs);
- env = builtins.listToAttrs (
- map
- (x: { name = (getEnv x); value = attrs."${x}"; })
- (builtins.attrNames attrs));
- in
- derivation (env // {
- inherit system;
- name = "buildtools0";
- inherit mkdir0 chmod0 cp0;
- builder = kaem;
- args = ["--file" (builtins.toFile "builder.kaem" ''
- ''${mkdir0} -p ''${out}/bin
- ${builtins.concatStringsSep "\n" script}
- '')];
- });
- buildtools0 = makeBin "buildtools0" {
- inherit
- kaem
- hex2
- blood-elf
- get_machine
- M1
- M2-Planet
- M2-Mesoplanet
- ;
- };
- buildWithC = name: attrs: script: derivation (attrs // {
- inherit system name;
- src = stage0-src;
- mkdir = mkdir0;
- M2LIBC_PATH = "${stage0-src}/M2libc";
- PATH = "${buildtools0}/bin";
- builder = kaem;
- args = ["--file" (builtins.toFile "builder.kaem" script)];
- });
- mescc-tools-extra = buildWithC "mescc-tools-extra" {} ''
- set -ex
- alias CC="M2-Mesoplanet --architecture ${ARCH} -f"
- BINDIR=''${out}/bin
- ''${mkdir} -p ''${BINDIR}
- cd ''${src}/mescc-tools-extra
- CC sha256sum.c -o ''${BINDIR}/sha256sum
- CC match.c -o ''${BINDIR}/match
- CC mkdir.c -o ''${BINDIR}/mkdir
- CC untar.c -o ''${BINDIR}/untar
- CC ungz.c -o ''${BINDIR}/ungz
- CC catm.c -o ''${BINDIR}/catm
- CC cp.c -o ''${BINDIR}/cp
- CC chmod.c -o ''${BINDIR}/chmod
- '';
- in
- {
- inherit
- hex0
- hex1
- catm
- hex2-0
- M0
- cc_amd64
- M2
- blood-elf-0
- M1-0
- hex2-1
- M1
- hex2
- kaem
- M2-Mesoplanet
- blood-elf
- get_machine
- M2-Planet
- makeBin
- buildtools0
- mescc-tools-extra
- ;
- }
|