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.
Unified · Split
| @@ -150,11 +150,46 @@ for opt do · 149 unmodified lines | |||
| 150 | esac | 150 | esac |
| 151 | done | 151 | done |
| 152 | 152 | ||
| 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 | |||
| 153 | if test -z "$cpu" ; then | 184 | if test -z "$cpu" ; then |
| 154 | if test -n "$ARCH" ; then | 185 | 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 | else | 191 | else |
| 157 | cpu=`uname -m` | 192 | cpu=`uname -m` |
| 158 | fi | 193 | fi |
| 159 | fi | 194 | fi |
| 160 | 195 | ||
| @@ -303,10 +338,6 @@ EOF · 142 unmodified lines | |||
| 303 | exit 1 | 338 | exit 1 |
| 304 | fi | 339 | fi |
| 305 | 340 | ||
| 306 | cc="${cross_prefix}${cc}" | ||
| 307 | ar="${cross_prefix}${ar}" | ||
| 308 | strip="${cross_prefix}${strip}" | ||
| 309 | |||
| 310 | if test -z "$cross_prefix" ; then | 341 | if test -z "$cross_prefix" ; then |
| 311 | CONFTEST=./conftest$EXESUF | 342 | CONFTEST=./conftest$EXESUF |
| 312 | if ! $cc -o $CONFTEST $source_path/conftest.c 2>/dev/null ; then | 343 | if ! $cc -o $CONFTEST $source_path/conftest.c 2>/dev/null ; then |