Skip to content

Commit

Permalink
Zuo: support cross compilation via configure and CC_FOR_BUILD
Browse files Browse the repository at this point in the history
  • Loading branch information
mflatt committed Jul 25, 2022
1 parent 4e325e6 commit abb9afd
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@ CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@

CC_FOR_BUILD = @CC_FOR_BUILD@
CFLAGS_FOR_BUILD = @CFLAGS_FOR_BUILD@
LDFLAGS_FOR_BUILD = @LDFLAGS_FOR_BUILD@
LIBS_FOR_BUILD = @LIBS_FOR_BUILD@

EMBED_LIBS = @EMBED_LIBS@

.PHONY: zuos-to-run-and-install
zuos-to-run-and-install: zuo
./zuo . zuos-to-run-and-install

zuo: $(srcdir)/zuo.c
$(CC) $(CPPFLAGS) $(CFLAGS) -DZUO_LIB_PATH='"'"$(srcdir)/lib"'"' -o zuo $(srcdir)/zuo.c $(LDFLAGS) $(LIBS)
$(CC_FOR_BUILD) $(FLAGS_FOR_BUILD) -DZUO_LIB_PATH='"'"$(srcdir)/lib"'"' -o zuo $(srcdir)/zuo.c $(LDFLAGS_FOR_BUILD) $(LIBS_FOR_BUILD)

.PHONY: check
check: zuo
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ A boot image is machine-independent, whether in a stand-alone file or
embedded in `.c` source.


Cross Compiling
---------------

If you use `./configure --host=...` to cross compile, then you will
also need to add something like `CC_FOR_BUILD=cc` as a `./configure`
argument to specify the compiler for a `zuo` to use on the build
machine. If necessary, you can also specify `CFLAGS_FOR_BUILD`,
`LDFLAGS_FOR_BUILD`, and/or `LIBS_FOR_BUILD`.


Embedding Zuo in Another Application
------------------------------------

Expand Down
15 changes: 15 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,10 @@ enable_embed="zuo"
ac_subst_vars='LTLIBOBJS
LIBOBJS
EMBED_LIBS
LIBS_FOR_BUILD
LDFLAGS_FOR_BUILD
CFLAGS_FOR_BUILD
CC_FOR_BUILD
OBJEXT
EXEEXT
ac_ct_CC
Expand Down Expand Up @@ -2584,6 +2588,17 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $
ac_compiler_gnu=$ac_cv_c_compiler_gnu
if test "${CC_FOR_BUILD}" = ""; then
CC_FOR_BUILD='$(CC) -O2'
CFLAGS_FOR_BUILD='$(CPPFLAGS) $(CFLAGS)'
LDFLAGS_FOR_BUILD='$(LDFLAGS)'
LIBS_FOR_BUILD='$(LIBS)'
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: zuo libraries to embed: \"${EMBED_LIBS}\"" >&5
$as_echo "$as_me: zuo libraries to embed: \"${EMBED_LIBS}\"" >&6;}
Expand Down
11 changes: 11 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ AS_IF([test "x$enable_embed" = xno],
AC_PROG_MAKE_SET()
AC_PROG_CC

if test "${CC_FOR_BUILD}" = ""; then
CC_FOR_BUILD='$(CC) -O2'
CFLAGS_FOR_BUILD='$(CPPFLAGS) $(CFLAGS)'
LDFLAGS_FOR_BUILD='$(LDFLAGS)'
LIBS_FOR_BUILD='$(LIBS)'
fi
AC_SUBST(CC_FOR_BUILD)
AC_SUBST(CFLAGS_FOR_BUILD)
AC_SUBST(LDFLAGS_FOR_BUILD)
AC_SUBST(LIBS_FOR_BUILD)

AC_SUBST(EMBED_LIBS)
AC_MSG_NOTICE([zuo libraries to embed: "${EMBED_LIBS}"])

Expand Down

0 comments on commit abb9afd

Please sign in to comment.