Skip to contentSkip to conversation

Support cross-compiling on Mac OS X

PATCH In review Dirk Hörner 4 participants 12 messages Jun 4, 2012 – Jun 5, 2012 Kbuild

lore
Share & tools
lore
#0 lore raw

cover Support cross-compiling on Mac OS X

Hi all,

this patch series adds support to cross-compile barebox on Mac OS X. Please review as I am quite unsure as to whether I have found the best solutions to some of the problems, especially patch two and three.

The first patch was cherry-picked from Linux.

I tested this series on Max OS X 10.6.8 using the yagarto ARM toolchain[1].

Ciao,
Dirk

[1]: http://www.yagarto.de/

Dirk Hörner (5):
make: use wc -c instead of stat -c%s to get file sizes
make: check for greadlink first, fall back to readlink hostcc tools: include "compiler.h", fix included headers scripts/compiler.h: fixup endianess defines on OS X scripts/genenv: always pass template to mktemp

Sam Ravnborg (1):
kbuild: Use Elfnn_Half as replacement for Elfnn_Section

 Makefile              |    2 +-
 common/Makefile       |    6 ++++--
 include/envfs.h       |    2 ++
 include/image.h       |    2 +-
 scripts/Makefile.lib  |    2 +-
 scripts/bareboxenv.c  |    2 ++
 scripts/compiler.h    |    3 +++
 scripts/genenv        |    2 +-
 scripts/mod/modpost.h |    4 ++--
 9 files changed, 17 insertions(+), 8 deletions(-)
Signature · 7 lines
1.7.10.3


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

PATCH 1/6 kbuild: Use Elfnn_Half as replacement for Elfnn_Section

From: Sam Ravnborg <[email protected]>

The Elfnn_Section is not available on all platforms, noteworthy are cygwin.
Use the safe replacement _Half.

---
 scripts/mod/modpost.h |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
scripts/mod/modpost.h +2 -2
index 0c23259..497d614 100644
@@ -17,7 +17,7 @@
 #define Elf_Shdr    Elf32_Shdr
 #define Elf_Sym     Elf32_Sym
 #define Elf_Addr    Elf32_Addr
-#define Elf_Section Elf32_Section
+#define Elf_Section Elf32_Half
 #define ELF_ST_BIND ELF32_ST_BIND
 #define ELF_ST_TYPE ELF32_ST_TYPE
 
@@ -31,7 +31,7 @@
 #define Elf_Shdr    Elf64_Shdr
 #define Elf_Sym     Elf64_Sym
 #define Elf_Addr    Elf64_Addr
-#define Elf_Section Elf64_Section
+#define Elf_Section Elf64_Half
 #define ELF_ST_BIND ELF64_ST_BIND
 #define ELF_ST_TYPE ELF64_ST_TYPE
 
Signature · 7 lines
1.7.10.3


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

PATCH 2/6 make: use wc -c instead of stat -c%s to get file sizes

In reply to Dirk Hörner

On OS X, stat does not know about %s. Solaris does not have stat. The drawback to this wc -c solution is that wc reads all the bytes, but we are only dealing with small files here, so that not be much of a problem.

---
 Makefile             |    2 +-
 common/Makefile      |    2 +-
 scripts/Makefile.lib |    2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
Makefile +1 -1
index bcaae0a..3ac8788 100644
@@ -536,7 +536,7 @@ quiet_cmd_barebox_version = GEN     .version
 # Check size of a file
 quiet_cmd_check_file_size = CHKSIZE $@
       cmd_check_file_size = set -e;					\
-	size=`stat -c%s $@`;						\
+	size=`wc -c < $@`;						\
 	max_size=`printf "%d" $2`;					\
 	if [ $$size -gt $$max_size ] ;					\
 	then								\
common/Makefile +1 -1
index a58aef9..9c14d7b 100644
@@ -77,7 +77,7 @@ barebox_default_env.lzo: barebox_default_env
 
 include/generated/barebox_default_env.h: barebox_default_env$(barebox_default_env_comp)
 	$(Q)cat $< | $(objtree)/scripts/bin2c default_environment > $@
-	$(Q)echo "const int default_environment_uncompress_size=`stat -c%s barebox_default_env`;" >> $@
+	$(Q)echo "const int default_environment_uncompress_size=`wc -c < barebox_default_env`;" >> $@
 
 CLEAN_FILES += include/generated/barebox_default_env.h barebox_default_env
 CLEAN_FILES += barebox_default_env.gz barebox_default_env.bz2
scripts/Makefile.lib +1 -1
index b842c48..9b02b1b 100644
@@ -171,7 +171,7 @@ cmd_gzip = (cat $(filter-out FORCE,$^) | gzip -n -f -9 > $@) || \
 size_append = printf $(shell						\
 dec_size=0;								\
 for F in $1; do								\
-	fsize=$$(stat -c "%s" $$F);					\
+	fsize=$$(wc -c < $$F);					        \
 	dec_size=$$(expr $$dec_size + $$fsize);				\
 done;									\
 printf "%08x\n" $$dec_size |						\
Signature · 7 lines
1.7.10.3


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

Re: [PATCH 2/6] make: use wc -c instead of stat -c%s to get file sizes

HI,

I don't like this to continue to duplicate code

Best Regards,
J.

Quoted 58 lines · Dirk Hörner

On OS X, stat does not know about %s. Solaris does not have stat. The drawback to this wc -c solution is that wc reads all the bytes, but we are only dealing with small files here, so that not be much of a problem.

---
 Makefile             |    2 +-
 common/Makefile      |    2 +-
 scripts/Makefile.lib |    2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
Makefile +1 -1
index bcaae0a..3ac8788 100644
@@ -536,7 +536,7 @@ quiet_cmd_barebox_version = GEN     .version
 # Check size of a file
 quiet_cmd_check_file_size = CHKSIZE $@
       cmd_check_file_size = set -e;					\
-	size=`stat -c%s $@`;						\
+	size=`wc -c < $@`;						\
 	max_size=`printf "%d" $2`;					\
 	if [ $$size -gt $$max_size ] ;					\
 	then								\
common/Makefile +1 -1
index a58aef9..9c14d7b 100644
@@ -77,7 +77,7 @@ barebox_default_env.lzo: barebox_default_env
 
 include/generated/barebox_default_env.h: barebox_default_env$(barebox_default_env_comp)
 	$(Q)cat $< | $(objtree)/scripts/bin2c default_environment > $@
-	$(Q)echo "const int default_environment_uncompress_size=`stat -c%s barebox_default_env`;" >> $@
+	$(Q)echo "const int default_environment_uncompress_size=`wc -c < barebox_default_env`;" >> $@
 
 CLEAN_FILES += include/generated/barebox_default_env.h barebox_default_env
 CLEAN_FILES += barebox_default_env.gz barebox_default_env.bz2
scripts/Makefile.lib +1 -1
index b842c48..9b02b1b 100644
@@ -171,7 +171,7 @@ cmd_gzip = (cat $(filter-out FORCE,$^) | gzip -n -f -9 > $@) || \
 size_append = printf $(shell						\
 dec_size=0;								\
 for F in $1; do								\
-	fsize=$$(stat -c "%s" $$F);					\
+	fsize=$$(wc -c < $$F);					        \
 	dec_size=$$(expr $$dec_size + $$fsize);				\
 done;									\
 printf "%08x\n" $$dec_size |						\
Signature · 7 lines
1.7.10.3


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#4 lore raw

Re: [PATCH 2/6] make: use wc -c instead of stat -c%s to get file sizes

Quoted 4 lines · Jean-Christophe PLAGNIOL-VILLARD

HI,

I don't like this to continue to duplicate code

What do you mean here?

Sascha

Quoted 67 lines

Best Regards,
J.

Quoted 58 lines · Dirk Hörner

On OS X, stat does not know about %s. Solaris does not have stat. The drawback to this wc -c solution is that wc reads all the bytes, but we are only dealing with small files here, so that not be much of a problem.

---
 Makefile             |    2 +-
 common/Makefile      |    2 +-
 scripts/Makefile.lib |    2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
Makefile +1 -1
index bcaae0a..3ac8788 100644
@@ -536,7 +536,7 @@ quiet_cmd_barebox_version = GEN     .version
 # Check size of a file
 quiet_cmd_check_file_size = CHKSIZE $@
       cmd_check_file_size = set -e;					\
-	size=`stat -c%s $@`;						\
+	size=`wc -c < $@`;						\
 	max_size=`printf "%d" $2`;					\
 	if [ $$size -gt $$max_size ] ;					\
 	then								\
common/Makefile +1 -1
index a58aef9..9c14d7b 100644
@@ -77,7 +77,7 @@ barebox_default_env.lzo: barebox_default_env
 
 include/generated/barebox_default_env.h: barebox_default_env$(barebox_default_env_comp)
 	$(Q)cat $< | $(objtree)/scripts/bin2c default_environment > $@
-	$(Q)echo "const int default_environment_uncompress_size=`stat -c%s barebox_default_env`;" >> $@
+	$(Q)echo "const int default_environment_uncompress_size=`wc -c < barebox_default_env`;" >> $@
 
 CLEAN_FILES += include/generated/barebox_default_env.h barebox_default_env
 CLEAN_FILES += barebox_default_env.gz barebox_default_env.bz2
scripts/Makefile.lib +1 -1
index b842c48..9b02b1b 100644
@@ -171,7 +171,7 @@ cmd_gzip = (cat $(filter-out FORCE,$^) | gzip -n -f -9 > $@) || \
 size_append = printf $(shell						\
 dec_size=0;								\
 for F in $1; do								\
-	fsize=$$(stat -c "%s" $$F);					\
+	fsize=$$(wc -c < $$F);					        \
 	dec_size=$$(expr $$dec_size + $$fsize);				\
 done;									\
 printf "%08x\n" $$dec_size |						\
Signature · 7 lines
1.7.10.3


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#5 lore raw

Re: [PATCH 2/6] make: use wc -c instead of stat -c%s to get file sizes

In reply to Jean-Christophe PLAGNIOL-VILLARD

Hi Jean-Christophe,

Quoted 4 lines · Jean-Christophe PLAGNIOL-VILLARD

HI,

       I don't like this to continue to duplicate code

I agree. Would you rather like a function in common/Kbuild.include and then $(call) it in appropriate places?

In any case, I guess the code unification should be done in a separate commit, either before or after my patch.

Ciao,
Dirk

Quoted 66 lines

Best Regards,
J.

Quoted 62 lines · Dirk Hörner

On OS X, stat does not know about %s. Solaris does not have stat. The drawback to this wc -c solution is that wc reads all the bytes, but we are
only dealing with small files here, so that not be much of a problem.

---
 Makefile             |    2 +-
 common/Makefile      |    2 +-
 scripts/Makefile.lib |    2 +-

 3 files changed, 3 insertions(+), 3 deletions(-)
Makefile +0 -0
index bcaae0a..3ac8788 100644
@@ -536,7 +536,7 @@ quiet_cmd_barebox_version = GEN     .version
  # Check size of a file

 quiet_cmd_check_file_size = CHKSIZE $@
       cmd_check_file_size = set -e;                                  \
-     size=stat -c%s $@;                                            \
+     size=wc -c < $@;                                              \
      max_size=printf "%d" $2;                                      \
      if [ $$size -gt $$max_size ] ;                                  \
      then                                                            \

common/Makefile +0 -0
index a58aef9..9c14d7b 100644
@@ -77,7 +77,7 @@ barebox_default_env.lzo: barebox_default_env
 

 include/generated/barebox_default_env.h:
barebox_default_env$(barebox_default_env_comp)
      $(Q)cat $< | $(objtree)/scripts/bin2c default_environment > $@
-     $(Q)echo "const int default_environment_uncompress_size=stat -c%s barebox_default_env;" >> $@
+     $(Q)echo "const int default_environment_uncompress_size=wc -c < barebox_default_env;" >> $@

 CLEAN_FILES += include/generated/barebox_default_env.h barebox_default_env
 CLEAN_FILES += barebox_default_env.gz barebox_default_env.bz2

scripts/Makefile.lib +0 -1
index b842c48..9b02b1b 100644
@@ -171,7 +171,7 @@ cmd_gzip = (cat $(filter-out FORCE,$^) | gzip -n -f
-9 > $@) || \
  size_append = printf $(shell                                         \
  dec_size=0;                                                          \

 for F in $1; do
     \
-     fsize=$$(stat -c "%s" $$F);                                     \
+     fsize=$$(wc -c < $$F);                                          \
      dec_size=$$(expr $$dec_size + $$fsize);                         \
 done;
     \
 printf "%08x\n" $$dec_size |                                         \
--
1.7.10.3

Quoted 4 lines
Quoted 4 lines

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#6 lore raw

PATCH 3/6 make: check for greadlink first, fall back to readlink

In reply to Dirk Hörner

OS X' readlink does not have an -f option.

---
 common/Makefile |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
common/Makefile +3 -1
index 9c14d7b..48cf715 100644
@@ -48,7 +48,9 @@ ifneq ($(CONFIG_DEFAULT_ENVIRONMENT_PATH),"")
 DEFAULT_ENVIRONMENT_PATH += $(CONFIG_DEFAULT_ENVIRONMENT_PATH)
 endif
 
-ENV_FILES := $(shell cd $(srctree); for i in $(DEFAULT_ENVIRONMENT_PATH); do find $${i} -type f -exec readlink -f '{}' \;; done)
+READLINK := $(shell command -v greadlink || echo readlink)
+
+ENV_FILES := $(shell cd $(srctree); for i in $(DEFAULT_ENVIRONMENT_PATH); do find $${i} -type f -exec $(READLINK) -f '{}' \;; done)
 
 endif # ifdef CONFIG_DEFAULT_ENVIRONMENT
 
Signature · 7 lines
1.7.10.3


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#7 lore raw

Re: [PATCH 3/6] make: check for greadlink first, fall back to readlink

Quoted 12 lines · Dirk Hörner

OS X' readlink does not have an -f option.

---
 common/Makefile |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
common/Makefile +0 -0
index 9c14d7b..48cf715 100644

common/Makefile ifneq ($(CONFIG_DEFAULT_ENVIRONMENT_PATH),"") · line 53

Quoted 7 lines
common/Makefile +3 -1
@@ -48,7 +48,9 @@ ifneq ($(CONFIG_DEFAULT_ENVIRONMENT_PATH),"")
 DEFAULT_ENVIRONMENT_PATH += $(CONFIG_DEFAULT_ENVIRONMENT_PATH)
 endif
 
-ENV_FILES := $(shell cd $(srctree); for i in $(DEFAULT_ENVIRONMENT_PATH); do find $${i} -type f -exec readlink -f '{}' \;; done)
+READLINK := $(shell command -v greadlink || echo readlink)
+
+ENV_FILES := $(shell cd $(srctree); for i in $(DEFAULT_ENVIRONMENT_PATH); do find $${i} -type f -exec $(READLINK) -f '{}' \;; done)

This is already broken. '-type f' only matches regular files. And ENV_FILES is only used for make dependencies. And make follows links. I think what we really need here is 'find $${i} ! -type d -print'

Michael

Quoted 11 lines
common/Makefile +0 -0
 endif # ifdef CONFIG_DEFAULT_ENVIRONMENT
 
Signature · 7 lines
1.7.10.3


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#8 lore raw

PATCH 4/6 hostcc tools: include "compiler.h", fix included headers

In reply to Dirk Hörner

When barebox headers get included from HOSTCC tools they should not include other architecture specific headers as barebox might get cross-compiled. Instead, the tool itself should include "compiler.h".

---
 include/envfs.h      |    2 ++
 include/image.h      |    2 +-
 scripts/bareboxenv.c |    2 ++
 3 files changed, 5 insertions(+), 1 deletion(-)
include/envfs.h +2 -0
index b5849d9..67b8902 100644
@@ -1,7 +1,9 @@
 #ifndef _ENVFS_H
 #define _ENVFS_H
 
+#ifdef __BAREBOX__
 #include <asm/byteorder.h>
+#endif
 
 #define ENVFS_MAGIC		    0x798fba79	/* some random number */
 #define ENVFS_INODE_MAGIC	0x67a8c78d
include/image.h +1 -1
index 35ff01b..027b5f2 100644
@@ -31,8 +31,8 @@
 #ifndef __IMAGE_H__
 #define __IMAGE_H__
 
-#include <linux/types.h>
 #ifdef __BAREBOX__
+#include <linux/types.h>
 #include <asm/byteorder.h>
 #include <stdio.h>
 #include <string.h>
scripts/bareboxenv.c +2 -0
index b0d5818..866e345 100644
@@ -34,6 +34,8 @@
 #include <getopt.h>
 #include <libgen.h>
 
+#include "compiler.h"
+
 #define debug(...)
 
 void *xmalloc(size_t size)
Signature · 7 lines
1.7.10.3


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#9 lore raw

PATCH 5/6 scripts/compiler.h: fixup endianess defines on OS X

In reply to Dirk Hörner
---
 scripts/compiler.h |    3 +++
 1 file changed, 3 insertions(+)
scripts/compiler.h +3 -0
index f4b1432..53f84b6 100644
@@ -45,6 +45,9 @@
 # include <byteswap.h>
 #elif defined(__MACH__)
 # include <machine/endian.h>
+# define __BYTE_ORDER    BYTE_ORDER
+# define __LITTLE_ENDIAN LITTLE_ENDIAN
+# define __BIG_ENDIAN    BIG_ENDIAN
 typedef unsigned long ulong;
 typedef unsigned int  uint;
 #endif
Signature · 7 lines
1.7.10.3


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#10 lore raw

PATCH 6/6 scripts/genenv: always pass template to mktemp

In reply to Dirk Hörner

Passing a template to mktemp is mandatory on OS X.

---
 scripts/genenv |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/genenv +1 -1
index 7b279c8..c84af0c 100755
@@ -8,7 +8,7 @@ objtree=$2
 cd $1 || exit 1
 shift 2
 
-tempdir=$(mktemp -d)
+tempdir=$(mktemp -d tmp.XXXXXX)
 
 for i in $*; do
 	cp -r $i/* $tempdir
Signature · 7 lines
1.7.10.3


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#11 lore raw
In reply to Dirk Hörner

Hi Dirk,

Quoted 10 lines · Dirk Hörner

Hi all,

this patch series adds support to cross-compile barebox on Mac OS X. Please review as I am quite unsure as to whether I have found the best solutions to some of the problems, especially patch two and three.

The first patch was cherry-picked from Linux.

I tested this series on Max OS X 10.6.8 using the yagarto ARM toolchain[1].

Applied the patches nobody has commented on.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox