All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] Cross compile improvements
@ 2013-03-14  5:57 Aaron Carroll
  2013-03-14  5:57 ` [PATCH 1/4] Propagate target OS from configure to Makefile Aaron Carroll
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Aaron Carroll @ 2013-03-14  5:57 UTC (permalink / raw)
  To: fio

This set improves handling of cross compilation to the point where
Android can now build with no special-casing in the configure script.

Tested on Linux/x86 and Darwin/x86_64 native, and cross compile from
Linux/x86 to Android/arm and Linux/arm.  I dont have access to any
big endian machine, so a sanity check of the endianess changes would
be appreciated.

Aaron Carroll (4):
  Propagate target OS from configure to Makefile
  configure: compile-time word size detection
  configure: endianness check for cross compile
  Android: remove static Android configuration

 Makefile  |   21 +++++++--------
 configure |   79 +++++++++++++++++++++++++++++++++++++++++-------------------
 2 files changed, 64 insertions(+), 36 deletions(-)


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/4] Propagate target OS from configure to Makefile
  2013-03-14  5:57 [PATCH 0/4] Cross compile improvements Aaron Carroll
@ 2013-03-14  5:57 ` Aaron Carroll
  2013-03-14  5:57 ` [PATCH 2/4] configure: compile-time word size detection Aaron Carroll
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Aaron Carroll @ 2013-03-14  5:57 UTC (permalink / raw)
  To: fio

Propagate target OS from configure to Makefile (CONFIG_TARGET_OS) to avoid
duplicating the check in Makefile.  Also allow CROSS_COMPILE for the toolchain
prefix, which is common (e.g. Linux).

Signed-off-by: Aaron Carroll <aaronc@cse.unsw.edu.au>
---
 Makefile  |   21 ++++++++++-----------
 configure |   12 +++++++-----
 2 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/Makefile b/Makefile
index 7a17555..ea96a89 100644
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,6 @@ CFLAGS	= -std=gnu99 -Wwrite-strings -Wall $(OPTFLAGS)
 LIBS	= -lm $(EXTLIBS)
 PROGS	= fio
 SCRIPTS = fio_generate_plots
-UNAME  := $(shell uname)
 
 ifneq ($(wildcard config-host.mak),)
 all:
@@ -80,42 +79,42 @@ ifndef CONFIG_INET_ATON
   SOURCE += lib/inet_aton.c
 endif
 
-ifeq ($(UNAME), Linux)
+ifeq ($(CONFIG_TARGET_OS), Linux)
   SOURCE += diskutil.c fifo.c blktrace.c cgroup.c trim.c engines/sg.c \
 		engines/binject.c profiles/tiobench.c
   LIBS += -lpthread -ldl
   LDFLAGS += -rdynamic
 endif
-ifeq ($(UNAME), Android)
+ifeq ($(CONFIG_TARGET_OS), Android)
   SOURCE += diskutil.c fifo.c blktrace.c trim.c profiles/tiobench.c
   LIBS += -ldl
   LDFLAGS += -rdynamic
 endif
-ifeq ($(UNAME), SunOS)
+ifeq ($(CONFIG_TARGET_OS), SunOS)
   LIBS	 += -lpthread -ldl
   CPPFLAGS += -D__EXTENSIONS__
 endif
-ifeq ($(UNAME), FreeBSD)
+ifeq ($(CONFIG_TARGET_OS), FreeBSD)
   LIBS	 += -lpthread -lrt
   LDFLAGS += -rdynamic
 endif
-ifeq ($(UNAME), NetBSD)
+ifeq ($(CONFIG_TARGET_OS), NetBSD)
   LIBS	 += -lpthread -lrt
   LDFLAGS += -rdynamic
 endif
-ifeq ($(UNAME), AIX)
+ifeq ($(CONFIG_TARGET_OS), AIX)
   LIBS	 += -lpthread -ldl -lrt
   CPPFLAGS += -D_LARGE_FILES -D__ppc__
   LDFLAGS += -L/opt/freeware/lib -Wl,-blibpath:/opt/freeware/lib:/usr/lib:/lib -Wl,-bmaxdata:0x80000000
 endif
-ifeq ($(UNAME), HP-UX)
+ifeq ($(CONFIG_TARGET_OS), HP-UX)
   LIBS   += -lpthread -ldl -lrt
   CFLAGS += -D_LARGEFILE64_SOURCE -D_XOPEN_SOURCE_EXTENDED
 endif
-ifeq ($(UNAME), Darwin)
+ifeq ($(CONFIG_TARGET_OS), Darwin)
   LIBS	 += -lpthread -ldl
 endif
-ifneq (,$(findstring CYGWIN,$(UNAME)))
+ifneq (,$(findstring CYGWIN,$(CONFIG_TARGET_OS)))
   SOURCE := $(filter-out engines/mmap.c,$(SOURCE))
   SOURCE += os/windows/posix.c
   LIBS	 += -lpthread -lpsapi -lws2_32
@@ -169,7 +168,7 @@ INSTALL = install
 prefix = /usr/local
 bindir = $(prefix)/bin
 
-ifeq ($(UNAME), Darwin)
+ifeq ($(CONFIG_TARGET_OS), Darwin)
 mandir = /usr/share/man
 else
 mandir = $(prefix)/man
diff --git a/configure b/configure
index d364971..1fa9b63 100755
--- a/configure
+++ b/configure
@@ -126,6 +126,7 @@ output_sym() {
 targetos=""
 cpu=""
 
+cross_prefix=${cross_prefix-${CROSS_COMPILE}}
 cc="${CC-${cross_prefix}gcc}"
 
 show_help="no"
@@ -173,6 +174,12 @@ else
   targetos=`uname -s`
 fi
 
+echo "# Automatically generated by configure - do not modify" > $config_host_mak
+printf "# Configured with:" >> $config_host_mak
+printf " '%s'" "$0" "$@" >> $config_host_mak
+echo >> $config_host_mak
+echo "CONFIG_TARGET_OS=$targetos" >> $config_host_mak
+
 # Some host OSes need non-standard checks for which CPU to use.
 # Note that these checks are broken for cross-compilation: if you're
 # cross-compiling to one of these OSes then you'll need to specify
@@ -929,11 +936,6 @@ echo "RLIMIT_MEMLOCK                $rlimit_memlock"
 
 #############################################################################
 
-echo "# Automatically generated by configure - do not modify" > $config_host_mak
-printf "# Configured with:" >> $config_host_mak
-printf " '%s'" "$0" "$@" >> $config_host_mak
-echo >> $config_host_mak
-
 if test "$wordsize" = "64" ; then
   output_sym "CONFIG_64BIT"
 elif test "$wordsize" = "32" ; then
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/4] configure: compile-time word size detection
  2013-03-14  5:57 [PATCH 0/4] Cross compile improvements Aaron Carroll
  2013-03-14  5:57 ` [PATCH 1/4] Propagate target OS from configure to Makefile Aaron Carroll
@ 2013-03-14  5:57 ` Aaron Carroll
  2013-03-14  5:57 ` [PATCH 3/4] configure: endianness check for cross compile Aaron Carroll
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Aaron Carroll @ 2013-03-14  5:57 UTC (permalink / raw)
  To: fio

Signed-off-by: Aaron Carroll <aaronc@cse.unsw.edu.au>
---
 configure |   14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/configure b/configure
index 1fa9b63..84c6af2 100755
--- a/configure
+++ b/configure
@@ -348,16 +348,20 @@ echo
 # check for wordsize
 wordsize="0"
 cat > $TMPC <<EOF
-#include <stdio.h>
+#include <limits.h>
+#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
 int main(void)
 {
-  unsigned int wsize = sizeof(long) * 8;
-  printf("%d\n", wsize);
+  BUILD_BUG_ON(sizeof(long)*CHAR_BIT != WORDSIZE);
   return 0;
 }
 EOF
-if compile_prog "" "" "wordsize"; then
-  wordsize=`$TMPE`
+if compile_prog "-DWORDSIZE=32" "" "wordsize"; then
+  wordsize="32"
+elif compile_prog "-DWORDSIZE=64" "" "wordsize"; then
+  wordsize="64"
+else
+  fatal "Unknown wordsize"
 fi
 echo "Wordsize                      $wordsize"
 
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/4] configure: endianness check for cross compile
  2013-03-14  5:57 [PATCH 0/4] Cross compile improvements Aaron Carroll
  2013-03-14  5:57 ` [PATCH 1/4] Propagate target OS from configure to Makefile Aaron Carroll
  2013-03-14  5:57 ` [PATCH 2/4] configure: compile-time word size detection Aaron Carroll
@ 2013-03-14  5:57 ` Aaron Carroll
  2013-03-14  5:57 ` [PATCH 4/4] Android: remove static Android configuration Aaron Carroll
  2013-03-14 14:09 ` [PATCH 0/4] Cross compile improvements Jens Axboe
  4 siblings, 0 replies; 6+ messages in thread
From: Aaron Carroll @ 2013-03-14  5:57 UTC (permalink / raw)
  To: fio

 - Add a cross compile check: assume yes if we can't run a test binary
 - If cross compiling, revert to a compile-time endianess check. This tries
   a few possible ways to detect big endian, but otherwise assumes little. We
   rely on the run-time check to save us if the build-time check is wrong.

Signed-off-by: Aaron Carroll <aaronc@cse.unsw.edu.au>
---
 configure |   40 +++++++++++++++++++++++++++++++++++++---
 1 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/configure b/configure
index 84c6af2..965623d 100755
--- a/configure
+++ b/configure
@@ -323,9 +323,26 @@ fi
 cc="${CC-${cross_prefix}gcc}"
 
 ##########################################
+# check cross compile
+
+cross_compile="no"
+cat > $TMPC <<EOF
+int main(void)
+{
+  return 0;
+}
+EOF
+if compile_prog "" "" "cross"; then
+  $TMPE 2>/dev/null || cross_compile="yes"
+else
+  fatal "compile test failed"
+fi
+
+##########################################
 # check endianness
 bigendian="no"
-cat > $TMPC <<EOF
+if test "$cross_compile" = "no" ; then
+  cat > $TMPC <<EOF
 #include <inttypes.h>
 int main(void)
 {
@@ -333,8 +350,24 @@ int main(void)
   return (*((uint8_t*)(&i))) == 0x67;
 }
 EOF
-if compile_prog "" "" "endian"; then
-  $TMPE && bigendian="yes"
+  if compile_prog "" "" "endian"; then
+    $TMPE && bigendian="yes"
+  fi
+else
+  # If we're cross compiling, try our best to work it out and rely on the
+  # run-time check to fail if we get it wrong.
+  cat > $TMPC <<EOF
+#include <endian.h>
+int main(void)
+{
+#if __BYTE_ORDER != __BIG_ENDIAN
+# error "Unknown endianness"
+#endif
+}
+EOF
+  compile_prog "" "" "endian" && bigendian="yes"
+  check_define "__ARMEB__" && bigendian="yes"
+  check_define "__MIPSEB__" && bigendian="yes"
 fi
 
 
@@ -342,6 +375,7 @@ echo "Operating system              $targetos"
 echo "CPU                           $cpu"
 echo "Big endian                    $bigendian"
 echo "Compiler                      $cc"
+echo "Cross compile                 $cross_compile"
 echo
 
 ##########################################
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/4] Android: remove static Android configuration
  2013-03-14  5:57 [PATCH 0/4] Cross compile improvements Aaron Carroll
                   ` (2 preceding siblings ...)
  2013-03-14  5:57 ` [PATCH 3/4] configure: endianness check for cross compile Aaron Carroll
@ 2013-03-14  5:57 ` Aaron Carroll
  2013-03-14 14:09 ` [PATCH 0/4] Cross compile improvements Jens Axboe
  4 siblings, 0 replies; 6+ messages in thread
From: Aaron Carroll @ 2013-03-14  5:57 UTC (permalink / raw)
  To: fio

Android can now be configured dynamically, so remove the static config.
For this we need to modify the socklen_t check #includes which appear to
be wrong anyway.

Signed-off-by: Aaron Carroll <aaronc@cse.unsw.edu.au>
---
 configure |   13 +------------
 1 files changed, 1 insertions(+), 12 deletions(-)

diff --git a/configure b/configure
index 965623d..2859891 100755
--- a/configure
+++ b/configure
@@ -233,16 +233,6 @@ CYGWIN*)
   echo "EXTFLAGS=$CFLAGS -include config-host.h -D_GNU_SOURCE" >> $config_host_mak
   exit 0
   ;;
-Android)
-  output_sym "CONFIG_32BIT"
-  output_sym "CONFIG_LITTLE_ENDIAN"
-  output_sym "CONFIG_SOCKLEN_T"
-  output_sym "CONFIG_GETTIMEOFDAY"
-  output_sym "CONFIG_CLOCK_GETTIME"
-  output_sym "CONFIG_CLOCK_MONOTONIC"
-  echo "CC=$cc" >> $config_host_mak
-  echo "EXTFLAGS=$CFLAGS -include config-host.h -D_GNU_SOURCE" >> $config_host_mak
-  exit 0
 esac
 
 if test ! -z "$cpu" ; then
@@ -874,8 +864,7 @@ echo "inet_aton                     $inet_aton"
 # socklen_t probe
 socklen_t="no"
 cat > $TMPC << EOF
-#include <string.h>
-#include <netinet/in.h>
+#include <sys/socket.h>
 int main(int argc, char **argv)
 {
   socklen_t len = 0;
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/4] Cross compile improvements
  2013-03-14  5:57 [PATCH 0/4] Cross compile improvements Aaron Carroll
                   ` (3 preceding siblings ...)
  2013-03-14  5:57 ` [PATCH 4/4] Android: remove static Android configuration Aaron Carroll
@ 2013-03-14 14:09 ` Jens Axboe
  4 siblings, 0 replies; 6+ messages in thread
From: Jens Axboe @ 2013-03-14 14:09 UTC (permalink / raw)
  To: Aaron Carroll; +Cc: fio

On Thu, Mar 14 2013, Aaron Carroll wrote:
> This set improves handling of cross compilation to the point where
> Android can now build with no special-casing in the configure script.
> 
> Tested on Linux/x86 and Darwin/x86_64 native, and cross compile from
> Linux/x86 to Android/arm and Linux/arm.  I dont have access to any
> big endian machine, so a sanity check of the endianess changes would
> be appreciated.

Thanks Aaron, applied. I give it the most nasty of tests, seeing if
configure runs and fio builds on HPUX/ia64:

bash-4.2# ./configure 
Operating system              HP-UX
CPU                           ia64
Big endian                    yes
Compiler                      gcc
Cross compile                 no
[...]

bash-4.2# /usr/local/bin/gmake -j8
FIO_VERSION = fio-2.0.14
[...]
    LINK fio
bash-4.2#

So I think you can consider this a pass.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-03-14 14:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-14  5:57 [PATCH 0/4] Cross compile improvements Aaron Carroll
2013-03-14  5:57 ` [PATCH 1/4] Propagate target OS from configure to Makefile Aaron Carroll
2013-03-14  5:57 ` [PATCH 2/4] configure: compile-time word size detection Aaron Carroll
2013-03-14  5:57 ` [PATCH 3/4] configure: endianness check for cross compile Aaron Carroll
2013-03-14  5:57 ` [PATCH 4/4] Android: remove static Android configuration Aaron Carroll
2013-03-14 14:09 ` [PATCH 0/4] Cross compile improvements Jens Axboe

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.