nexmon – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 #!/bin/sh
2 #
3 # aircrack-ng build config generation script by Len White <lwhite@nrw.ca>
4 #
5 # The purpose of this is to generate a file to be included by common.mak that defines
6 # compile time configuration, granting us more flexibility in tests and speeding build process
7 # by not running the tests every time we compile a single file.
8 #
9 # NOTES: * common.cfg is automatically regenerated on make clean
10 # * common.cfg is NOT required to build aircrack, but is required for autoconfiguration of the new crypto cores.
11 #
12  
13 CC=$1
14 IS_X86=0
15 IS_ARM=0
16 IS_CROSS=0
17 SIMDSIZE=0
18 SIMDFLAG=""
19  
20 if [ ! $1 ]; then
21 echo "Usage: $0 <compiler> [cfgpath]"
22 exit 127
23 fi
24  
25 if [ ! $2 ]; then
26 CURDIR=$(pwd)
27 else
28 CURDIR=$2
29 fi
30  
31 CFGFILE="${CURDIR}/common.cfg"
32  
33 clean_exit () {
34 if [ -n "$tmpdir" ]; then
35 if [ -d "${tmpdir}" ]; then
36 rm -rf "${tmpdir}"
37 fi
38 fi
39 }
40  
41 if [ "$(uname -s)" = 'OpenBSD' ]; then
42 OPENBSD=1
43 trap clean_exit EXIT
44 else
45 trap clean_exit SIGINT SIGKILL SIGQUIT SIGSEGV SIGPIPE SIGALRM SIGTERM EXIT
46 fi
47  
48 # $1 flag $2 variable
49 test_compile_flag () {
50 FLAGTEST=$(echo | $CC -fsyntax-only ${1} -xc -Werror - 2>/dev/null && echo Y)
51  
52 if [ "$FLAGTEST" = "Y" ] && [ $2 ]; then
53 echo "${2}=${FLAGTEST}" >> $CFGFILE
54 fi
55 }
56  
57 test_header_file () {
58 if [ -f "$1" ]; then
59 echo "${2}=Y" >> $CFGFILE
60 fi
61 }
62  
63 cpuid_test () {
64 tmpdir="$(mktemp -d -t acng.XXXX)"
65  
66 cat >${tmpdir}/cpuidtest.c <<EOF
67 #include <cpuid.h>
68 #include <stdio.h>
69 int main() {
70 unsigned eax = 0, ebx = 0, ecx = 0, edx = 0;
71 unsigned int max_level = __get_cpuid_max(0, NULL);
72  
73 if (max_level >= 7) {
74 __cpuid_count(7, 0, eax, ebx, ecx, edx);
75  
76 if (ebx & (1 << 5)) // AVX2
77 return 16;
78 }
79  
80 __cpuid(1, eax, ebx, ecx, edx);
81  
82 if (ecx & (1 << 28)) // AVX1
83 return 8;
84  
85 if (edx & (1 << 26)) // SSE2
86 return 4;
87  
88 return 1;
89 }
90 EOF
91  
92 $($CC -o ${tmpdir}/cpuidtest ${tmpdir}/cpuidtest.c 2>/dev/null)
93  
94 if [ -x "${tmpdir}/cpuidtest" ]; then
95 ${tmpdir}/cpuidtest
96  
97 SIMDSIZE=$?
98 fi
99  
100 if [ $SIMDSIZE -gt 0 ]; then
101 case $SIMDSIZE in
102 16)
103 SIMDTYPE="AVX2"
104 ;;
105 8)
106 SIMDTYPE="AVX"
107 ;;
108 4)
109 SIMDTYPE="SSE2"
110 ;;
111 1)
112 SIMDTYPE="MMX"
113 ;;
114 esac
115 fi
116 }
117  
118 case "$CC" in
119 mips-* | arm-*)
120 IS_CROSS=1
121 IS_X86=0
122 ;;
123 *);;
124 esac
125  
126 UARCH=$(uname -m)
127  
128 case "$UARCH" in
129 x86_64 | amd64 | i*86*)
130 IS_X86=1
131 ;;
132 *arm*)
133 IS_ARM=1
134 ;;
135 *mips*)
136 IS_CROSS=1
137 ;;
138 *)
139 ;;
140 esac
141  
142 if [ $IS_X86 = 1 ]; then
143 cpuid_test
144  
145 if [ $SIMDSIZE -gt 0 ]; then
146 if [ $SIMDSIZE = 16 ]; then
147 test_compile_flag -mavx2
148  
149 if [ "$FLAGTEST" = "Y" ]; then
150 echo "AVX2FLAG=Y" > $CFGFILE
151 fi
152  
153 echo "SIMDCORE=true" >> $CFGFILE
154 elif [ $SIMDSIZE = 8 ]; then
155 test_compile_flag -mavx
156  
157 if [ "$FLAGTEST" = "Y" ]; then
158 echo "AVX1FLAG=Y" > $CFGFILE
159 fi
160  
161 echo "SIMDCORE=true" >> $CFGFILE
162 elif [ $SIMDSIZE = 4 ]; then
163 test_compile_flag -msse2
164  
165 if [ "$FLAGTEST" = "Y" ]; then
166 echo "SSEFLAG=Y" > $CFGFILE
167 fi
168 fi
169 fi
170  
171 if [ ! $OPENBSD ]; then
172 test_compile_flag -masm=intel INTEL_ASM
173 fi
174 elif [ $IS_ARM = 1 ]; then
175 >$CFGFILE
176  
177 if [ -f "/proc/cpuinfo" ]; then
178 NEON_FLAG=$(grep -c neon /proc/cpuinfo)
179  
180 if [ $NEON_FLAG -eq 1 ]; then
181 test_compile_flag -mfpu=neon HAS_NEON
182  
183 if [ "$FLAGTEST" = "Y" ]; then
184 echo "SIMDCORE=true" >>$CFGFILE
185 else
186 IS_CROSS=1
187 fi
188 else
189 IS_CROSS=1
190 fi
191 else
192 IS_CROSS=1
193 fi
194 fi
195  
196 test_compile_flag -pthread PTHREAD
197  
198 if [ $IS_X86 -eq 0 ]; then
199 # If we're on non-x86 platform, we need to check for auxv for cpuid since it's broken on some debian vers
200 test_header_file sys/auxv.h HAS_AUXV
201 fi
202  
203 if [ $IS_CROSS -eq 1 ]; then
204 echo "NEWSSE=false" >>$CFGFILE
205 fi
206  
207 # If we fall thru all the tests and still haven't created a config, create an empty one.
208 if [ ! -f "$CFGFILE" ]; then
209 echo >$CFGFILE
210 fi