From b0bf7661d1dd8ee1248eb50f30400ea8b8b488d7 Mon Sep 17 00:00:00 2001 From: "Devon H. O'Dell" Date: Wed, 23 Feb 2011 15:01:36 -0500 Subject: [PATCH] build: enable building on 32-bit architectures Previously, we wouldn't build on 32-bit architectures, let alone configure. This was due in part to some issues where we essentially ignored setting CFLAGS properly. In addition, FreeBSD and possibly other BSDs only report i386 for any 32-bit x86 architecture. This has the side-effect that we have to do some additional guesswork to determine the actual CPU. Since we make use of cmpxchg8b, we require an i586 machine. FreeBSD's default 32-bit gcc -march setting is i486, so in effort to make things easier for FreeBSD users on 32-bit, set that to i586 by default. Linux makes this a little easier for us, since its uname actually returns useful information about the architecture (and assumedly the compilers for that architecture target the same arch at a minimum), so we will refuse to work on i386 / i486 on Linux as well. But really, I'd be slightly surprised at a ton of use on pentium/k5. --- Makefile.in | 1 + build/ck.build.in | 2 +- build/regressions.build.in | 2 +- configure | 63 +++++++++++++++++++++++++++++++------- 4 files changed, 55 insertions(+), 13 deletions(-) diff --git a/Makefile.in b/Makefile.in index 39e8066..930598a 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1,5 +1,6 @@ .PHONY: all clean distribution regressions install +CFLAGS=@CFLAGS@ PREFIX=@PREFIX@ LIBRARY=@LIBRARY@ HEADERS=@HEADERS@ diff --git a/build/ck.build.in b/build/ck.build.in index 65dfa63..d43edd5 100644 --- a/build/ck.build.in +++ b/build/ck.build.in @@ -1,5 +1,5 @@ CC=@CC@ MAKE=make -CFLAGS=-D_XOPEN_SOURCE=600 -D_BSD_SOURCE -I../include -std=gnu99 -pedantic -Wall -W -Wundef -Wendif-labels -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wdisabled-optimization -fstrict-aliasing -O2 -pipe -Wno-parentheses +CFLAGS=-D_XOPEN_SOURCE=600 -D_BSD_SOURCE -I../include -std=gnu99 -pedantic -Wall -W -Wundef -Wendif-labels -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wdisabled-optimization -fstrict-aliasing -O2 -pipe -Wno-parentheses @CFLAGS@ include ../build/ck.build.@PROFILE@ diff --git a/build/regressions.build.in b/build/regressions.build.in index 7cd0f99..9020251 100644 --- a/build/regressions.build.in +++ b/build/regressions.build.in @@ -1,5 +1,5 @@ CC=@CC@ MAKE=make -CFLAGS=-D_XOPEN_SOURCE=600 -D_BSD_SOURCE -I../../../include -std=gnu99 -pedantic -Wall -W -Wundef -Wendif-labels -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wdisabled-optimization -fstrict-aliasing -O2 -pipe -Wno-parentheses +CFLAGS=-D_XOPEN_SOURCE=600 -D_BSD_SOURCE -I../../../include -std=gnu99 -pedantic -Wall -W -Wundef -Wendif-labels -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wdisabled-optimization -fstrict-aliasing -O2 -pipe -Wno-parentheses @CFLAGS@ include ../../../build/ck.build.@PROFILE@ diff --git a/configure b/configure index 096e611..6ce06e4 100755 --- a/configure +++ b/configure @@ -1,6 +1,7 @@ #!/bin/sh # # Copyright © 2009, 2010 Samy Al Bahra. +# Copyright © 2011 Devon H. O'Dell # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -77,13 +78,18 @@ assert() generate() { - sed "s/@PROFILE@/$PROFILE/g;s#@CC@#$CC#g;s#@HEADERS@#$HEADERS#g;s#@LIBRARY@#$LIBRARY#g;s#@PREFIX@#$PREFIX#g" \ + sed -e "s#@PROFILE@#$PROFILE#g" \ + -e "s#@CC@#$CC#g" \ + -e "s#@CFLAGS@#$CFLAGS#g" \ + -e "s#@HEADERS@#$HEADERS#g" \ + -e "s#@LIBRARY@#$LIBRARY#g" \ + -e "s#@PREFIX@#$PREFIX#g" \ $1 > $2 } for option in $*; do - value=`echo "$option" | cut -f 2 -d=` + value=`echo "$option" | sed -e 's/^[^=]*=\(.*\)/\1/'` case "$option" in --help) @@ -106,7 +112,7 @@ for option in $*; do PREFIX=$value ;; --cflags=*) - CFLAGS=$CFLAGS $value + CFLAGS="$CFLAGS $value" ;; --headers=*) HEADERS=$value @@ -182,14 +188,49 @@ case $PLATFORM in ENVIRONMENT=64 ;; i386|i486|i586|i686|i586_i686|pentium*|athlon*|k5|k6|k6_2|k6_3) - if test "$SYSTEM" = "darwin"; then - ENVIRONMENT=64 - PLATFORM=x86_64 - else - PLATFORM=x86 - ENVIRONMENT=32 - assert "" "" "unsupported" - fi + case $SYSTEM in + darwin) + ENVIRONMENT=64 + PLATFORM=x86_64 + ;; + freebsd) + PLATFORM=x86 + ENVIRONMENT=32 + + # FreeBSD doesn't give us a nice way to determine the CPU + # class of the running system, reporting any 32-bit x86 + # architecture as i386. 486 is its minimum supported CPU + # class and cmpxchg8b was implemented first in i586. + dmesg | grep -q "486-class" + if test "$?" -eq 0; then + assert "" "" "Must have an i586 class or higher CPU" + fi + + # FreeBSD still generates code for 486-class CPUs as its + # default 32-bit target, but we need 586 at the least. + echo "$CFLAGS" | grep -q 'march=' + if test "$?" -ne 0; then + # Needed for cmpxchg8b + CFLAGS="$CFLAGS -march=i586" + fi + ;; + linux) + case $PLATFORM in + i386|i486) + assert "" "" "Must have an i586 class or higher CPU" + ;; + esac + + PLATFORM=x86 + ENVIRONMENT=32 + ;; + + *) + PLATFORM=x86 + ENVIRONMENT=32 + assert "$PLATFORM $ENVIRONMENT" "$PLATFORM $ENVIRONMENT" "unsupported" + ;; + esac ;; "amd64"|"x86_64") PLATFORM=x86_64