← Back to davo.co
aboutsummaryrefslogtreecommitdiffstats
path: root/build-musl
diff options
context:
space:
mode:
authorDavid Faulkner <[email protected]>2026-08-07 23:40:47 -0500
committerDavid Faulkner <[email protected]>2026-08-07 23:40:47 -0500
commitb3e9e62599532050fc776c5e8f076915b56c2235 (patch)
treeaf252346106a61b18cc6fc6fdbd32e962d096f1c /build-musl
Import official C23 code examples for Modern C (Jens Gustedt, 2024)HEADupstream-importmain
- Add official C source files, Makefile, c23-fallback.h, and LICENSE - Update README.md with study mirror notice
Diffstat (limited to 'build-musl')
-rw-r--r--build-musl120
1 files changed, 120 insertions, 0 deletions
diff --git a/build-musl b/build-musl
new file mode 100644
index 0000000..a3f6c58
--- /dev/null
+++ b/build-musl
@@ -0,0 +1,120 @@
+#!/bin/sh
+
+# A script to configure the musl C library
+
+# This is intended to provide you with a way to use the musl C library
+# with modern compilers such that you will be able to use most C23
+# features that such compilers already provide.
+#
+# Note that this script not suited for cross compilation.
+#
+# You need
+#
+# - a native Linux system, with musl or glibc, regardless
+#
+# - a modern C compiler with good support for C23 features such as gcc
+# (starting with version 13) or clang (starting with 17).
+
+# - a directory (denoted by sourceDir in the following) with the musl
+# source plus C23 patches as provided here:
+#
+# https://forge.icube.unistra.fr/icps/musl/-/branches
+#
+# As these patches will hopefully be integrated more and more into
+# musl's main line this is a moving target and you should make sure
+# that you always grab the latest c23 branch. As of this writing
+# this is c23-v11.
+#
+# - Root rights (so-called sudoer rights in Linux slang) to be able to
+# install the compiled library and wrappers in a system wide
+# directory, "/usr/local" per default.
+#
+# To configure, compile and install
+#
+# cd sourceDir
+# path/to/this/directory/build-musl COMPILER [FLAG] [LOGFILE]
+#
+# where
+#
+# - COMPILER is the name of the compiler, for example "gcc-13" or
+# "clang-17".
+#
+# (FLAG and LOGFILE are optional and not interesting in general.)
+#
+# For example with
+#
+# path/to/this/directory/build-musl clang-18
+#
+# the LOGFILE is musl-log-clang-18.txt in sourceDir, and the
+# installation is in /usr/local/musl-clang-18. Note that to be able to
+# install, it is usually necessary to collect your password, which is
+# done by a program referred to by the SUDO_ASKPASS variable
+# below. Per default this will result in a popup at the end of
+# compilation that blocks your screen.
+
+# The interface that you then should use is bin/cc, for the example
+# above that would be
+#
+# /usr/local/musl-clang-18/bin/cc
+#
+# You should be able to use this just as any other compiler
+# interface. To use this interface to compile in C23 mode you probably
+# have to add an option "-std=c23" or "-std=c2x".
+
+
+PREFIXDIR="${PREFIXDIR:-/usr/local}"
+LOGFILE="${LOGFILE:-musl-log}"
+SUDO_ASKPASS="${SUDO_ASKPASS:-/usr/bin/ssh-askpass}"
+
+export SUDO_ASKPASS
+
+COMMANDLINE="$*"
+
+if [ $# -gt 0 ] ; then
+ export CC="$1"
+ PREFIXDIR="${PREFIXDIR}/musl-$1"
+ LOGFILE="${LOGFILE}-$1"
+ shift
+fi
+
+if [ $# -gt 0 ] ; then
+ export CFLAGS="-std=$1"
+ PREFIXDIR="${PREFIXDIR}-$1"
+ LOGFILE="${LOGFILE}-$1"
+ shift
+fi
+
+if [ $# -gt 0 ] ; then
+ export CFLAGS="${CFLAGS} $*"
+ PREFIXDIR="${PREFIXDIR}-$1"
+ LOGFILE="${LOGFILE}-$1"
+fi
+
+LOGFILE="${LOGFILE}.txt"
+
+echo > "${LOGFILE}"
+
+echo "command line: ${COMMANDLINE}" | tee -a "${LOGFILE}"
+echo "building musl with prefix '${PREFIXDIR}', ask-pass '${SUDO_ASKPASS}'" | tee -a "${LOGFILE}"
+echo " compiler '${CC}' and flags '${CFLAGS}'" | tee -a "${LOGFILE}"
+echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" | tee -a "${LOGFILE}"
+./configure "--prefix=${PREFIXDIR}" 2>&1 1>>"${LOGFILE}"
+if [ $? -ne 0 ] ; then
+ echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" | tee -a "${LOGFILE}"
+ echo "configuration failed" | tee -a "${LOGFILE}"
+ cat "${LOGFILE}"
+ exit 1
+fi
+echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" | tee -a "${LOGFILE}"
+make clean 2>&1 | tee -a "${LOGFILE}"
+echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" | tee -a "${LOGFILE}"
+make -j 8 2>&1 | tee -a "${LOGFILE}"
+echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" | tee -a "${LOGFILE}"
+sudo -A make install 2>&1 | tee -a "${LOGFILE}"
+echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" | tee -a "${LOGFILE}"
+
+if [ -x "${PREFIXDIR}/bin/musl-gcc" ] ; then
+ sudo -A ln -sf "musl-gcc" "${PREFIXDIR}/bin/cc" 2>&1 | tee -a "${LOGFILE}"
+elif [ -x "${PREFIXDIR}/bin/musl-clang" ] ; then
+ sudo -A ln -sf "musl-clang" "${PREFIXDIR}/bin/cc" 2>&1 | tee -a "${LOGFILE}"
+fi