Skip to content

Commit

Permalink
configure: remove bogus uname platform checks
Browse files Browse the repository at this point in the history
calling uname in a configure script is entirely bogus, as it will return
wrong results in crosscompilation scenarios. the only sensible way to
detect the target platform's peculiarities is to test the preprocessor
for macros defining the target.
  • Loading branch information
rofl0r committed Jan 9, 2018
1 parent 2f3d33d commit b299193
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,6 @@ done
set +C
trap 'rm "$tmpc"' EXIT INT QUIT TERM HUP

ismac() {
uname -s | grep Darwin >/dev/null
}

isx86_64() {
uname -m | grep -i X86_64 >/dev/null
}

isbsd() {
uname -s | grep BSD >/dev/null
}

isopenbsd() {
uname -s | grep OpenBSD >/dev/null
}

check_compile() {
printf "checking %s ... " "$1"
printf "$3" > "$tmpc"
Expand Down Expand Up @@ -73,7 +57,7 @@ usage() {
echo "--ignore-cve default: no"
echo " if set to yes ignores CVE-2015-3887 and makes it possible"
echo " to preload from current dir (insecure)"
ismac && isx86_64 && echo "--fat-binary : build for both i386 and x86_64 architectures on 64-bit Macs"
echo "--fat-binary : build for both i386 and x86_64 architectures on 64-bit Macs"
echo "--help : show this text"
exit 1
}
Expand Down Expand Up @@ -133,10 +117,33 @@ if [ -z "$CC" ] ; then
CC=cc
fi

check_define __OpenBSD__ && \

bsd_detected=false
isbsd() {
$bsd_detected
}
mac_detected=false
ismac() {
$mac_detected
}
mac_64=false
ismac64() {
$mac_64
}


check_define __APPLE__ && {
mac_detected=true
check_define __x86_64__ && mac_64=true
}
check_define __FreeBSD__ && bsd_detected=true
check_define __OpenBSD__ && {
bsd_detected=true
echo "CFLAGS+=-DIS_OPENBSD">>config.mak
check_compile_run 'whether OpenBSDs fclose() (illegally) calls close()' \
'#include <stdio.h>\n#include<stdlib.h>\nint close(int x){exit(0);}int main(){fclose(stdin);return 1;}' && \
OUR_CPPFLAGS="$OUR_CPPFLAGS -DBROKEN_FCLOSE"
}

echo "CC=$CC">config.mak
[ -z "$CPPFLAGS" ] || echo "CPPFLAGS=$CPPFLAGS">>config.mak
Expand All @@ -155,7 +162,7 @@ if ismac ; then
echo NO_AS_NEEDED=>>config.mak
echo LDSO_SUFFIX=dylib>>config.mak
echo MAC_CFLAGS+=-DIS_MAC=1>>config.mak
if isx86_64 && [ "$fat_binary" = 1 ] ; then
if ismac64 && [ "$fat_binary" = 1 ] ; then
echo "Configuring a fat binary for i386 and x86_64"
echo MAC_CFLAGS+=-arch i386 -arch x86_64>>config.mak
echo LDFLAGS+=-arch i386 -arch x86_64>>config.mak
Expand All @@ -164,7 +171,6 @@ if ismac ; then
elif isbsd ; then
echo LIBDL=>>config.mak
echo "CFLAGS+=-DIS_BSD">>config.mak
isopenbsd && echo "CFLAGS+=-DIS_OPENBSD">>config.mak
make_cmd=gmake
fi

Expand Down

0 comments on commit b299193

Please sign in to comment.