shithub: scc

Download patch

ref: ea588fa8a7848ccd7a048251823d72559574f6a8
parent: 643e8a40e46be15008645eecbeac019d7796552b
author: Roberto E. Vargas Caballero <[email protected]>
date: Wed Jun 1 10:16:10 EDT 2022

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.

--- a/Makefile
+++ b/Makefile
@@ -13,10 +13,13 @@
 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 @@
 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
--- a/README
+++ b/README
@@ -8,6 +8,10 @@
 	- 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 @@
 	  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.
@@ -71,6 +78,28 @@
 
 	- 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
 ===========================
--- a/include/scc/scc/Makefile
+++ b/include/scc/scc/Makefile
@@ -10,21 +10,23 @@
 
 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
--- a/include/scc/scc/sysincludes.def.h
+++ /dev/null
@@ -1,8 +1,0 @@
-/* configure below your standard sys include paths */
-char *sysincludes[] = {
-	"%p/include/bits/%a/",
-	"%p/include/bits/%s/",
-	"%p/include/bits/%s/%a/",
-	"%p/include/",
-	NULL
-};
--- /dev/null
+++ b/include/scc/scc/sysincludes.scc.h
@@ -1,0 +1,8 @@
+/* configure below your standard sys include paths */
+char *sysincludes[] = {
+	"%p/include/bits/%a/",
+	"%p/include/bits/%s/",
+	"%p/include/bits/%s/%a/",
+	"%p/include/",
+	NULL
+};
--- a/include/scc/scc/sysld.def.h
+++ /dev/null
@@ -1,14 +1,0 @@
-/* configure below your system linker command line */
-
-char *ldcmd[] = {
-	"-static",
-	"-z","nodefaultlib",
-	%NOPIE%
-	"-o","%o",
-	"-L","%p/lib/scc/%a-%s",
-	"%p/lib/scc/%a-%s/crt.o",
-	"%c",
-	"-lc",
-	"-lcrt",
-        NULL
-};
--- /dev/null
+++ b/include/scc/scc/sysld.scc.h
@@ -1,0 +1,14 @@
+/* configure below your system linker command line */
+
+char *ldcmd[] = {
+	"-static",
+	"-z","nodefaultlib",
+	%NOPIE%
+	"-o","%o",
+	"-L","%p/lib/scc/%a-%s",
+	"%p/lib/scc/%a-%s/crt.o",
+	"%c",
+	"-lc",
+	"-lcrt",
+        NULL
+};
--- a/scripts/rules.mk
+++ b/scripts/rules.mk
@@ -4,6 +4,7 @@
 # Define default configuration variables
 PREFIX = /usr/local
 LIBPREFIX = $(PREFIX)
+LIBPROFILE = scc
 CONF = amd64-linux
 TOOL = unix
 HOST = posix