]> git.ipfire.org Git - thirdparty/dracut.git/blame - configure
fix(zfcp_rules): correct shellcheck regression when parsing ccw args
[thirdparty/dracut.git] / configure
CommitLineData
103281f3 1#!/bin/bash
103281f3
CW
2
3# We don't support srcdir != builddir
9a52c3fd 4echo \#buildapi-variable-no-builddir > /dev/null
103281f3
CW
5
6prefix=/usr
7
2692a422 8enable_documentation=yes
51d21c6b 9enable_dracut_cpio=no
2692a422 10
62f27ee6 11CC="${CC:-cc}"
699414f5
MAP
12PKG_CONFIG="${PKG_CONFIG:-pkg-config}"
13
103281f3
CW
14# Little helper function for reading args from the commandline.
15# it automatically handles -a b and -a=b variants, and returns 1 if
16# we need to shift $3.
17read_arg() {
18 # $1 = arg name
19 # $2 = arg value
20 # $3 = arg parameter
21 local rematch='^[^=]*=(.*)$'
22 if [[ $2 =~ $rematch ]]; then
f4053eb0 23 read -r "$1" <<< "${BASH_REMATCH[1]}"
103281f3 24 else
f4053eb0 25 read -r "$1" <<< "$3"
103281f3
CW
26 # There is no way to shift our callers args, so
27 # return 1 to indicate they should do it instead.
28 return 1
29 fi
1d4b3375 30 return 0
103281f3
CW
31}
32
33while (($# > 0)); do
34 case "${1%%=*}" in
9a52c3fd
HH
35 --prefix) read_arg prefix "$@" || shift ;;
36 --libdir) read_arg libdir "$@" || shift ;;
37 --datadir) read_arg datadir "$@" || shift ;;
38 --sysconfdir) read_arg sysconfdir "$@" || shift ;;
39 --sbindir) read_arg sbindir "$@" || shift ;;
40 --mandir) read_arg mandir "$@" || shift ;;
41 --disable-documentation) enable_documentation=no ;;
42 --program-prefix) read_arg programprefix "$@" || shift ;;
43 --exec-prefix) read_arg execprefix "$@" || shift ;;
44 --bindir) read_arg bindir "$@" || shift ;;
45 --includedir) read_arg includedir "$@" || shift ;;
46 --libexecdir) read_arg libexecdir "$@" || shift ;;
47 --localstatedir) read_arg localstatedir "$@" || shift ;;
48 --sharedstatedir) read_arg sharedstatedir "$@" || shift ;;
49 --infodir) read_arg infodir "$@" || shift ;;
50 --systemdsystemunitdir) read_arg systemdsystemunitdir "$@" || shift ;;
51 --bashcompletiondir) read_arg bashcompletiondir "$@" || shift ;;
51d21c6b 52 --enable-dracut-cpio) enable_dracut_cpio=yes ;;
9a52c3fd 53 *) echo "Ignoring unknown option '$1'" ;;
103281f3
CW
54 esac
55 shift
56done
57
7bb80835
YW
58if ! ${PKG_CONFIG} --exists --print-errors " libkmod >= 23 "; then
59 echo "dracut needs pkg-config and libkmod >= 23." >&2
607fec3e
HH
60 exit 1
61fi
62
4980bad3
AAF
63if ! command -v "${CC}" > /dev/null; then
64 echo "dracut needs a C compiler (${CC} not found)." >&2
65 exit 1
66fi
67
9a52c3fd 68cat << EOF > conftest.c
62f27ee6
DTCD
69#include <fts.h>
70int main() {
71 return 0;
72}
73EOF
74
f4053eb0 75# shellcheck disable=SC2086
9a52c3fd 76${CC} $CFLAGS $LDFLAGS conftest.c > /dev/null 2>&1
62f27ee6
DTCD
77ret=$?
78rm -f conftest.c a.out
79
80# musl doesn't have fts.h included
81if test $ret -ne 0; then
9a52c3fd
HH
82 echo "dracut needs fts development files." >&2
83 exit 1
62f27ee6
DTCD
84fi
85
9a52c3fd 86cat << EOF > conftest.c
62f27ee6
DTCD
87#include <fts.h>
88int main(void) {
89 fts_open(0, 0, 0);
90 return 0;
91}
92EOF
93
94found=no
95for lib in "-lc" "-lfts"; do
9a52c3fd
HH
96 # shellcheck disable=SC2086
97 ${CC} $CFLAGS $LDFLAGS conftest.c -Wl,$lib > /dev/null 2>&1
98 ret=$?
99 if test $ret -eq 0; then
100 FTS_LIBS="$lib"
101 found=yes
102 break
103 fi
62f27ee6
DTCD
104done
105rm -f conftest.c a.out
106
107if test $found = no; then
9a52c3fd
HH
108 echo "dracut couldn't find usable fts library" >&2
109 exit 1
62f27ee6
DTCD
110fi
111
0ef40d88
SS
112cat << EOF > conftest.c
113#include <stdio.h>
114#include <unistd.h>
115#include <sys/syscall.h>
116
117#ifndef SYS_gettid
118#error "SYS_gettid unavailable on this system"
119#endif
120
121#define gettid() ((pid_t) syscall(SYS_gettid))
122
123int main(void) {
124 return getpid() == gettid() ? 0 : -1;
125}
126EOF
127
128# shellcheck disable=SC2086
129${CC} $CFLAGS $LDFLAGS conftest.c > /dev/null 2>&1
130ret=$?
131rm -f conftest.c a.out
132
133if test $ret -ne 0; then
134 echo "dracut needs SYS_gettid support." >&2
135 exit 1
136fi
137
51d21c6b
DD
138if test "$enable_dracut_cpio" = "yes"; then
139 cargo --version > /dev/null
140 ret=$?
141 if test $ret -ne 0; then
142 echo "dracut couldn't find cargo for dracut-cpio build"
143 exit 1
144 fi
145fi
146
9a52c3fd 147cat > Makefile.inc.$$ << EOF
103281f3
CW
148prefix ?= ${prefix}
149libdir ?= ${libdir:-${prefix}/lib}
150datadir ?= ${datadir:-${prefix}/share}
151sysconfdir ?= ${sysconfdir:-${prefix}/etc}
152sbindir ?= ${sbindir:-${prefix}/sbin}
153mandir ?= ${mandir:-${prefix}/share/man}
1d4b3375 154enable_documentation ?= ${enable_documentation:-yes}
51d21c6b 155enable_dracut_cpio ?= ${enable_dracut_cpio}
1d4b3375 156bindir ?= ${bindir:-${prefix}/bin}
2a0da60e
HH
157KMOD_CFLAGS ?= $(${PKG_CONFIG} --cflags " libkmod >= 23 ")
158KMOD_LIBS ?= $(${PKG_CONFIG} --libs " libkmod >= 23 ")
62f27ee6 159FTS_LIBS ?= ${FTS_LIBS}
103281f3 160EOF
1d4b3375
HH
161
162{
163 [[ $programprefix ]] && echo "programprefix ?= ${programprefix}"
164 [[ $execprefix ]] && echo "execprefix ?= ${execprefix}"
165 [[ $includedir ]] && echo "includedir ?= ${includedir}"
166 [[ $libexecdir ]] && echo "libexecdir ?= ${libexecdir}"
167 [[ $localstatedir ]] && echo "localstatedir ?= ${localstatedir}"
168 [[ $sharedstatedir ]] && echo "sharedstatedir ?= ${sharedstatedir}"
169 [[ $infodir ]] && echo "infodir ?= ${infodir}"
170 [[ $systemdsystemunitdir ]] && echo "systemdsystemunitdir ?= ${systemdsystemunitdir}"
171 [[ $bashcompletiondir ]] && echo "bashcompletiondir ?= ${bashcompletiondir}"
172} >> Makefile.inc.$$
173
174mv Makefile.inc.$$ Makefile.inc