Thomas Dy 2 years ago
parent
commit
5c9775ac31
5 changed files with 173 additions and 48 deletions
  1. 1 0
      checksums
  2. 28 0
      mes.kaem
  3. 49 48
      stage0-posix.nix
  4. 70 0
      sysa.nix
  5. 25 0
      tcc-0.9.26-patched.kaem

+ 1 - 0
checksums

@@ -0,0 +1 @@
+e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855  /dev/null

+ 28 - 0
mes.kaem

@@ -0,0 +1,28 @@
+#!/bin/sh
+set -ex
+
+prefix=${out}
+bindir=${prefix}/bin
+libdir=${prefix}/lib
+incdir=${prefix}/include
+tmpdir=/tmp
+sources=/tmp
+
+NYACC_PKG=nyacc-1.00.2
+MES_PKG=mes
+MES_PREFIX=${tmpdir}/src/mes-m2-dad1744fa80f52b3b428803c06b09d39c285f500
+GUILE_LOAD_PATH=${MES_PREFIX}/mes/module:${MES_PREFIX}/module:${tmpdir}/src/${NYACC_PKG}/module
+mkdir -p ${prefix} ${bindir} ${libdir} ${incdir} ${tmpdir}
+
+cd ${tmpdir}
+mkdir files src mes
+cp ${src}/sysa/mes/files/mescc.scm files/mescc.scm
+cp ${src}/sysa/mes/files/config.h files/config.h
+
+cp ${nyacc_src} src/${NYACC_PKG}.tar.gz
+cp ${mes_src} src/${MES_PKG}.tar.gz
+
+# create empty checksum file so the build succeeds
+cp ${checksums} ${sources}/${MES_PKG}/checksums
+
+kaem --file ${src}/sysa/mes/mes.kaem

+ 49 - 48
stage0-posix.nix

@@ -1,8 +1,9 @@
 let
   system = "x86_64-linux";
 
-  ARCH_DIR = "AMD64";
-  ARCH = "amd64";
+  ARCH_DIR = "x86";
+  ARCH = "x86";
+  ELF_ARCH = "i386";
 
   stage0-src = builtins.fetchGit {
     url = "https://github.com/oriansj/stage0-posix.git";
@@ -23,29 +24,29 @@ let
 
   hex0 = run "hex0" [
     "${stage0-src}/bootstrap-seeds/POSIX/${ARCH_DIR}/hex0-seed"
-    "${arch-src}/hex0_AMD64.hex0"
+    "${arch-src}/hex0_${ARCH_DIR}.hex0"
     out
   ];
 
   hex1 = run "hex1" [
     hex0
-    "${arch-src}/hex1_AMD64.hex0"
+    "${arch-src}/hex1_${ARCH_DIR}.hex0"
     out
   ];
 
   catm = run "catm" [
     hex0
-    "${arch-src}/catm_AMD64.hex0"
+    "${arch-src}/catm_${ARCH_DIR}.hex0"
     out
   ];
 
   hex2-0 = run "hex2-0" [
     hex1
-    "${arch-src}/hex2_AMD64.hex1"
+    "${arch-src}/hex2_${ARCH_DIR}.hex1"
     out
   ];
 
-  arch-elf-hex2 = "${arch-src}/ELF-amd64.hex2";
+  arch-elf-hex2 = "${arch-src}/ELF-${ELF_ARCH}.hex2";
 
   cat = name: args: run name ([
     catm
@@ -58,7 +59,7 @@ let
     out
   ];
 
-  M0 = buildHex2 "M0" arch-elf-hex2 "${arch-src}/M0_AMD64.hex2";
+  M0 = buildHex2 "M0" arch-elf-hex2 "${arch-src}/M0_${ARCH_DIR}.hex2";
 
   buildM0 = name: elf: src: buildHex2 name elf (run "${name}-m0" [
     M0
@@ -66,12 +67,12 @@ let
     out
   ]);
 
-  cc_amd64 = buildM0 "cc_amd64" arch-elf-hex2 "${arch-src}/cc_amd64.M1";
+  cc = buildM0 "cc_${ARCH}" arch-elf-hex2 "${arch-src}/cc_${ARCH}.M1";
 
   M2 =
     let
       M2-0-c = cat "M2-0.c" [
-        "${stage0-src}/M2libc/amd64/linux/bootstrap.c"
+        "${stage0-src}/M2libc/${ARCH}/linux/bootstrap.c"
         "${stage0-src}/M2-Planet/cc.h"
         "${stage0-src}/M2libc/bootstrappable.c"
         "${stage0-src}/M2-Planet/cc_globals.c"
@@ -83,27 +84,27 @@ let
         "${stage0-src}/M2-Planet/cc.c"
       ];
       M2-0-M1 = run "M2-0.M1" [
-        cc_amd64
+        cc
         M2-0-c
         out
       ];
       M2-0-0-M1 = cat "M2-0-0.m1" [
-        "${arch-src}/amd64_defs.M1"
+        "${arch-src}/${ARCH}_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";
+  libc-elf-hex2 = "${stage0-src}/M2libc/${ARCH}/ELF-${ARCH}.hex2";
+  libc-elf-debug-hex2 = "${stage0-src}/M2libc/${ARCH}/ELF-${ARCH}-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"
+        "--architecture" ARCH
+        "-f" "${stage0-src}/M2libc/${ARCH}/linux/bootstrap.c"
         "-f" "${stage0-src}/M2libc/bootstrappable.c"
         "-f" "${stage0-src}/mescc-tools/stringify.c"
         "-f" "${stage0-src}/mescc-tools/blood-elf.c"
@@ -111,7 +112,7 @@ let
         "-o" out
       ];
       blood-elf-0-0-M1 = cat "blood-elf-0-0.M1" [
-        "${arch-src}/amd64_defs.M1"
+        "${arch-src}/${ARCH}_defs.M1"
         "${arch-src}/libc-core.M1"
         blood-elf-0-M1
       ];
@@ -129,8 +130,8 @@ let
     let
       M1-macro-0-M1 = run "M1-macro-0.M1" [
         M2
-        "--architecture" "amd64"
-        "-f" "${stage0-src}/M2libc/amd64/linux/bootstrap.c"
+        "--architecture" ARCH
+        "-f" "${stage0-src}/M2libc/${ARCH}/linux/bootstrap.c"
         "-f" "${stage0-src}/M2libc/bootstrappable.c"
         "-f" "${stage0-src}/mescc-tools/stringify.c"
         "-f" "${stage0-src}/mescc-tools/M1-macro.c"
@@ -140,7 +141,7 @@ let
       ];
       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}/${ARCH}_defs.M1"
         "${arch-src}/libc-core.M1"
         M1-macro-0-M1
         M1-macro-0-footer-M1
@@ -152,12 +153,12 @@ let
     let
       hex2_linker-1-M1 = run "hex2_linker-1.M1" [
         M2
-        "--architecture" "amd64"
+        "--architecture" ARCH
         "-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/${ARCH}/linux/fcntl.c"
+        "-f" "${stage0-src}/M2libc/${ARCH}/linux/unistd.c"
+        "-f" "${stage0-src}/M2libc/${ARCH}/linux/sys/stat.c"
         "-f" "${stage0-src}/M2libc/stdlib.c"
         "-f" "${stage0-src}/M2libc/stdio.c"
         "-f" "${stage0-src}/M2libc/bootstrappable.c"
@@ -171,10 +172,10 @@ let
       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"
+        "--architecture" ARCH
         "--little-endian"
-        "-f" "${stage0-src}/M2libc/amd64/amd64_defs.M1"
-        "-f" "${stage0-src}/M2libc/amd64/libc-full.M1"
+        "-f" "${stage0-src}/M2libc/${ARCH}/${ARCH}_defs.M1"
+        "-f" "${stage0-src}/M2libc/${ARCH}/libc-full.M1"
         "-f" hex2_linker-1-M1
         "-f" hex2_linker-1-footer-M1
         "-o" out
@@ -185,17 +186,17 @@ let
   buildM1 = deps: name: srcs:
     let
       M1-src = run "${name}.M1" (
-        [ M2 "--architecture" "amd64" ]
+        [ M2 "--architecture" ARCH ]
         ++ (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"
+        "--architecture" ARCH
         "--little-endian"
-        "-f" "${stage0-src}/M2libc/amd64/amd64_defs.M1"
-        "-f" "${stage0-src}/M2libc/amd64/libc-full.M1"
+        "-f" "${stage0-src}/M2libc/${ARCH}/${ARCH}_defs.M1"
+        "-f" "${stage0-src}/M2libc/${ARCH}/libc-full.M1"
         "-f" M1-src
         "-f" M1-footer-src
         "-o" out
@@ -203,7 +204,7 @@ let
     in
     run name [
       deps.hex2
-      "--architecture" "amd64"
+      "--architecture" ARCH
       "--little-endian"
       "--base-address" "0x00600000"
       "-f" libc-elf-debug-hex2
@@ -218,8 +219,8 @@ let
   } "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/${ARCH}/linux/fcntl.c"
+    "${stage0-src}/M2libc/${ARCH}/linux/unistd.c"
     "${stage0-src}/M2libc/string.c"
     "${stage0-src}/M2libc/stdlib.c"
     "${stage0-src}/M2libc/stdio.c"
@@ -235,9 +236,9 @@ let
   } "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/${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/bootstrappable.c"
@@ -256,8 +257,8 @@ let
     "${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/${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"
@@ -338,9 +339,9 @@ let
     "${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/${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/bootstrappable.c"
@@ -351,9 +352,9 @@ let
     "${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/${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/bootstrappable.c"
@@ -364,8 +365,8 @@ let
     "${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/${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"
@@ -453,7 +454,7 @@ in
     catm
     hex2-0
     M0
-    cc_amd64
+    cc
     M2
     blood-elf-0
     M1-0

+ 70 - 0
sysa.nix

@@ -0,0 +1,70 @@
+let
+  system = "x86_64-linux";
+  inherit (import ./stage0-posix.nix) kaem buildtools0 mescc-tools-extra;
+
+  live-bootstrap-src = builtins.fetchGit {
+    url = "https://github.com/fosslinux/live-bootstrap.git";
+    rev = "b2e8e0fea0d1715a0c3a2e3cccd64b617c040851";
+  };
+
+  mes-src = builtins.fetchurl {
+    url = "https://github.com/oriansj/mes-m2/archive/dad1744fa80f52b3b428803c06b09d39c285f500.tar.gz";
+    sha256 = "a8da14d1cd6aaa1ff607a571a8ca5948258195c712de05b0f8ad11c215b6b094";
+  };
+
+  nyacc-src = builtins.fetchurl {
+    url = "https://download.savannah.gnu.org/releases/nyacc/nyacc-1.00.2.tar.gz";
+    sha256 = "f36e4fb7dd524dc3f4b354d3d5313f69e7ce5a6ae93711e8cf6d51eaa8d2b318";
+  };
+
+  mes = derivation {
+    inherit system;
+    name = "mes";
+
+    src = live-bootstrap-src;
+
+    mes_src = mes-src;
+    nyacc_src = nyacc-src;
+    empty = builtins.toFile "empty" "";
+    checksums = ./checksums;
+
+    builder = kaem;
+
+    ARCH = "x86";
+    PATH = "${buildtools0}/bin:${mescc-tools-extra}/bin";
+
+    args = ["--file" ./mes.kaem];
+  };
+
+  tcc-0_9_26-patched-src = builtins.fetchurl {
+    url = "https://lilypond.org/janneke/tcc/tcc-0.9.26-1136-g5bba73cc.tar.gz";
+  };
+
+  mes-0_23-src = builtins.fetchurl {
+    url = "https://mirrors.kernel.org/gnu/mes/mes-0.23.tar.gz";
+  };
+
+  tcc-0_9_26 = derivation {
+    inherit system;
+    name = "tcc-0.9.26";
+
+    src = live-bootstrap-src;
+
+    inherit mes;
+    mes_src = mes-0_23-src;
+    tcc_src = tcc-0_9_26-patched-src;
+
+    checksums = ./checksums;
+
+    builder = kaem;
+
+    ARCH = "x86";
+    PATH = "${buildtools0}/bin:${mescc-tools-extra}/bin:${mes}/bin";
+
+    args = ["--file" ./tcc-0.9.26-patched.kaem];
+  };
+
+in
+{
+  inherit mes tcc-0_9_26;
+}

+ 25 - 0
tcc-0.9.26-patched.kaem

@@ -0,0 +1,25 @@
+#!/bin/sh
+set -ex
+
+prefix=${out}
+bindir=${prefix}/bin
+libdir=${prefix}/lib
+incdir=${prefix}/include
+tmpdir=/tmp/tcc
+sources=/tmp
+
+MES_PKG=mes-0.23
+MES_PREFIX=${mes}
+# GUILE_LOAD_PATH=${MES_PREFIX}/mes/module:${MES_PREFIX}/module:${tmpdir}/src/${NYACC_PKG}/module
+mkdir -p ${prefix} ${bindir} ${libdir} ${incdir} ${tmpdir} /tmp/${MES_PKG}/src
+
+cd ${tmpdir}
+mkdir src
+
+cp ${tcc_src} src/tcc-0.9.26.tar.gz
+cp ${mes_src} ../${MES_PKG}/src/${MES_PKG}.tar.gz
+
+# create empty checksum file so the build succeeds
+# cp ${checksums} ${sources}/${MES_PKG}/checksums
+
+kaem --file ${src}/sysa/tcc-0.9.26/tcc-0.9.26.kaem