Support cross-compiling on Mac OS X
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
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
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
@@ -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
PATCH 2/6 make: use wc -c instead of stat -c%s to get file sizes
In reply to Dirk HörnerOn 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
@@ -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
@@ -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
@@ -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
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.
Signed-off-by Dirk Hörner <[email protected]>--- Makefile | 2 +- common/Makefile | 2 +- scripts/Makefile.lib | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)Makefile +1
-1@@ -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@@ -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.bz2scripts/Makefile.lib +1
-1@@ -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
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.
Signed-off-by Dirk Hörner <[email protected]>--- Makefile | 2 +- common/Makefile | 2 +- scripts/Makefile.lib | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)Makefile +1
-1@@ -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@@ -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.bz2scripts/Makefile.lib +1
-1@@ -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
Re: [PATCH 2/6] make: use wc -c instead of stat -c%s to get file sizes
In reply to Jean-Christophe PLAGNIOL-VILLARDHi 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.Signed-off-by Dirk Hörner <[email protected]>---
Makefile | 2 +-
common/Makefile | 2 +-
scripts/Makefile.lib | 2 +-3 files changed, 3 insertions(+), 3 deletions(-)Makefile +0
-0@@ -536,7 +536,7 @@ quiet_cmd_barebox_version = GEN .version # Check size of a filequiet_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@@ -77,7 +77,7 @@ barebox_default_env.lzo: barebox_default_envinclude/generated/barebox_default_env.h:
barebox_default_env$(barebox_default_env_comp)
$(Q)cat $< | $(objtree)/scripts/bin2cdefault_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.hbarebox_default_env
CLEAN_FILES += barebox_default_env.gz barebox_default_env.bz2scripts/Makefile.lib +0
-1@@ -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
PATCH 3/6 make: check for greadlink first, fall back to readlink
In reply to Dirk HörnerOS X' readlink does not have an -f option.
--- common/Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
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) endif # ifdef CONFIG_DEFAULT_ENVIRONMENT
Signature · 7 lines
1.7.10.3 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
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.
Signed-off-by Dirk Hörner <[email protected]>--- common/Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)common/Makefile +0
-0
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
-0endif # ifdef CONFIG_DEFAULT_ENVIRONMENTSignature · 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
PATCH 4/6 hostcc tools: include "compiler.h", fix included headers
In reply to Dirk HörnerWhen 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
@@ -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
@@ -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
@@ -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
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
@@ -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_ENDIANtypedef 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
PATCH 6/6 scripts/genenv: always pass template to mktemp
In reply to Dirk HörnerPassing a template to mktemp is mandatory on OS X.
--- scripts/genenv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/genenv +1 -1
@@ -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
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