at master 8.6 kB view raw
1{ 2 lib, 3 fetchurl, 4 callPackage, 5 kaem, 6 mescc-tools, 7}: 8 9# Maintenance note: 10# Build steps have been adapted from build-aux/bootstrap.sh.in 11# as well as the live-bootstrap project 12# https://github.com/fosslinux/live-bootstrap/blob/737bf61a26152fb82510a2797f0d712de918aa78/sysa/mes-0.25/mes-0.25.kaem 13 14let 15 pname = "mes"; 16 version = "0.25"; 17 18 src = fetchurl { 19 url = "mirror://gnu/mes/mes-${version}.tar.gz"; 20 hash = "sha256-MlJQs1Z+2SA7pwFhyDWvAQeec+vtl7S1u3fKUAuCiUA="; 21 }; 22 23 nyacc = callPackage ./nyacc.nix { inherit nyacc; }; 24 25 config_h = builtins.toFile "config.h" '' 26 #undef SYSTEM_LIBC 27 #define MES_VERSION "${version}" 28 ''; 29 30 sources = (import ./sources.nix).x86.linux.mescc; 31 inherit (sources) 32 libc_mini_SOURCES 33 libmescc_SOURCES 34 libc_SOURCES 35 mes_SOURCES 36 ; 37 38 # add symlink() to libc+tcc so we can use it in ln-boot 39 libc_tcc_SOURCES = sources.libc_tcc_SOURCES ++ [ "lib/linux/symlink.c" ]; 40 41 meta = with lib; { 42 description = "Scheme interpreter and C compiler for bootstrapping"; 43 homepage = "https://www.gnu.org/software/mes"; 44 license = licenses.gpl3Plus; 45 teams = [ teams.minimal-bootstrap ]; 46 platforms = [ "i686-linux" ]; 47 }; 48 49 srcPost = 50 kaem.runCommand "${pname}-src-${version}" 51 { 52 outputs = [ 53 "out" 54 "bin" 55 ]; 56 inherit meta; 57 } 58 '' 59 # Unpack source 60 ungz --file ${src} --output mes.tar 61 mkdir ''${out} 62 cd ''${out} 63 untar --non-strict --file ''${NIX_BUILD_TOP}/mes.tar # ignore symlinks 64 65 MES_PREFIX=''${out}/mes-${version} 66 67 cd ''${MES_PREFIX} 68 69 cp ${config_h} include/mes/config.h 70 71 mkdir include/arch 72 cp include/linux/x86/syscall.h include/arch/syscall.h 73 cp include/linux/x86/kernel-stat.h include/arch/kernel-stat.h 74 75 # Remove pregenerated files 76 rm mes/module/mes/psyntax.pp mes/module/mes/psyntax.pp.header 77 78 # These files are symlinked in the repo 79 cp mes/module/srfi/srfi-9-struct.mes mes/module/srfi/srfi-9.mes 80 cp mes/module/srfi/srfi-9/gnu-struct.mes mes/module/srfi/srfi-9/gnu.mes 81 82 # Remove environment impurities 83 __GUILE_LOAD_PATH="\"''${MES_PREFIX}/mes/module:''${MES_PREFIX}/module:${nyacc.guilePath}\"" 84 boot0_scm=mes/module/mes/boot-0.scm 85 guile_mes=mes/module/mes/guile.mes 86 replace --file ''${boot0_scm} --output ''${boot0_scm} --match-on "(getenv \"GUILE_LOAD_PATH\")" --replace-with ''${__GUILE_LOAD_PATH} 87 replace --file ''${guile_mes} --output ''${guile_mes} --match-on "(getenv \"GUILE_LOAD_PATH\")" --replace-with ''${__GUILE_LOAD_PATH} 88 89 module_mescc_scm=module/mescc/mescc.scm 90 replace --file ''${module_mescc_scm} --output ''${module_mescc_scm} --match-on "(getenv \"M1\")" --replace-with "\"${mescc-tools}/bin/M1\"" 91 replace --file ''${module_mescc_scm} --output ''${module_mescc_scm} --match-on "(getenv \"HEX2\")" --replace-with "\"${mescc-tools}/bin/hex2\"" 92 replace --file ''${module_mescc_scm} --output ''${module_mescc_scm} --match-on "(getenv \"BLOOD_ELF\")" --replace-with "\"${mescc-tools}/bin/blood-elf\"" 93 replace --file ''${module_mescc_scm} --output ''${module_mescc_scm} --match-on "(getenv \"srcdest\")" --replace-with "\"''${MES_PREFIX}\"" 94 95 mes_c=src/mes.c 96 replace --file ''${mes_c} --output ''${mes_c} --match-on "getenv (\"MES_PREFIX\")" --replace-with "\"''${MES_PREFIX}\"" 97 replace --file ''${mes_c} --output ''${mes_c} --match-on "getenv (\"srcdest\")" --replace-with "\"''${MES_PREFIX}\"" 98 99 # Increase runtime resource limits 100 gc_c=src/gc.c 101 replace --file ''${gc_c} --output ''${gc_c} --match-on "getenv (\"MES_ARENA\")" --replace-with "\"100000000\"" 102 replace --file ''${gc_c} --output ''${gc_c} --match-on "getenv (\"MES_MAX_ARENA\")" --replace-with "\"100000000\"" 103 replace --file ''${gc_c} --output ''${gc_c} --match-on "getenv (\"MES_STACK\")" --replace-with "\"6000000\"" 104 105 # Create mescc.scm 106 mescc_in=scripts/mescc.scm.in 107 replace --file ''${mescc_in} --output ''${mescc_in} --match-on "(getenv \"MES_PREFIX\")" --replace-with "\"''${MES_PREFIX}\"" 108 replace --file ''${mescc_in} --output ''${mescc_in} --match-on "(getenv \"includedir\")" --replace-with "\"''${MES_PREFIX}/include\"" 109 replace --file ''${mescc_in} --output ''${mescc_in} --match-on "(getenv \"libdir\")" --replace-with "\"''${MES_PREFIX}/lib\"" 110 replace --file ''${mescc_in} --output ''${mescc_in} --match-on @prefix@ --replace-with ''${MES_PREFIX} 111 replace --file ''${mescc_in} --output ''${mescc_in} --match-on @VERSION@ --replace-with ${version} 112 replace --file ''${mescc_in} --output ''${mescc_in} --match-on @mes_cpu@ --replace-with x86 113 replace --file ''${mescc_in} --output ''${mescc_in} --match-on @mes_kernel@ --replace-with linux 114 mkdir -p ''${bin}/bin 115 cp ''${mescc_in} ''${bin}/bin/mescc.scm 116 117 # Build mes-m2 118 kaem --verbose --strict --file kaem.x86 119 cp bin/mes-m2 ''${bin}/bin/mes-m2 120 chmod 555 ''${bin}/bin/mes-m2 121 ''; 122 123 srcPrefix = "${srcPost.out}/mes-${version}"; 124 125 cc = "${srcPost.bin}/bin/mes-m2"; 126 ccArgs = [ 127 "-e" 128 "main" 129 "${srcPost.bin}/bin/mescc.scm" 130 "--" 131 "-D" 132 "HAVE_CONFIG_H=1" 133 "-I" 134 "${srcPrefix}/include" 135 "-I" 136 "${srcPrefix}/include/linux/x86" 137 ]; 138 139 CC = toString ([ cc ] ++ ccArgs); 140 141 stripExt = source: lib.replaceStrings [ ".c" ] [ "" ] (builtins.baseNameOf source); 142 143 compile = 144 source: 145 kaem.runCommand (stripExt source) { } '' 146 mkdir ''${out} 147 cd ''${out} 148 ${CC} -c ${srcPrefix}/${source} 149 ''; 150 151 crt1 = compile "/lib/linux/x86-mes-mescc/crt1.c"; 152 153 getRes = suffix: res: "${res}/${res.name}${suffix}"; 154 155 archive = out: sources: "catm ${out} ${lib.concatMapStringsSep " " (getRes ".o") sources}"; 156 sourceArchive = out: sources: "catm ${out} ${lib.concatMapStringsSep " " (getRes ".s") sources}"; 157 158 mkLib = 159 libname: sources: 160 let 161 os = map compile sources; 162 in 163 kaem.runCommand "${pname}-${libname}-${version}" 164 { 165 inherit meta; 166 } 167 '' 168 LIBDIR=''${out}/lib 169 mkdir -p ''${LIBDIR} 170 cd ''${LIBDIR} 171 172 ${archive "${libname}.a" os} 173 ${sourceArchive "${libname}.s" os} 174 ''; 175 176 libc-mini = mkLib "libc-mini" libc_mini_SOURCES; 177 libmescc = mkLib "libmescc" libmescc_SOURCES; 178 libc = mkLib "libc" libc_SOURCES; 179 libc_tcc = mkLib "libc+tcc" libc_tcc_SOURCES; 180 181 # Recompile Mes and Mes C library using mes-m2 bootstrapped Mes 182 libs = 183 kaem.runCommand "${pname}-m2-libs-${version}" 184 { 185 inherit pname version; 186 187 passthru.tests.get-version = 188 result: 189 kaem.runCommand "${pname}-get-version-${version}" { } '' 190 ${result}/bin/mes --version 191 mkdir ''${out} 192 ''; 193 194 inherit meta; 195 } 196 '' 197 LIBDIR=''${out}/lib 198 mkdir -p ''${out} ''${LIBDIR} 199 200 mkdir -p ''${LIBDIR}/x86-mes 201 202 # crt1.o 203 cp ${crt1}/crt1.o ''${LIBDIR}/x86-mes 204 cp ${crt1}/crt1.s ''${LIBDIR}/x86-mes 205 206 # libc-mini.a 207 cp ${libc-mini}/lib/libc-mini.a ''${LIBDIR}/x86-mes 208 cp ${libc-mini}/lib/libc-mini.s ''${LIBDIR}/x86-mes 209 210 # libmescc.a 211 cp ${libmescc}/lib/libmescc.a ''${LIBDIR}/x86-mes 212 cp ${libmescc}/lib/libmescc.s ''${LIBDIR}/x86-mes 213 214 # libc.a 215 cp ${libc}/lib/libc.a ''${LIBDIR}/x86-mes 216 cp ${libc}/lib/libc.s ''${LIBDIR}/x86-mes 217 218 # libc+tcc.a 219 cp ${libc_tcc}/lib/libc+tcc.a ''${LIBDIR}/x86-mes 220 cp ${libc_tcc}/lib/libc+tcc.s ''${LIBDIR}/x86-mes 221 ''; 222 223 # Build mes itself 224 compiler = 225 kaem.runCommand "${pname}-${version}" 226 { 227 inherit pname version; 228 229 passthru.tests.get-version = 230 result: 231 kaem.runCommand "${pname}-get-version-${version}" { } '' 232 ${result}/bin/mes --version 233 mkdir ''${out} 234 ''; 235 236 inherit meta; 237 } 238 '' 239 mkdir -p ''${out}/bin 240 241 ${srcPost.bin}/bin/mes-m2 -e main ${srcPost.bin}/bin/mescc.scm -- \ 242 -L ''${srcPrefix}/lib \ 243 -L ${libs}/lib \ 244 -lc \ 245 -lmescc \ 246 -nostdlib \ 247 -o ''${out}/bin/mes \ 248 ${libs}/lib/x86-mes/crt1.o \ 249 ${lib.concatMapStringsSep " " (getRes ".o") (map compile mes_SOURCES)} 250 ''; 251in 252{ 253 inherit 254 src 255 srcPost 256 srcPrefix 257 nyacc 258 ; 259 inherit compiler libs; 260}