nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1#!/usr/bin/env nix-shell
2#!nix-shell -i bash -p bash coreutils gnutar
3
4# Generate a sources.nix for a version of GNU mes. Creates lists of source files
5# from build-aux/configure-lib.sh.
6#
7# You may point this tool at a manually downloaded tarball, but more ideal is
8# using the source tarball from Nixpkgs. For example:
9#
10# MES_TARBALL="$(nix-build --no-link -A minimal-bootstrap.mes.src ../../../../..)"
11# ./gen-sources.sh "$MES_TARBALL" > ./new-sources.nix
12
13set -eu
14
15# Supported platforms
16ARCHS="x86"
17KERNELS="linux"
18COMPILERS="mescc gcc"
19
20
21format() {
22 echo "["
23 echo $* | xargs printf ' "%s"\n'
24 echo " ]"
25}
26
27gen_sources() {
28 # Configuration variables used by configure-lib.sh
29 export mes_libc=mes
30 export mes_cpu=$1
31 export mes_kernel=$2
32 export compiler=$3
33
34 # Populate source file lists
35 source $CONFIGURE_LIB_SH
36
37 cat <<EOF
38 $mes_cpu.$mes_kernel.$compiler = {
39 libc_mini_SOURCES = $(format $libc_mini_SOURCES);
40 libmescc_SOURCES = $(format $libmescc_SOURCES);
41 libtcc1_SOURCES = $(format $libtcc1_SOURCES);
42 libc_SOURCES = $(format $libc_SOURCES);
43 libc_tcc_SOURCES = $(format $libc_tcc_SOURCES);
44 libc_gnu_SOURCES = $(format $libc_gnu_SOURCES);
45 mes_SOURCES = $(format $mes_SOURCES);
46 };
47EOF
48}
49
50
51MES_TARBALL=$1
52if [ ! -f $MES_TARBALL ]; then
53 echo "Provide path to mes-x.x.x.tar.gz as first argument" >&2
54 exit 1
55fi
56echo "Generating sources.nix from $MES_TARBALL" >&2
57
58TMP=$(mktemp -d)
59cd $TMP
60echo "Workdir: $TMP" >&2
61
62echo "Extracting $MES_TARBALL" >&2
63tar --strip-components 1 -xf $MES_TARBALL
64
65CONFIGURE_LIB_SH="$TMP/build-aux/configure-lib.sh"
66if [ ! -f $CONFIGURE_LIB_SH ]; then
67 echo "Could not find mes's configure-lib.sh script at $CONFIGURE_LIB_SH" >&2
68 exit 1
69fi
70
71# Create dummy config expected by configure-lib.sh
72touch config.sh
73chmod +x config.sh
74
75
76echo "Configuring with $CONFIGURE_LIB_SH" >&2
77
78cat <<EOF
79# This file is generated by ./gen-sources.sh.
80# Do not edit!
81{
82EOF
83
84for arch in $ARCHS; do
85 for kernel in $KERNELS; do
86 for compiler in $COMPILERS; do
87 gen_sources $arch $kernel $compiler
88 done
89 done
90done
91
92cat <<EOF
93}
94EOF