···1+commit fdda59736ddc048cf38a2c7103f4f5d9eeaf995e
2+Author: Ben Gamari <ben@smart-cactus.org>
3+Date: Tue Oct 17 10:51:34 2017 -0400
4+5+ Try implementing cross-compilation
6+7+diff --git a/bc/Makefile.am b/bc/Makefile.am
8+index d9d412e..fdef633 100644
9+--- a/bc/Makefile.am
10++++ b/bc/Makefile.am
11+@@ -17,6 +17,7 @@ MAINTAINERCLEANFILES = Makefile.in bc.c bc.h scan.c \
12+13+ AM_CPPFLAGS = -I$(srcdir) -I$(srcdir)/../h
14+ LIBBC = ../lib/libbc.a
15++LIBBC_HOST = ../lib/libbc_host.a
16+ LIBL = @LEXLIB@
17+ LDADD = $(LIBBC) $(LIBL) @READLINELIB@
18+19+@@ -29,12 +30,20 @@ $(PROGRAMS): libmath.h $(LIBBC)
20+ scan.o: bc.h
21+ global.o: libmath.h
22++
23++main_host.c : main.c
24++ cp $< $@
25+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)
28++
29++%.o_host : CC:=$(CC_FOR_BUILD)
30++
31++%.o_host : %.c
32++ $(COMPILE) -c $(CFLAGS) $(INCLUDES) -o $@ $<
33+34+-libmath.h: libmath.b $(fbcOBJ) $(LIBBC)
35++libmath.h: libmath.b $(fbcOBJ) $(LIBBC_HOST)
36+ echo '{0}' > libmath.h
37+- $(MAKE) global.o
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
46+--- a/configure.ac
47++++ b/configure.ac
48+@@ -20,6 +20,7 @@ m4_define([dc_version], 1.4.1)
49+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)
55+56+@@ -35,6 +36,7 @@ AC_DEFINE([DC_COPYRIGHT],
57+ [Define the dc copyright line.])
58+59+ AC_PROG_CC
60++AX_CC_FOR_BUILD
61+ AC_USE_SYSTEM_EXTENSIONS
62+63+ AM_PROG_LEX
64+diff --git a/lib/Makefile.am b/lib/Makefile.am
65+index ec4bf59..c670f5b 100644
66+--- a/lib/Makefile.am
67++++ b/lib/Makefile.am
68+@@ -1,5 +1,5 @@
69+ ## Process this file with automake to produce Makefile.in
70+-noinst_LIBRARIES = libbc.a
71++noinst_LIBRARIES = libbc.a libbc_host.a
72+73+ AM_CPPFLAGS = -I. -I.. -I$(srcdir)/../h
74+75+@@ -24,3 +24,11 @@ testmul: testmul.o number.o
76+77+ specialnumber: newnumber.o
78+ cp newnumber.o number.o
79++
80++%.o_host : CC:=$(CC_FOR_BUILD)
81++%.o_host : %.c
82++ $(COMPILE) -c $(CFLAGS) $(INCLUDES) -o $@ $<
83++
84++libbc_host.a : $(addsuffix _host,$(libbc_a_OBJECTS))
85++ ar cru $@ $+
86++ ranlib $@
87+diff --git a/m4/cc_for_build.m4 b/m4/cc_for_build.m4
88+new file mode 100644
89+index 0000000..c62ffad
90+--- /dev/null
91++++ b/m4/cc_for_build.m4
92+@@ -0,0 +1,77 @@
93++# ===========================================================================
94++# https://www.gnu.org/software/autoconf-archive/ax_cc_for_build.html
95++# ===========================================================================
96++#
97++# SYNOPSIS
98++#
99++# AX_CC_FOR_BUILD
100++#
101++# DESCRIPTION
102++#
103++# Find a build-time compiler. Sets CC_FOR_BUILD and EXEEXT_FOR_BUILD.
104++#
105++# LICENSE
106++#
107++# Copyright (c) 2010 Reuben Thomas <rrt@sc3d.org>
108++# Copyright (c) 1999 Richard Henderson <rth@redhat.com>
109++#
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.
114++#
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.
119++#
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/>.
122++#
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.
130++#
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.
135++
136++#serial 3
137++
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)'
144++ else
145++ CC_FOR_BUILD=gcc
146++ fi
147++fi
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)'
152++else
153++ AC_CACHE_CHECK([for build system executable suffix], bfd_cv_build_exeext,
154++ [rm -f conftest*
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
159++ case $file in
160++ *.c | *.o | *.obj | *.ilk | *.pdb) ;;
161++ *) bfd_cv_build_exeext=`echo $file | sed -e s/conftest//` ;;
162++ esac
163++ done
164++ rm -f 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}
168++fi
169++AC_SUBST(EXEEXT_FOR_BUILD)])dnl
···1+{stdenv, autoreconfHook, buildPackages, fetchurl, flex, readline, ed, texinfo}:
23stdenv.mkDerivation rec {
4 name = "bc-1.07.1";
···910 configureFlags = [ "--with-readline" ];
1112+ # As of 1.07 cross-compilation is quite complicated as the build system wants
13+ # to build a code generator, bc/fbc, on the build machine.
14+ patches = [ ./cross-bc.patch ];
15+ depsBuildBuild = [ buildPackages.stdenv.cc ];
16+ nativeBuildInputs = [
17+ # Tools
18+ autoreconfHook ed flex texinfo
19+ # Libraries for build
20+ buildPackages.readline buildPackages.ncurses
21+ ];
22+ buildInputs = [ readline ];
2324+ doCheck = true; # not cross
25+26+ # Hack to make sure we never to the relaxation `$PATH` and hooks support for
27+ # compatability. This will be replaced with something clearer in a future
28+ # masss-rebuild.
29+ crossConfig = true;
3031 meta = {
32 description = "GNU software calculator";