1 commit fdda59736ddc048cf38a2c7103f4f5d9eeaf995e
2 Author: Ben Gamari <ben@smart-cactus.org>
3 Date: Tue Oct 17 10:51:34 2017 -0400
5 Try implementing cross-compilation
7 diff --git a/bc/Makefile.am b/bc/Makefile.am
8 index d9d412e..fdef633 100644
11 @@ -17,6 +17,7 @@ MAINTAINERCLEANFILES = Makefile.in bc.c bc.h scan.c \
13 AM_CPPFLAGS = -I$(srcdir) -I$(srcdir)/../h
14 LIBBC = ../lib/libbc.a
15 +LIBBC_HOST = ../lib/libbc_host.a
17 LDADD = $(LIBBC) $(LIBL) @READLINELIB@
19 @@ -29,12 +30,20 @@ $(PROGRAMS): libmath.h $(LIBBC)
26 -fbcOBJ = main.o bc.o scan.o execute.o load.o storage.o util.o warranty.o
27 +fbcOBJ = $(addsuffix _host,main.o bc.o scan.o execute.o load.o storage.o util.o warranty.o)
29 +%.o_host : CC:=$(CC_FOR_BUILD)
32 + $(COMPILE) -c $(CFLAGS) $(INCLUDES) -o $@ $<
34 -libmath.h: libmath.b $(fbcOBJ) $(LIBBC)
35 +libmath.h: libmath.b $(fbcOBJ) $(LIBBC_HOST)
36 echo '{0}' > libmath.h
38 - $(LINK) -o fbc $(fbcOBJ) global.o $(LIBBC) $(LIBL) $(READLINELIB) $(LIBS)
39 + $(MAKE) global.o_host
40 + $(CC_FOR_BUILD) -o fbc $(fbcOBJ) global.o_host $(LIBBC_HOST) $(LIBL) ${READLINELIB} $(LIBS)
41 ./fbc -c $(srcdir)/libmath.b </dev/null >libmath.h
42 $(srcdir)/fix-libmath_h
43 rm -f ./fbc ./global.o
44 diff --git a/configure.ac b/configure.ac
45 index fc74573..5cabb73 100644
48 @@ -20,6 +20,7 @@ m4_define([dc_version], 1.4.1)
50 AC_INIT([bc],[bc_version])
51 AC_CONFIG_SRCDIR(doc/bc.1)
52 +AC_CONFIG_MACRO_DIR([m4])
53 AM_INIT_AUTOMAKE([dist-bzip2])
54 AC_CONFIG_HEADERS(config.h)
56 @@ -35,6 +36,7 @@ AC_DEFINE([DC_COPYRIGHT],
57 [Define the dc copyright line.])
61 AC_USE_SYSTEM_EXTENSIONS
64 diff --git a/lib/Makefile.am b/lib/Makefile.am
65 index ec4bf59..c670f5b 100644
69 ## Process this file with automake to produce Makefile.in
70 -noinst_LIBRARIES = libbc.a
71 +noinst_LIBRARIES = libbc.a libbc_host.a
73 AM_CPPFLAGS = -I. -I.. -I$(srcdir)/../h
75 @@ -24,3 +24,11 @@ testmul: testmul.o number.o
77 specialnumber: newnumber.o
78 cp newnumber.o number.o
80 +%.o_host : CC:=$(CC_FOR_BUILD)
82 + $(COMPILE) -c $(CFLAGS) $(INCLUDES) -o $@ $<
84 +libbc_host.a : $(addsuffix _host,$(libbc_a_OBJECTS))
87 diff --git a/m4/cc_for_build.m4 b/m4/cc_for_build.m4
89 index 0000000..c62ffad
91 +++ b/m4/cc_for_build.m4
93 +# ===========================================================================
94 +# https://www.gnu.org/software/autoconf-archive/ax_cc_for_build.html
95 +# ===========================================================================
103 +# Find a build-time compiler. Sets CC_FOR_BUILD and EXEEXT_FOR_BUILD.
107 +# Copyright (c) 2010 Reuben Thomas <rrt@sc3d.org>
108 +# Copyright (c) 1999 Richard Henderson <rth@redhat.com>
110 +# This program is free software: you can redistribute it and/or modify it
111 +# under the terms of the GNU General Public License as published by the
112 +# Free Software Foundation, either version 3 of the License, or (at your
113 +# option) any later version.
115 +# This program is distributed in the hope that it will be useful, but
116 +# WITHOUT ANY WARRANTY; without even the implied warranty of
117 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
118 +# Public License for more details.
120 +# You should have received a copy of the GNU General Public License along
121 +# with this program. If not, see <https://www.gnu.org/licenses/>.
123 +# As a special exception, the respective Autoconf Macro's copyright owner
124 +# gives unlimited permission to copy, distribute and modify the configure
125 +# scripts that are the output of Autoconf when processing the Macro. You
126 +# need not follow the terms of the GNU General Public License when using
127 +# or distributing such scripts, even though portions of the text of the
128 +# Macro appear in them. The GNU General Public License (GPL) does govern
129 +# all other use of the material that constitutes the Autoconf Macro.
131 +# This special exception to the GPL applies to versions of the Autoconf
132 +# Macro released by the Autoconf Archive. When you make and distribute a
133 +# modified version of the Autoconf Macro, you may extend this special
134 +# exception to the GPL to apply to your modified version as well.
138 +dnl Get a default for CC_FOR_BUILD to put into Makefile.
139 +AC_DEFUN([AX_CC_FOR_BUILD],
140 +[# Put a plausible default for CC_FOR_BUILD in Makefile.
141 +if test -z "$CC_FOR_BUILD"; then
142 + if test "x$cross_compiling" = "xno"; then
143 + CC_FOR_BUILD='$(CC)'
148 +AC_SUBST(CC_FOR_BUILD)
149 +# Also set EXEEXT_FOR_BUILD.
150 +if test "x$cross_compiling" = "xno"; then
151 + EXEEXT_FOR_BUILD='$(EXEEXT)'
153 + AC_CACHE_CHECK([for build system executable suffix], bfd_cv_build_exeext,
155 + echo 'int main () { return 0; }' > conftest.c
156 + bfd_cv_build_exeext=
157 + ${CC_FOR_BUILD} -o conftest conftest.c 1>&5 2>&5
158 + for file in conftest.*; do
160 + *.c | *.o | *.obj | *.ilk | *.pdb) ;;
161 + *) bfd_cv_build_exeext=`echo $file | sed -e s/conftest//` ;;
165 + test x"${bfd_cv_build_exeext}" = x && bfd_cv_build_exeext=no])
166 + EXEEXT_FOR_BUILD=""
167 + test x"${bfd_cv_build_exeext}" != xno && EXEEXT_FOR_BUILD=${bfd_cv_build_exeext}
169 +AC_SUBST(EXEEXT_FOR_BUILD)])dnl