commit ea588fa8a7848ccd7a048251823d72559574f6a8
parent 643e8a40e46be15008645eecbeac019d7796552b
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Wed, 1 Jun 2022 14:16:10 +0200
driver/posix: Make easier to target a musl libc
This commit adds some boilerplate to make easier to support musl.
There are some corner cases that can produce some headaches but
it is a big improvement over what we had before.
Diffstat:
6 files changed, 44 insertions(+), 5 deletions(-)
diff --git a/Makefile b/Makefile
@@ -13,10 +13,13 @@ include $(PROJECTDIR)/scripts/rules.mk
ROOT = $(DESTDIR)$(PREFIX)
NODEP = 1
-all:
+all: config
+@$(MAKE) `$(SCRIPTDIR)/config -c` toolchain
+@$(MAKE) `$(SCRIPTDIR)/config` `uname -m`
+config:
+ cd include/scc/scc && $(MAKE) $@
+
install:
$(SCRIPTDIR)/install $(ROOT)
+@$(MAKE) install-`uname -m`
@@ -109,3 +112,7 @@ dirs: $(SCRIPTDIR)/libc-dirs
clean:
xargs rm -rf < $(SCRIPTDIR)/libc-dirs
rm -f dirs
+
+distclean: clean
+ rm -f include/scc/scc/sysld.h
+ rm -f include/scc/scc/sysincludes.h
diff --git a/README b/README
@@ -8,6 +8,10 @@ can be passed to the command line:
- PREFIX: Prefix of the path where scc toolchain is going
to be installed. /usr/local by default.
+ - LIBPREFIX: Prefix of the path where scc searchs for
+ headers and libraries when scc is executed. $PREFIX
+ by default.
+
- DESTDIR: Temporary directory prepend to PREFIX used in the
install path. It is mainly intended to help package maintainers
to install in a specific directory used as base for the package
@@ -55,6 +59,9 @@ The main targets of the Makefile are:
for all the available configurations based in the host
architecture.
+ - config
+ Generate headers supposed to be customized by the user.
+
- toolchain
Compile the toolchain with the default configuration
specified in CONF.
@@ -72,6 +79,28 @@ The main targets of the Makefile are:
- distclean
Remove all the generated files.
+Musl libc support
+=================
+The Scc libc is a C99 library and cannot used to compile POSIX compliant
+programs. Scc includes a template that can be used to use a musl libc
+compiled by gcc:
+
+ $ make LIBPROFILE=musl config
+
+It will generate the files sysld.h and sysincludes.h configured to be used
+with a musl libc. Beware that it is likely that those files have to be
+customized to fit your system because the macro GCCLIBPATH depends heavily
+of the toolchain used to compile musl. As the musl libc is likely
+will be installed in a different prefix the scc compilation must be modified
+to:
+
+ $ make LIBPREFIX=/usr/local/musl
+
+If the helper scc shell script is used instead of scc-cc then the
+environment variable SCCLIBPREFIX must be set:
+
+ $ SCCLIBPREFIX=/usr/local/musl scc hello.c
+
Deviations from standard C
===========================
This compiler aims to be fully compatible with the C99 standard, but
diff --git a/include/scc/scc/Makefile b/include/scc/scc/Makefile
@@ -10,21 +10,23 @@ SYSHDR =\
NODEP = 1
-all: $(SYSHDR)
+all: cstd.h
cstd.h: cstd-$(STD).h
cp cstd-$(STD).h $@
+config: sysld.h sysincludes.h
+
sysld.h:
set -e;\
rm -f $@;\
trap "rm -f $$$$.tmp" INT QUIT TERM HUP;\
sed -e 's/%NOPIE%/"$(NOPIE_LDFLAGS)",/' \
- -e 's/"",//' sysld.def.h > $$$$.tmp && \
+ -e 's/"",//' sysld.$(LIBPROFILE).h > $$$$.tmp && \
mv $$$$.tmp $@
sysincludes.h:
- cp sysincludes.def.h $@
+ cp sysincludes.$(LIBPROFILE).h $@
clean:
- rm -f $(SYSHDR)
+ rm -f cstd.h
diff --git a/include/scc/scc/sysincludes.def.h b/include/scc/scc/sysincludes.scc.h
diff --git a/include/scc/scc/sysld.def.h b/include/scc/scc/sysld.scc.h
diff --git a/scripts/rules.mk b/scripts/rules.mk
@@ -4,6 +4,7 @@ all:
# Define default configuration variables
PREFIX = /usr/local
LIBPREFIX = $(PREFIX)
+LIBPROFILE = scc
CONF = amd64-linux
TOOL = unix
HOST = posix