9 # Build steps have been adapted from build-aux/bootstrap.sh.in
10 # as well as the live-bootstrap project
11 # https://github.com/fosslinux/live-bootstrap/blob/737bf61a26152fb82510a2797f0d712de918aa78/sysa/mes-0.25/mes-0.25.kaem
18 url = "mirror://gnu/mes/mes-${version}.tar.gz";
19 hash = "sha256-MlJQs1Z+2SA7pwFhyDWvAQeec+vtl7S1u3fKUAuCiUA=";
22 nyacc = callPackage ./nyacc.nix { inherit nyacc; };
24 config_h = builtins.toFile "config.h" ''
26 #define MES_VERSION "${version}"
29 sources = (import ./sources.nix).x86.linux.mescc;
30 inherit (sources) libc_mini_SOURCES libmescc_SOURCES libc_SOURCES mes_SOURCES;
32 # add symlink() to libc+tcc so we can use it in ln-boot
33 libc_tcc_SOURCES = sources.libc_tcc_SOURCES ++ [ "lib/linux/symlink.c" ];
36 description = "Scheme interpreter and C compiler for bootstrapping";
37 homepage = "https://www.gnu.org/software/mes";
38 license = licenses.gpl3Plus;
39 maintainers = teams.minimal-bootstrap.members;
40 platforms = [ "i686-linux" ];
43 srcPost = kaem.runCommand "${pname}-src-${version}" {
44 outputs = [ "out" "bin" ];
48 ungz --file ${src} --output mes.tar
51 untar --non-strict --file ''${NIX_BUILD_TOP}/mes.tar # ignore symlinks
53 MES_PREFIX=''${out}/mes-${version}
57 cp ${config_h} include/mes/config.h
60 cp include/linux/x86/syscall.h include/arch/syscall.h
61 cp include/linux/x86/kernel-stat.h include/arch/kernel-stat.h
63 # Remove pregenerated files
64 rm mes/module/mes/psyntax.pp mes/module/mes/psyntax.pp.header
66 # These files are symlinked in the repo
67 cp mes/module/srfi/srfi-9-struct.mes mes/module/srfi/srfi-9.mes
68 cp mes/module/srfi/srfi-9/gnu-struct.mes mes/module/srfi/srfi-9/gnu.mes
70 # Remove environment impurities
71 __GUILE_LOAD_PATH="\"''${MES_PREFIX}/mes/module:''${MES_PREFIX}/module:${nyacc.guilePath}\""
72 boot0_scm=mes/module/mes/boot-0.scm
73 guile_mes=mes/module/mes/guile.mes
74 replace --file ''${boot0_scm} --output ''${boot0_scm} --match-on "(getenv \"GUILE_LOAD_PATH\")" --replace-with ''${__GUILE_LOAD_PATH}
75 replace --file ''${guile_mes} --output ''${guile_mes} --match-on "(getenv \"GUILE_LOAD_PATH\")" --replace-with ''${__GUILE_LOAD_PATH}
77 module_mescc_scm=module/mescc/mescc.scm
78 replace --file ''${module_mescc_scm} --output ''${module_mescc_scm} --match-on "(getenv \"M1\")" --replace-with "\"${mescc-tools}/bin/M1\""
79 replace --file ''${module_mescc_scm} --output ''${module_mescc_scm} --match-on "(getenv \"HEX2\")" --replace-with "\"${mescc-tools}/bin/hex2\""
80 replace --file ''${module_mescc_scm} --output ''${module_mescc_scm} --match-on "(getenv \"BLOOD_ELF\")" --replace-with "\"${mescc-tools}/bin/blood-elf\""
81 replace --file ''${module_mescc_scm} --output ''${module_mescc_scm} --match-on "(getenv \"srcdest\")" --replace-with "\"''${MES_PREFIX}\""
84 replace --file ''${mes_c} --output ''${mes_c} --match-on "getenv (\"MES_PREFIX\")" --replace-with "\"''${MES_PREFIX}\""
85 replace --file ''${mes_c} --output ''${mes_c} --match-on "getenv (\"srcdest\")" --replace-with "\"''${MES_PREFIX}\""
87 # Increase runtime resource limits
89 replace --file ''${gc_c} --output ''${gc_c} --match-on "getenv (\"MES_ARENA\")" --replace-with "\"100000000\""
90 replace --file ''${gc_c} --output ''${gc_c} --match-on "getenv (\"MES_MAX_ARENA\")" --replace-with "\"100000000\""
91 replace --file ''${gc_c} --output ''${gc_c} --match-on "getenv (\"MES_STACK\")" --replace-with "\"6000000\""
94 mescc_in=scripts/mescc.scm.in
95 replace --file ''${mescc_in} --output ''${mescc_in} --match-on "(getenv \"MES_PREFIX\")" --replace-with "\"''${MES_PREFIX}\""
96 replace --file ''${mescc_in} --output ''${mescc_in} --match-on "(getenv \"includedir\")" --replace-with "\"''${MES_PREFIX}/include\""
97 replace --file ''${mescc_in} --output ''${mescc_in} --match-on "(getenv \"libdir\")" --replace-with "\"''${MES_PREFIX}/lib\""
98 replace --file ''${mescc_in} --output ''${mescc_in} --match-on @prefix@ --replace-with ''${MES_PREFIX}
99 replace --file ''${mescc_in} --output ''${mescc_in} --match-on @VERSION@ --replace-with ${version}
100 replace --file ''${mescc_in} --output ''${mescc_in} --match-on @mes_cpu@ --replace-with x86
101 replace --file ''${mescc_in} --output ''${mescc_in} --match-on @mes_kernel@ --replace-with linux
102 mkdir -p ''${bin}/bin
103 cp ''${mescc_in} ''${bin}/bin/mescc.scm
106 kaem --verbose --strict --file kaem.x86
107 cp bin/mes-m2 ''${bin}/bin/mes-m2
108 chmod 555 ''${bin}/bin/mes-m2
111 srcPrefix = "${srcPost.out}/mes-${version}";
113 cc = "${srcPost.bin}/bin/mes-m2";
116 "${srcPost.bin}/bin/mescc.scm"
118 "-D" "HAVE_CONFIG_H=1"
119 "-I" "${srcPrefix}/include"
120 "-I" "${srcPrefix}/include/linux/x86"
123 CC = toString ([ cc ] ++ ccArgs);
129 (builtins.baseNameOf source);
131 compile = source: kaem.runCommand (stripExt source) {} ''
134 ${CC} -c ${srcPrefix}/${source}
137 crt1 = compile "/lib/linux/x86-mes-mescc/crt1.c";
139 getRes = suffix: res: "${res}/${res.name}${suffix}";
141 archive = out: sources:
142 "catm ${out} ${lib.concatMapStringsSep " " (getRes ".o") sources}";
143 sourceArchive = out: sources:
144 "catm ${out} ${lib.concatMapStringsSep " " (getRes ".s") sources}";
146 mkLib = libname: sources: let
147 os = map compile sources;
148 in kaem.runCommand "${pname}-${libname}-${version}" {
155 ${archive "${libname}.a" os}
156 ${sourceArchive "${libname}.s" os}
159 libc-mini = mkLib "libc-mini" libc_mini_SOURCES;
160 libmescc = mkLib "libmescc" libmescc_SOURCES;
161 libc = mkLib "libc" libc_SOURCES;
162 libc_tcc = mkLib "libc+tcc" libc_tcc_SOURCES;
164 # Recompile Mes and Mes C library using mes-m2 bootstrapped Mes
165 libs = kaem.runCommand "${pname}-m2-libs-${version}" {
166 inherit pname version;
168 passthru.tests.get-version = result: kaem.runCommand "${pname}-get-version-${version}" {} ''
169 ${result}/bin/mes --version
177 mkdir -p ''${out} ''${LIBDIR}
179 mkdir -p ''${LIBDIR}/x86-mes
182 cp ${crt1}/crt1.o ''${LIBDIR}/x86-mes
183 cp ${crt1}/crt1.s ''${LIBDIR}/x86-mes
186 cp ${libc-mini}/lib/libc-mini.a ''${LIBDIR}/x86-mes
187 cp ${libc-mini}/lib/libc-mini.s ''${LIBDIR}/x86-mes
190 cp ${libmescc}/lib/libmescc.a ''${LIBDIR}/x86-mes
191 cp ${libmescc}/lib/libmescc.s ''${LIBDIR}/x86-mes
194 cp ${libc}/lib/libc.a ''${LIBDIR}/x86-mes
195 cp ${libc}/lib/libc.s ''${LIBDIR}/x86-mes
198 cp ${libc_tcc}/lib/libc+tcc.a ''${LIBDIR}/x86-mes
199 cp ${libc_tcc}/lib/libc+tcc.s ''${LIBDIR}/x86-mes
203 compiler = kaem.runCommand "${pname}-${version}" {
204 inherit pname version;
206 passthru.tests.get-version = result: kaem.runCommand "${pname}-get-version-${version}" {} ''
207 ${result}/bin/mes --version
214 mkdir -p ''${out}/bin
216 ${srcPost.bin}/bin/mes-m2 -e main ${srcPost.bin}/bin/mescc.scm -- \
217 -L ''${srcPrefix}/lib \
222 -o ''${out}/bin/mes \
223 ${libs}/lib/x86-mes/crt1.o \
224 ${lib.concatMapStringsSep " " (getRes ".o") (map compile mes_SOURCES)}
227 inherit src srcPost srcPrefix nyacc;
228 inherit compiler libs;