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
150150 esac
151151 done
152152
153+cc="${cross_prefix}${cc}"
154+ar="${cross_prefix}${ar}"
155+strip="${cross_prefix}${strip}"
156+
157+
158+PPIF_TEMPLATE="
159+int 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"
173+ppif() {
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+
153184 if test -z "$cpu" ; then
154185 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"
156191 else
157− cpu=`uname -m`
192+ cpu=`uname -m`
158193 fi
159194 fi
160195
@@ -303,10 +338,6 @@ EOF · 142 unmodified lines
303338 exit 1
304339 fi
305340
306−cc="${cross_prefix}${cc}"
307−ar="${cross_prefix}${ar}"
308−strip="${cross_prefix}${strip}"
309−
310341 if test -z "$cross_prefix" ; then
311342 CONFTEST=./conftest$EXESUF
312343 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