History

configure: allow cc tests even if cross compiling, test i386/x86-64

Adds a tool `ppif` at configure which can test preprocessor conditions even when $cc is a cross compiler to any foreign platform. Currently used only to identify i386 or x86_64 (including when cross compiling) as a mini-demonstration. Hopefully will be used in the future to test more compiler features and/or replace uname-related tests with more accurate results.

Avi Halachmi (:avih) committed 7 years ago

Commit 84779b21 parent 3d789181 file · +37 −6Browse files

Unified · Split

configure+37−6
@@ -150,11 +150,46 @@ for opt do · 149 unmodified lines
150 esac150 esac
151done151done
152 152
153cc="${cross_prefix}${cc}"
154ar="${cross_prefix}${ar}"
155strip="${cross_prefix}${strip}"
156
157
158PPIF_TEMPLATE="
159int ppif(void) {
160#if %s
161 return 0;
162#else
163 PPIF_FALSE;
164#endif
165}
166"
167
168# Succeeds when preprocessor condition `#if $1` is true.
169# if $2 is not empty, prints to stderr `checking whether $2... <yes/no>`
170# Works also when $cc is a cross compiler to any foreign platform.
171# E.g. ppif "defined(__GNUC__) && (GCC_MAJOR >= 3)"
172# or ppif "defined(_WIN32)" "target is Windows"
173ppif() {
174 [ -z "${2-}" ] || printf "checking whether %s... " "$2" >&2
175 printf "$PPIF_TEMPLATE" "$1" > ppif.c \
176 && $cc -o ppif.o -c ppif.c 2>/dev/null
177 ppif_rv=$?
178 rm ppif.c ppif.o 2>/dev/null
179 [ -z "${2-}" ] || { [ 0 = $ppif_rv ] && echo yes || echo no; } >&2
180 return $ppif_rv
181}
182
183
153if test -z "$cpu" ; then184if test -z "$cpu" ; then
154 if test -n "$ARCH" ; then185 if test -n "$ARCH" ; then
155 cpu="$ARCH"186 cpu="$ARCH"
187 elif ppif "defined(__x86_64__)"; then
188 cpu="x86_64"
189 elif ppif "defined(__i386__)"; then
190 cpu="i386"
156 else191 else
157 cpu=`uname -m`192 cpu=`uname -m`
158 fi193 fi
159fi194fi
160 195
@@ -303,10 +338,6 @@ EOF · 142 unmodified lines
303exit 1338exit 1
304fi339fi
305 340
306cc="${cross_prefix}${cc}"
307ar="${cross_prefix}${ar}"
308strip="${cross_prefix}${strip}"
309
310if test -z "$cross_prefix" ; then341if test -z "$cross_prefix" ; then
311 CONFTEST=./conftest$EXESUF342 CONFTEST=./conftest$EXESUF
312 if ! $cc -o $CONFTEST $source_path/conftest.c 2>/dev/null ; then343 if ! $cc -o $CONFTEST $source_path/conftest.c 2>/dev/null ; then

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t