blob: a3f6c580f464f101e148f0e46edda96c5cf556f1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
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
|