plan to cleanup the fd generation code
[trinity.git] / configure.sh
blob067908ac85f00f86bdc3d3ad8e4e99ef3a8e3958
1 #!/bin/bash
3 DEVEL=1
5 if [ -t 1 ]; then
6 RED="\e[1;31m"
7 GREEN="\e[1;32m"
8 COL_RESET="\e[0;m"
9 fi
11 MISSING_DEFS=0
13 [ -z "$CC" ] && CC=gcc
15 # expand tilde
16 CC="$(eval echo ${CROSS_COMPILE}${CC})"
18 CFLAGS=""
19 if [ "${SYSROOT}xx" != "xx" ]; then
20 CFLAGS="$(eval echo --sysroot=${SYSROOT} )"
23 echo "#pragma once" > config.h
24 echo "/* This file is auto-generated by configure.sh */" >> config.h
26 TMP=$(mktemp)
28 check_header()
30 echo -n "[*] Checking header $1 ... "
32 rm -f "$TMP" || exit 1
33 echo "#include <$1>" >"$TMP.c"
35 ${CC} ${CFLAGS} "$TMP.c" -E &>"$TMP.log"
36 if [ $? -eq 0 ]; then
37 echo $GREEN "[YES]" $COL_RESET
38 echo "#define $2 1" >> config.h
39 else
40 echo $RED "[NO]" $COL_RESET
41 MISSING_DEFS=1
45 #############################################################################################
47 echo -n "#define " >> config.h
48 grep VERSION= Makefile | sed 's/=/ /' >> config.h
50 #############################################################################################
52 echo "[*] Checking system headers."
54 #############################################################################################
55 # is /usr/include/linux/if_pppox.h new enough to feature pppol2tpin6/pppol2tpv3in6
57 echo -n "[*] Checking if pppox can use pppol2tpin6.. "
58 rm -f "$TMP" || exit 1
60 cat >"$TMP.c" << EOF
61 #include <stdio.h>
62 #include <netinet/in.h>
63 #include <linux/if.h>
64 #include <linux/if_pppox.h>
66 void main()
68 struct sockaddr_pppol2tpin6 *pppox;
69 printf("%d\n", pppox->sa_family);
71 EOF
73 ${CC} ${CFLAGS} "$TMP.c" -o "$TMP" &>"$TMP.log"
74 if [ ! -x "$TMP" ]; then
75 echo $RED "[NO]" $COL_RESET
76 MISSING_DEFS=1
77 else
78 echo $GREEN "[YES]" $COL_RESET
79 echo "#define USE_PPPOL2TPIN6 1" >> config.h
82 #############################################################################################
83 # is /usr/include/linux/if_pppox.h new enough to feature pppol2tpv3
85 echo -n "[*] Checking if pppox can use pppol2tv3.. "
86 rm -f "$TMP" || exit 1
88 cat >"$TMP.c" << EOF
89 #include <stdio.h>
90 #include <netinet/in.h>
91 #include <linux/if.h>
92 #include <linux/if_pppox.h>
94 void main()
96 struct sockaddr_pppol2tpv3 *pppox;
97 printf("%d\n", pppox->sa_family);
99 EOF
101 ${CC} ${CFLAGS} "$TMP.c" -o "$TMP" &>"$TMP.log"
102 if [ ! -x "$TMP" ]; then
103 echo $RED "[NO]" $COL_RESET
104 MISSING_DEFS=1
105 else
106 echo $GREEN "[YES]" $COL_RESET
107 echo "#define USE_PPPOL2TPV3 1" >> config.h
110 #############################################################################################
111 # is /usr/include/linux/if_pppox.h new enough to feature pptp
113 echo -n "[*] Checking if pppox can use pptp.. "
114 rm -f "$TMP" || exit 1
116 cat >"$TMP.c" << EOF
117 #include <stdio.h>
118 #include <netinet/in.h>
119 #include <linux/if.h>
120 #include <linux/if_pppox.h>
122 void main()
124 struct sockaddr_pppox *pppox;
125 printf("%d\n", pppox->sa_addr.pptp.call_id);
129 ${CC} ${CFLAGS} "$TMP.c" -o "$TMP" &>"$TMP.log"
130 if [ ! -x "$TMP" ]; then
131 echo $RED "[NO]" $COL_RESET
132 MISSING_DEFS=1
133 else
134 echo $GREEN "[YES]" $COL_RESET
135 echo "#define USE_PPPOX_PPTP 1" >> config.h
138 #############################################################################################
139 # is /usr/include/linux/llc.h new enough to feature LLC_OPT_PKTINFO
141 echo -n "[*] Checking if llc can use LLC_OPT_PKTINFO.. "
142 rm -f "$TMP" || exit 1
144 cat >"$TMP.c" << EOF
145 #include <stdio.h>
146 #include <net/if.h>
147 #include <linux/llc.h>
149 void main()
151 printf("%d\n", LLC_OPT_PKTINFO);
155 ${CC} ${CFLAGS} "$TMP.c" -o "$TMP" &>"$TMP.log"
156 if [ ! -x "$TMP" ]; then
157 echo $RED "[NO]" $COL_RESET
158 MISSING_DEFS=1
159 else
160 echo $GREEN "[YES]" $COL_RESET
161 echo "#define USE_LLC_OPT_PKTINFO 1" >> config.h
164 #############################################################################################
165 # Do glibc headers provides struct termios2
167 echo -n "[*] Checking if glibc headers provide termios2.. "
168 rm -f "$TMP" || exit 1
170 cat >"$TMP.c" << EOF
171 #include <sys/ioctl.h>
172 #include <sys/vt.h>
173 #include <termios.h>
175 int main()
177 struct termios2 test;
181 ${CC} ${CFLAGS} "$TMP.c" -o "$TMP" &>"$TMP.log"
182 if [ ! -x "$TMP" ]; then
183 echo $RED "[NO]" $COL_RESET
184 MISSING_DEFS=1
185 else
186 echo $GREEN "[YES]" $COL_RESET
187 echo "#define HAVE_TERMIOS2 1" >> config.h
190 #############################################################################################
192 check_header linux/caif/caif_socket.h USE_CAIF
193 check_header linux/if_alg.h USE_IF_ALG
194 check_header linux/rds.h USE_RDS
195 check_header linux/vfio.h USE_VFIO
196 check_header linux/btrfs.h USE_BTRFS
197 check_header drm/drm.h USE_DRM
198 check_header drm/exynos_drm.h USE_DRM_EXYNOS
199 check_header sound/compress_offload.h USE_SNDDRV_COMPRESS_OFFLOAD
200 check_header linux/kvm.h USE_KVM
201 check_header linux/seccomp.h USE_SECCOMP
202 check_header linux/vhost.h USE_VHOST
204 rm -f "$TMP" "$TMP.log" "$TMP.c"
206 #############################################################################################
207 if [ "$DEVEL" == "1" ]; then
208 VER=$(git describe --always)
209 echo "#define GITVERSION \""$VER\" >> config.h
212 #############################################################################################
214 if [ "$MISSING_DEFS" == "1" ]; then
215 echo "[-] Some header definitions were missing. This is not fatal."
216 echo " It usually means you're building on an older distribution which doesn't"
217 echo " have header files describing newer kernel features."
218 echo " Trinity will still compile and run, it just won't use those new features."
219 echo " Go ahead, and run 'make'"
222 exit 0