]>
Commit | Line | Data |
---|---|---|
103281f3 | 1 | #!/bin/bash |
103281f3 CW |
2 | |
3 | # We don't support srcdir != builddir | |
4 | echo \#buildapi-variable-no-builddir >/dev/null | |
5 | ||
6 | prefix=/usr | |
7 | ||
2692a422 CW |
8 | enable_documentation=yes |
9 | ||
62f27ee6 | 10 | CC="${CC:-cc}" |
699414f5 MAP |
11 | PKG_CONFIG="${PKG_CONFIG:-pkg-config}" |
12 | ||
103281f3 CW |
13 | # Little helper function for reading args from the commandline. |
14 | # it automatically handles -a b and -a=b variants, and returns 1 if | |
15 | # we need to shift $3. | |
16 | read_arg() { | |
17 | # $1 = arg name | |
18 | # $2 = arg value | |
19 | # $3 = arg parameter | |
20 | local rematch='^[^=]*=(.*)$' | |
21 | if [[ $2 =~ $rematch ]]; then | |
f4053eb0 | 22 | read -r "$1" <<< "${BASH_REMATCH[1]}" |
103281f3 | 23 | else |
f4053eb0 | 24 | read -r "$1" <<< "$3" |
103281f3 CW |
25 | # There is no way to shift our callers args, so |
26 | # return 1 to indicate they should do it instead. | |
27 | return 1 | |
28 | fi | |
1d4b3375 | 29 | return 0 |
103281f3 CW |
30 | } |
31 | ||
32 | while (($# > 0)); do | |
33 | case "${1%%=*}" in | |
34 | --prefix) read_arg prefix "$@" || shift;; | |
35 | --libdir) read_arg libdir "$@" || shift;; | |
36 | --datadir) read_arg datadir "$@" || shift;; | |
37 | --sysconfdir) read_arg sysconfdir "$@" || shift;; | |
38 | --sbindir) read_arg sbindir "$@" || shift;; | |
39 | --mandir) read_arg mandir "$@" || shift;; | |
2692a422 | 40 | --disable-documentation) enable_documentation=no;; |
1d4b3375 HH |
41 | --program-prefix) read_arg programprefix "$@" || shift;; |
42 | --exec-prefix) read_arg execprefix "$@" || shift;; | |
43 | --bindir) read_arg bindir "$@" || shift;; | |
44 | --includedir) read_arg includedir "$@" || shift;; | |
45 | --libexecdir) read_arg libexecdir "$@" || shift;; | |
46 | --localstatedir) read_arg localstatedir "$@" || shift;; | |
47 | --sharedstatedir) read_arg sharedstatedir "$@" || shift;; | |
48 | --infodir) read_arg infodir "$@" || shift;; | |
49 | --systemdsystemunitdir) read_arg systemdsystemunitdir "$@" || shift;; | |
50 | --bashcompletiondir) read_arg bashcompletiondir "$@" || shift;; | |
103281f3 CW |
51 | *) echo "Ignoring unknown option '$1'";; |
52 | esac | |
53 | shift | |
54 | done | |
55 | ||
7bb80835 YW |
56 | if ! ${PKG_CONFIG} --exists --print-errors " libkmod >= 23 "; then |
57 | echo "dracut needs pkg-config and libkmod >= 23." >&2 | |
607fec3e HH |
58 | exit 1 |
59 | fi | |
60 | ||
62f27ee6 DTCD |
61 | cat <<EOF >conftest.c |
62 | #include <fts.h> | |
63 | int main() { | |
64 | return 0; | |
65 | } | |
66 | EOF | |
67 | ||
f4053eb0 | 68 | # shellcheck disable=SC2086 |
62f27ee6 DTCD |
69 | ${CC} $CFLAGS $LDFLAGS conftest.c >/dev/null 2>&1 |
70 | ret=$? | |
71 | rm -f conftest.c a.out | |
72 | ||
73 | # musl doesn't have fts.h included | |
74 | if test $ret -ne 0; then | |
75 | echo "dracut needs fts development files." >&2 | |
76 | exit 1 | |
77 | fi | |
78 | ||
79 | cat <<EOF >conftest.c | |
80 | #include <fts.h> | |
81 | int main(void) { | |
82 | fts_open(0, 0, 0); | |
83 | return 0; | |
84 | } | |
85 | EOF | |
86 | ||
87 | found=no | |
88 | for lib in "-lc" "-lfts"; do | |
f4053eb0 HH |
89 | # shellcheck disable=SC2086 |
90 | ${CC} $CFLAGS $LDFLAGS conftest.c -Wl,$lib >/dev/null 2>&1 | |
62f27ee6 DTCD |
91 | ret=$? |
92 | if test $ret -eq 0; then | |
93 | FTS_LIBS="$lib" | |
94 | found=yes | |
95 | break; | |
96 | fi | |
97 | done | |
98 | rm -f conftest.c a.out | |
99 | ||
100 | if test $found = no; then | |
101 | echo "dracut couldn't find usable fts library" >&2 | |
102 | exit 1 | |
103 | fi | |
104 | ||
1d4b3375 | 105 | cat > Makefile.inc.$$ <<EOF |
103281f3 CW |
106 | prefix ?= ${prefix} |
107 | libdir ?= ${libdir:-${prefix}/lib} | |
108 | datadir ?= ${datadir:-${prefix}/share} | |
109 | sysconfdir ?= ${sysconfdir:-${prefix}/etc} | |
110 | sbindir ?= ${sbindir:-${prefix}/sbin} | |
111 | mandir ?= ${mandir:-${prefix}/share/man} | |
1d4b3375 HH |
112 | enable_documentation ?= ${enable_documentation:-yes} |
113 | bindir ?= ${bindir:-${prefix}/bin} | |
2a0da60e HH |
114 | KMOD_CFLAGS ?= $(${PKG_CONFIG} --cflags " libkmod >= 23 ") |
115 | KMOD_LIBS ?= $(${PKG_CONFIG} --libs " libkmod >= 23 ") | |
62f27ee6 | 116 | FTS_LIBS ?= ${FTS_LIBS} |
103281f3 | 117 | EOF |
1d4b3375 HH |
118 | |
119 | { | |
120 | [[ $programprefix ]] && echo "programprefix ?= ${programprefix}" | |
121 | [[ $execprefix ]] && echo "execprefix ?= ${execprefix}" | |
122 | [[ $includedir ]] && echo "includedir ?= ${includedir}" | |
123 | [[ $libexecdir ]] && echo "libexecdir ?= ${libexecdir}" | |
124 | [[ $localstatedir ]] && echo "localstatedir ?= ${localstatedir}" | |
125 | [[ $sharedstatedir ]] && echo "sharedstatedir ?= ${sharedstatedir}" | |
126 | [[ $infodir ]] && echo "infodir ?= ${infodir}" | |
127 | [[ $systemdsystemunitdir ]] && echo "systemdsystemunitdir ?= ${systemdsystemunitdir}" | |
128 | [[ $bashcompletiondir ]] && echo "bashcompletiondir ?= ${bashcompletiondir}" | |
129 | } >> Makefile.inc.$$ | |
130 | ||
131 | mv Makefile.inc.$$ Makefile.inc |