Skip to content

Commit

Permalink
configure: make buildsystem-set CPPFLAGS non-overridable
Browse files Browse the repository at this point in the history
we temporarily store all buildsystem-set conditionals into
OUR_CPPFLAGS and write it into config.mak as an addition to eventually
user-supplied CPPFLAGS. this should prevent crucial things we set from
being overwritten by a user that has CPPFLAGS exported.

fixes rofl0r#142
  • Loading branch information
rofl0r committed Oct 16, 2016
1 parent 0f6b226 commit c883cd4
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions configure
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/sh

prefix=/usr/local
OUR_CPPFLAGS=

# Get a temporary filename
i=0
Expand Down Expand Up @@ -33,18 +34,18 @@ check_compile() {
printf "checking %s ... " "$1"
printf "$3" > "$tmpc"
local res=0
$CC $CPPFLAGS $2 $CFLAGS -c "$tmpc" -o /dev/null >/dev/null 2>&1 \
$CC $OUR_CPPFLAGS $CPPFLAGS $2 $CFLAGS -c "$tmpc" -o /dev/null >/dev/null 2>&1 \
|| res=1
test x$res = x0 && \
{ printf "yes\n" ; test x"$2" = x || CPPFLAGS="$CPPFLAGS $2" ; } \
{ printf "yes\n" ; test x"$2" = x || OUR_CPPFLAGS="$OUR_CPPFLAGS $2" ; } \
|| printf "no\n"
return $res
}

check_define() {
printf "checking whether \$CC defines %s ... " "$1"
local res=1
$CC $CPPFLAGS $CFLAGS -dM -E - </dev/null | grep "$1" >/dev/null && res=0
$CC $OUR_CPPFLAGS $CPPFLAGS $CFLAGS -dM -E - </dev/null | grep "$1" >/dev/null && res=0
test x$res = x0 && printf "yes\n" || printf "no\n"
return $res
}
Expand All @@ -53,7 +54,7 @@ check_compile_run() {
printf "checking %s ... " "$1"
printf "$2" > "$tmpc"
local res=0
$CC $CPPFLAGS $CFLAGS "$tmpc" -o "$tmpc".out >/dev/null 2>&1 \
$CC $OUR_CPPFLAGS $CPPFLAGS $CFLAGS "$tmpc" -o "$tmpc".out >/dev/null 2>&1 \
|| res=1
test x$res = x0 && { "$tmpc".out || res=1 ; }
rm -f "$tmpc".out
Expand Down Expand Up @@ -143,7 +144,7 @@ check_compile 'whether netinet/in.h defines __u6_addr.__u6_addr16' \
check_define __OpenBSD__ && \
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;}' && \
CPPFLAGS="$CPPFLAGS -DBROKEN_FCLOSE"
OUR_CPPFLAGS="$OUR_CPPFLAGS -DBROKEN_FCLOSE"

echo CC?=$CC>config.mak
[ -z "$CPPFLAGS" ] || echo CPPFLAGS?=$CPPFLAGS>>config.mak
Expand All @@ -155,7 +156,8 @@ echo bindir=$bindir>>config.mak
echo libdir=$libdir>>config.mak
echo includedir=$includedir>>config.mak
echo sysconfdir=$sysconfdir>>config.mak
[ "$ignore_cve" = "no" ] && echo CPPFLAGS+= -DSUPER_SECURE>>config.mak
[ "$ignore_cve" = "no" ] && echo "CPPFLAGS+= -DSUPER_SECURE">>config.mak
[ -z "$OUR_CPPFLAGS" ] || echo "CPPFLAGS+= $OUR_CPPFLAGS" >>config.mak
make_cmd=make
if ismac ; then
echo NO_AS_NEEDED=>>config.mak
Expand Down

0 comments on commit c883cd4

Please sign in to comment.