minimal-libc.tinycc-mes: refactor into common.nix
This commit is contained in:
@@ -17,5 +17,6 @@ lib.makeScope newScope (self: with self; {
|
||||
|
||||
ln-boot = callPackage ./ln-boot { };
|
||||
|
||||
tinycc-mes = callPackage ./tinycc/default.nix { };
|
||||
tinycc-bootstrappable = callPackage ./tinycc/bootstrappable.nix { };
|
||||
tinycc-mes = callPackage ./tinycc/mes.nix { };
|
||||
})
|
||||
|
||||
@@ -9,12 +9,14 @@
|
||||
|
||||
{ lib
|
||||
, runCommand
|
||||
, callPackage
|
||||
, fetchurl
|
||||
, mes
|
||||
, mes-libc
|
||||
, buildTinyccN
|
||||
}:
|
||||
let
|
||||
inherit (callPackage ./common.nix { }) buildTinyccMes;
|
||||
|
||||
version = "unstable-2023-04-20";
|
||||
rev = "80114c4da6b17fbaabb399cc29f427e368309bc8";
|
||||
|
||||
@@ -85,7 +87,7 @@ let
|
||||
# Bootstrap stage build flags obtained from
|
||||
# https://gitlab.com/janneke/tinycc/-/blob/80114c4da6b17fbaabb399cc29f427e368309bc8/boot.sh
|
||||
|
||||
tinycc-boot0 = buildTinyccN {
|
||||
tinycc-boot0 = buildTinyccMes {
|
||||
pname = "tinycc-boot0";
|
||||
inherit src version meta;
|
||||
prev = tinycc-boot-mes;
|
||||
@@ -98,7 +100,7 @@ let
|
||||
];
|
||||
};
|
||||
|
||||
tinycc-boot1 = buildTinyccN {
|
||||
tinycc-boot1 = buildTinyccMes {
|
||||
pname = "tinycc-boot1";
|
||||
inherit src version meta;
|
||||
prev = tinycc-boot0;
|
||||
@@ -112,7 +114,7 @@ let
|
||||
];
|
||||
};
|
||||
|
||||
tinycc-boot2 = buildTinyccN {
|
||||
tinycc-boot2 = buildTinyccMes {
|
||||
pname = "tinycc-boot2";
|
||||
inherit src version meta;
|
||||
prev = tinycc-boot1;
|
||||
@@ -128,7 +130,7 @@ let
|
||||
];
|
||||
};
|
||||
|
||||
tinycc-boot3 = buildTinyccN {
|
||||
tinycc-boot3 = buildTinyccMes {
|
||||
pname = "tinycc-boot3";
|
||||
inherit src version meta;
|
||||
prev = tinycc-boot2;
|
||||
@@ -143,21 +145,19 @@ let
|
||||
"-D HAVE_LONG_LONG=1"
|
||||
];
|
||||
};
|
||||
|
||||
tinycc-bootstrappable = buildTinyccN {
|
||||
pname = "tinycc-bootstrappable";
|
||||
inherit src version meta;
|
||||
prev = tinycc-boot3;
|
||||
buildOptions = [
|
||||
"-D HAVE_BITFIELD=1"
|
||||
"-D HAVE_FLOAT=1"
|
||||
"-D HAVE_LONG_LONG=1"
|
||||
"-D HAVE_SETJMP=1"
|
||||
];
|
||||
libtccBuildOptions = [
|
||||
"-D HAVE_FLOAT=1"
|
||||
"-D HAVE_LONG_LONG=1"
|
||||
];
|
||||
};
|
||||
in
|
||||
tinycc-bootstrappable
|
||||
buildTinyccMes {
|
||||
pname = "tinycc-bootstrappable";
|
||||
inherit src version meta;
|
||||
prev = tinycc-boot3;
|
||||
buildOptions = [
|
||||
"-D HAVE_BITFIELD=1"
|
||||
"-D HAVE_FLOAT=1"
|
||||
"-D HAVE_LONG_LONG=1"
|
||||
"-D HAVE_SETJMP=1"
|
||||
];
|
||||
libtccBuildOptions = [
|
||||
"-D HAVE_FLOAT=1"
|
||||
"-D HAVE_LONG_LONG=1"
|
||||
];
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
{ lib
|
||||
, runCommand
|
||||
, mes-libc
|
||||
, ln-boot
|
||||
}:
|
||||
{
|
||||
buildTinyccMes = {
|
||||
pname,
|
||||
version,
|
||||
src,
|
||||
prev,
|
||||
buildOptions,
|
||||
libtccBuildOptions,
|
||||
meta
|
||||
}:
|
||||
let
|
||||
options = lib.strings.concatStringsSep " " buildOptions;
|
||||
libtccOptions = lib.strings.concatStringsSep " " libtccBuildOptions;
|
||||
in
|
||||
runCommand "${pname}-${version}" {
|
||||
inherit pname version meta;
|
||||
nativeBuildInputs = [ ln-boot ];
|
||||
} ''
|
||||
catm config.h
|
||||
mkdir -p ''${out}/bin
|
||||
${prev}/bin/tcc \
|
||||
-g \
|
||||
-v \
|
||||
-static \
|
||||
-o ''${out}/bin/tcc \
|
||||
-D BOOTSTRAP=1 \
|
||||
${options} \
|
||||
-I . \
|
||||
-I ${src} \
|
||||
-D TCC_TARGET_I386=1 \
|
||||
-D CONFIG_TCCDIR=\"''${out}/lib\" \
|
||||
-D CONFIG_TCC_CRTPREFIX=\"''${out}/lib\" \
|
||||
-D CONFIG_TCC_ELFINTERP=\"\" \
|
||||
-D CONFIG_TCC_LIBPATHS=\"''${out}/lib\" \
|
||||
-D CONFIG_TCC_SYSINCLUDEPATHS=\"${mes-libc}/include:${src}/include\" \
|
||||
-D TCC_LIBGCC=\"libc.a\" \
|
||||
-D TCC_LIBTCC1=\"libtcc1.a\" \
|
||||
-D CONFIG_TCCBOOT=1 \
|
||||
-D CONFIG_TCC_STATIC=1 \
|
||||
-D CONFIG_USE_LIBGCC=1 \
|
||||
-D TCC_MES_LIBC=1 \
|
||||
-D TCC_VERSION=\"${version}\" \
|
||||
-D ONE_SOURCE=1 \
|
||||
-L ${prev}/lib \
|
||||
${src}/tcc.c
|
||||
|
||||
''${out}/bin/tcc -v
|
||||
|
||||
# Recompile libc: crt{1,n,i}, libtcc.a, libc.a, libgetopt.a
|
||||
mkdir -p ''${out}/lib
|
||||
''${out}/bin/tcc ${mes-libc.CFLAGS} -c -o ''${out}/lib/crt1.o ${mes-libc}/lib/crt1.c
|
||||
''${out}/bin/tcc ${mes-libc.CFLAGS} -c -o ''${out}/lib/crtn.o ${mes-libc}/lib/crtn.c
|
||||
''${out}/bin/tcc ${mes-libc.CFLAGS} -c -o ''${out}/lib/crti.o ${mes-libc}/lib/crti.c
|
||||
''${out}/bin/tcc -c -D TCC_TARGET_I386=1 ${libtccOptions} -o libtcc1.o ${src}/lib/libtcc1.c
|
||||
''${out}/bin/tcc -ar cr ''${out}/lib/libtcc1.a libtcc1.o
|
||||
''${out}/bin/tcc ${mes-libc.CFLAGS} -c -o libc.o ${mes-libc}/lib/libc.c
|
||||
''${out}/bin/tcc -ar cr ''${out}/lib/libc.a libc.o
|
||||
''${out}/bin/tcc ${mes-libc.CFLAGS} -c -o getopt.o ${mes-libc}/lib/getopt.c
|
||||
''${out}/bin/tcc -ar cr ''${out}/lib/libgetopt.a getopt.o
|
||||
|
||||
# Install headers
|
||||
ln -s ${mes-libc}/include ''${out}/include
|
||||
'';
|
||||
}
|
||||
@@ -1,154 +0,0 @@
|
||||
# Build steps adapted from https://github.com/fosslinux/live-bootstrap/blob/1bc4296091c51f53a5598050c8956d16e945b0f5/sysa/tcc-0.9.27/tcc-0.9.27.kaem
|
||||
#
|
||||
# SPDX-FileCopyrightText: 2021-22 fosslinux <fosslinux@aussies.space>
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
{ lib
|
||||
, runCommand
|
||||
, fetchurl
|
||||
, callPackage
|
||||
, mes
|
||||
, mes-libc
|
||||
, ln-boot
|
||||
}:
|
||||
let
|
||||
version = "unstable-2023-04-20";
|
||||
rev = "86f3d8e33105435946383aee52487b5ddf918140";
|
||||
|
||||
tarball = fetchurl {
|
||||
url = "https://repo.or.cz/tinycc.git/snapshot/${rev}.tar.gz";
|
||||
sha256 = "11idrvbwfgj1d03crv994mpbbbyg63j1k64lw1gjy7mkiifw2xap";
|
||||
};
|
||||
src = (runCommand "tinycc-${version}-source" {} ''
|
||||
ungz --file ${tarball} --output tinycc.tar
|
||||
mkdir -p ''${out}
|
||||
cd ''${out}
|
||||
untar --file ''${NIX_BUILD_TOP}/tinycc.tar
|
||||
'') + "/tinycc-${builtins.substring 0 7 rev}";
|
||||
|
||||
meta = with lib; {
|
||||
description = "Small, fast, and embeddable C compiler and interpreter";
|
||||
homepage = "https://repo.or.cz/w/tinycc.git";
|
||||
license = licenses.lgpl21Only;
|
||||
maintainers = with maintainers; [ emilytrau ];
|
||||
platforms = [ "i686-linux" ];
|
||||
};
|
||||
|
||||
buildTinyccN = {
|
||||
pname,
|
||||
version,
|
||||
src,
|
||||
prev,
|
||||
buildOptions,
|
||||
libtccBuildOptions,
|
||||
meta
|
||||
}:
|
||||
let
|
||||
options = lib.strings.concatStringsSep " " buildOptions;
|
||||
libtccOptions = lib.strings.concatStringsSep " " libtccBuildOptions;
|
||||
in
|
||||
runCommand "${pname}-${version}" {
|
||||
inherit pname version meta;
|
||||
nativeBuildInputs = [ ln-boot ];
|
||||
} ''
|
||||
catm config.h
|
||||
mkdir -p ''${out}/bin
|
||||
${prev}/bin/tcc \
|
||||
-g \
|
||||
-v \
|
||||
-static \
|
||||
-o ''${out}/bin/tcc \
|
||||
-D BOOTSTRAP=1 \
|
||||
${options} \
|
||||
-I . \
|
||||
-I ${src} \
|
||||
-D TCC_TARGET_I386=1 \
|
||||
-D CONFIG_TCCDIR=\"''${out}/lib\" \
|
||||
-D CONFIG_TCC_CRTPREFIX=\"''${out}/lib\" \
|
||||
-D CONFIG_TCC_ELFINTERP=\"\" \
|
||||
-D CONFIG_TCC_LIBPATHS=\"''${out}/lib\" \
|
||||
-D CONFIG_TCC_SYSINCLUDEPATHS=\"${mes-libc}/include:${src}/include\" \
|
||||
-D TCC_LIBGCC=\"libc.a\" \
|
||||
-D TCC_LIBTCC1=\"libtcc1.a\" \
|
||||
-D CONFIG_TCCBOOT=1 \
|
||||
-D CONFIG_TCC_STATIC=1 \
|
||||
-D CONFIG_USE_LIBGCC=1 \
|
||||
-D TCC_MES_LIBC=1 \
|
||||
-D TCC_VERSION=\"${version}\" \
|
||||
-D ONE_SOURCE=1 \
|
||||
-L ${prev}/lib \
|
||||
${src}/tcc.c
|
||||
|
||||
''${out}/bin/tcc -v
|
||||
|
||||
# Recompile libc: crt{1,n,i}, libtcc.a, libc.a, libgetopt.a
|
||||
mkdir -p ''${out}/lib
|
||||
''${out}/bin/tcc ${mes-libc.CFLAGS} -c -o ''${out}/lib/crt1.o ${mes-libc}/lib/crt1.c
|
||||
''${out}/bin/tcc ${mes-libc.CFLAGS} -c -o ''${out}/lib/crtn.o ${mes-libc}/lib/crtn.c
|
||||
''${out}/bin/tcc ${mes-libc.CFLAGS} -c -o ''${out}/lib/crti.o ${mes-libc}/lib/crti.c
|
||||
''${out}/bin/tcc -c -D TCC_TARGET_I386=1 ${libtccOptions} -o libtcc1.o ${src}/lib/libtcc1.c
|
||||
''${out}/bin/tcc -ar cr ''${out}/lib/libtcc1.a libtcc1.o
|
||||
''${out}/bin/tcc ${mes-libc.CFLAGS} -c -o libc.o ${mes-libc}/lib/libc.c
|
||||
''${out}/bin/tcc -ar cr ''${out}/lib/libc.a libc.o
|
||||
''${out}/bin/tcc ${mes-libc.CFLAGS} -c -o getopt.o ${mes-libc}/lib/getopt.c
|
||||
''${out}/bin/tcc -ar cr ''${out}/lib/libgetopt.a getopt.o
|
||||
|
||||
# Install headers
|
||||
ln -s ${mes-libc}/include ''${out}/include
|
||||
'';
|
||||
|
||||
tinycc-bootstrappable = callPackage ./bootstrappable.nix { inherit buildTinyccN; };
|
||||
|
||||
tccdefs = runCommand "tccdefs-${version}" {} ''
|
||||
mkdir ''${out}
|
||||
${tinycc-bootstrappable}/bin/tcc -static -DC2STR -o c2str ${src}/conftest.c
|
||||
./c2str ${src}/include/tccdefs.h ''${out}/tccdefs_.h
|
||||
'';
|
||||
|
||||
tinycc-mes-boot = buildTinyccN {
|
||||
pname = "tinycc-mes-boot";
|
||||
inherit src version meta;
|
||||
prev = tinycc-bootstrappable;
|
||||
buildOptions = [
|
||||
"-D HAVE_BITFIELD=1"
|
||||
"-D HAVE_FLOAT=1"
|
||||
"-D HAVE_LONG_LONG=1"
|
||||
"-D HAVE_SETJMP=1"
|
||||
"-D CONFIG_TCC_PREDEFS=1"
|
||||
"-I ${tccdefs}"
|
||||
"-D CONFIG_TCC_SEMLOCK=0"
|
||||
];
|
||||
libtccBuildOptions = [
|
||||
"-D HAVE_FLOAT=1"
|
||||
"-D HAVE_LONG_LONG=1"
|
||||
"-D CONFIG_TCC_PREDEFS=1"
|
||||
"-I ${tccdefs}"
|
||||
"-D CONFIG_TCC_SEMLOCK=0"
|
||||
];
|
||||
};
|
||||
|
||||
tinycc-mes = buildTinyccN {
|
||||
pname = "tinycc-mes";
|
||||
inherit src version meta;
|
||||
prev = tinycc-mes-boot;
|
||||
buildOptions = [
|
||||
"-std=c99"
|
||||
"-D HAVE_BITFIELD=1"
|
||||
"-D HAVE_FLOAT=1"
|
||||
"-D HAVE_LONG_LONG=1"
|
||||
"-D HAVE_SETJMP=1"
|
||||
"-D CONFIG_TCC_PREDEFS=1"
|
||||
"-I ${tccdefs}"
|
||||
"-D CONFIG_TCC_SEMLOCK=0"
|
||||
];
|
||||
libtccBuildOptions = [
|
||||
"-D HAVE_FLOAT=1"
|
||||
"-D HAVE_LONG_LONG=1"
|
||||
"-D CONFIG_TCC_PREDEFS=1"
|
||||
"-I ${tccdefs}"
|
||||
"-D CONFIG_TCC_SEMLOCK=0"
|
||||
];
|
||||
};
|
||||
in
|
||||
tinycc-mes
|
||||
@@ -0,0 +1,87 @@
|
||||
# Build steps adapted from https://github.com/fosslinux/live-bootstrap/blob/1bc4296091c51f53a5598050c8956d16e945b0f5/sysa/tcc-0.9.27/tcc-0.9.27.kaem
|
||||
#
|
||||
# SPDX-FileCopyrightText: 2021-22 fosslinux <fosslinux@aussies.space>
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
{ lib
|
||||
, runCommand
|
||||
, fetchurl
|
||||
, callPackage
|
||||
, tinycc-bootstrappable
|
||||
}:
|
||||
let
|
||||
inherit (callPackage ./common.nix { }) buildTinyccMes;
|
||||
|
||||
version = "unstable-2023-04-20";
|
||||
rev = "86f3d8e33105435946383aee52487b5ddf918140";
|
||||
|
||||
tarball = fetchurl {
|
||||
url = "https://repo.or.cz/tinycc.git/snapshot/${rev}.tar.gz";
|
||||
sha256 = "11idrvbwfgj1d03crv994mpbbbyg63j1k64lw1gjy7mkiifw2xap";
|
||||
};
|
||||
src = (runCommand "tinycc-${version}-source" {} ''
|
||||
ungz --file ${tarball} --output tinycc.tar
|
||||
mkdir -p ''${out}
|
||||
cd ''${out}
|
||||
untar --file ''${NIX_BUILD_TOP}/tinycc.tar
|
||||
'') + "/tinycc-${builtins.substring 0 7 rev}";
|
||||
|
||||
meta = with lib; {
|
||||
description = "Small, fast, and embeddable C compiler and interpreter";
|
||||
homepage = "https://repo.or.cz/w/tinycc.git";
|
||||
license = licenses.lgpl21Only;
|
||||
maintainers = with maintainers; [ emilytrau ];
|
||||
platforms = [ "i686-linux" ];
|
||||
};
|
||||
|
||||
tccdefs = runCommand "tccdefs-${version}" {} ''
|
||||
mkdir ''${out}
|
||||
${tinycc-bootstrappable}/bin/tcc -static -DC2STR -o c2str ${src}/conftest.c
|
||||
./c2str ${src}/include/tccdefs.h ''${out}/tccdefs_.h
|
||||
'';
|
||||
|
||||
tinycc-mes-boot = buildTinyccMes {
|
||||
pname = "tinycc-mes-boot";
|
||||
inherit src version meta;
|
||||
prev = tinycc-bootstrappable;
|
||||
buildOptions = [
|
||||
"-D HAVE_BITFIELD=1"
|
||||
"-D HAVE_FLOAT=1"
|
||||
"-D HAVE_LONG_LONG=1"
|
||||
"-D HAVE_SETJMP=1"
|
||||
"-D CONFIG_TCC_PREDEFS=1"
|
||||
"-I ${tccdefs}"
|
||||
"-D CONFIG_TCC_SEMLOCK=0"
|
||||
];
|
||||
libtccBuildOptions = [
|
||||
"-D HAVE_FLOAT=1"
|
||||
"-D HAVE_LONG_LONG=1"
|
||||
"-D CONFIG_TCC_PREDEFS=1"
|
||||
"-I ${tccdefs}"
|
||||
"-D CONFIG_TCC_SEMLOCK=0"
|
||||
];
|
||||
};
|
||||
in
|
||||
buildTinyccMes {
|
||||
pname = "tinycc-mes";
|
||||
inherit src version meta;
|
||||
prev = tinycc-mes-boot;
|
||||
buildOptions = [
|
||||
"-std=c99"
|
||||
"-D HAVE_BITFIELD=1"
|
||||
"-D HAVE_FLOAT=1"
|
||||
"-D HAVE_LONG_LONG=1"
|
||||
"-D HAVE_SETJMP=1"
|
||||
"-D CONFIG_TCC_PREDEFS=1"
|
||||
"-I ${tccdefs}"
|
||||
"-D CONFIG_TCC_SEMLOCK=0"
|
||||
];
|
||||
libtccBuildOptions = [
|
||||
"-D HAVE_FLOAT=1"
|
||||
"-D HAVE_LONG_LONG=1"
|
||||
"-D CONFIG_TCC_PREDEFS=1"
|
||||
"-I ${tccdefs}"
|
||||
"-D CONFIG_TCC_SEMLOCK=0"
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user