···11+commit fdda59736ddc048cf38a2c7103f4f5d9eeaf995e
22+Author: Ben Gamari <ben@smart-cactus.org>
33+Date: Tue Oct 17 10:51:34 2017 -0400
44+55+ Try implementing cross-compilation
66+77+diff --git a/bc/Makefile.am b/bc/Makefile.am
88+index d9d412e..fdef633 100644
99+--- a/bc/Makefile.am
1010++++ b/bc/Makefile.am
1111+@@ -17,6 +17,7 @@ MAINTAINERCLEANFILES = Makefile.in bc.c bc.h scan.c \
1212+1313+ AM_CPPFLAGS = -I$(srcdir) -I$(srcdir)/../h
1414+ LIBBC = ../lib/libbc.a
1515++LIBBC_HOST = ../lib/libbc_host.a
1616+ LIBL = @LEXLIB@
1717+ LDADD = $(LIBBC) $(LIBL) @READLINELIB@
1818+1919+@@ -29,12 +30,20 @@ $(PROGRAMS): libmath.h $(LIBBC)
2020+ scan.o: bc.h
2121+ global.o: libmath.h
2222++
2323++main_host.c : main.c
2424++ cp $< $@
2525+2626+-fbcOBJ = main.o bc.o scan.o execute.o load.o storage.o util.o warranty.o
2727++fbcOBJ = $(addsuffix _host,main.o bc.o scan.o execute.o load.o storage.o util.o warranty.o)
2828++
2929++%.o_host : CC:=$(CC_FOR_BUILD)
3030++
3131++%.o_host : %.c
3232++ $(COMPILE) -c $(CFLAGS) $(INCLUDES) -o $@ $<
3333+3434+-libmath.h: libmath.b $(fbcOBJ) $(LIBBC)
3535++libmath.h: libmath.b $(fbcOBJ) $(LIBBC_HOST)
3636+ echo '{0}' > libmath.h
3737+- $(MAKE) global.o
3838+- $(LINK) -o fbc $(fbcOBJ) global.o $(LIBBC) $(LIBL) $(READLINELIB) $(LIBS)
3939++ $(MAKE) global.o_host
4040++ $(CC_FOR_BUILD) -o fbc $(fbcOBJ) global.o_host $(LIBBC_HOST) $(LIBL) ${READLINELIB} $(LIBS)
4141+ ./fbc -c $(srcdir)/libmath.b </dev/null >libmath.h
4242+ $(srcdir)/fix-libmath_h
4343+ rm -f ./fbc ./global.o
4444+diff --git a/configure.ac b/configure.ac
4545+index fc74573..5cabb73 100644
4646+--- a/configure.ac
4747++++ b/configure.ac
4848+@@ -20,6 +20,7 @@ m4_define([dc_version], 1.4.1)
4949+5050+ AC_INIT([bc],[bc_version])
5151+ AC_CONFIG_SRCDIR(doc/bc.1)
5252++AC_CONFIG_MACRO_DIR([m4])
5353+ AM_INIT_AUTOMAKE([dist-bzip2])
5454+ AC_CONFIG_HEADERS(config.h)
5555+5656+@@ -35,6 +36,7 @@ AC_DEFINE([DC_COPYRIGHT],
5757+ [Define the dc copyright line.])
5858+5959+ AC_PROG_CC
6060++AX_CC_FOR_BUILD
6161+ AC_USE_SYSTEM_EXTENSIONS
6262+6363+ AM_PROG_LEX
6464+diff --git a/lib/Makefile.am b/lib/Makefile.am
6565+index ec4bf59..c670f5b 100644
6666+--- a/lib/Makefile.am
6767++++ b/lib/Makefile.am
6868+@@ -1,5 +1,5 @@
6969+ ## Process this file with automake to produce Makefile.in
7070+-noinst_LIBRARIES = libbc.a
7171++noinst_LIBRARIES = libbc.a libbc_host.a
7272+7373+ AM_CPPFLAGS = -I. -I.. -I$(srcdir)/../h
7474+7575+@@ -24,3 +24,11 @@ testmul: testmul.o number.o
7676+7777+ specialnumber: newnumber.o
7878+ cp newnumber.o number.o
7979++
8080++%.o_host : CC:=$(CC_FOR_BUILD)
8181++%.o_host : %.c
8282++ $(COMPILE) -c $(CFLAGS) $(INCLUDES) -o $@ $<
8383++
8484++libbc_host.a : $(addsuffix _host,$(libbc_a_OBJECTS))
8585++ ar cru $@ $+
8686++ ranlib $@
8787+diff --git a/m4/cc_for_build.m4 b/m4/cc_for_build.m4
8888+new file mode 100644
8989+index 0000000..c62ffad
9090+--- /dev/null
9191++++ b/m4/cc_for_build.m4
9292+@@ -0,0 +1,77 @@
9393++# ===========================================================================
9494++# https://www.gnu.org/software/autoconf-archive/ax_cc_for_build.html
9595++# ===========================================================================
9696++#
9797++# SYNOPSIS
9898++#
9999++# AX_CC_FOR_BUILD
100100++#
101101++# DESCRIPTION
102102++#
103103++# Find a build-time compiler. Sets CC_FOR_BUILD and EXEEXT_FOR_BUILD.
104104++#
105105++# LICENSE
106106++#
107107++# Copyright (c) 2010 Reuben Thomas <rrt@sc3d.org>
108108++# Copyright (c) 1999 Richard Henderson <rth@redhat.com>
109109++#
110110++# This program is free software: you can redistribute it and/or modify it
111111++# under the terms of the GNU General Public License as published by the
112112++# Free Software Foundation, either version 3 of the License, or (at your
113113++# option) any later version.
114114++#
115115++# This program is distributed in the hope that it will be useful, but
116116++# WITHOUT ANY WARRANTY; without even the implied warranty of
117117++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
118118++# Public License for more details.
119119++#
120120++# You should have received a copy of the GNU General Public License along
121121++# with this program. If not, see <https://www.gnu.org/licenses/>.
122122++#
123123++# As a special exception, the respective Autoconf Macro's copyright owner
124124++# gives unlimited permission to copy, distribute and modify the configure
125125++# scripts that are the output of Autoconf when processing the Macro. You
126126++# need not follow the terms of the GNU General Public License when using
127127++# or distributing such scripts, even though portions of the text of the
128128++# Macro appear in them. The GNU General Public License (GPL) does govern
129129++# all other use of the material that constitutes the Autoconf Macro.
130130++#
131131++# This special exception to the GPL applies to versions of the Autoconf
132132++# Macro released by the Autoconf Archive. When you make and distribute a
133133++# modified version of the Autoconf Macro, you may extend this special
134134++# exception to the GPL to apply to your modified version as well.
135135++
136136++#serial 3
137137++
138138++dnl Get a default for CC_FOR_BUILD to put into Makefile.
139139++AC_DEFUN([AX_CC_FOR_BUILD],
140140++[# Put a plausible default for CC_FOR_BUILD in Makefile.
141141++if test -z "$CC_FOR_BUILD"; then
142142++ if test "x$cross_compiling" = "xno"; then
143143++ CC_FOR_BUILD='$(CC)'
144144++ else
145145++ CC_FOR_BUILD=gcc
146146++ fi
147147++fi
148148++AC_SUBST(CC_FOR_BUILD)
149149++# Also set EXEEXT_FOR_BUILD.
150150++if test "x$cross_compiling" = "xno"; then
151151++ EXEEXT_FOR_BUILD='$(EXEEXT)'
152152++else
153153++ AC_CACHE_CHECK([for build system executable suffix], bfd_cv_build_exeext,
154154++ [rm -f conftest*
155155++ echo 'int main () { return 0; }' > conftest.c
156156++ bfd_cv_build_exeext=
157157++ ${CC_FOR_BUILD} -o conftest conftest.c 1>&5 2>&5
158158++ for file in conftest.*; do
159159++ case $file in
160160++ *.c | *.o | *.obj | *.ilk | *.pdb) ;;
161161++ *) bfd_cv_build_exeext=`echo $file | sed -e s/conftest//` ;;
162162++ esac
163163++ done
164164++ rm -f conftest*
165165++ test x"${bfd_cv_build_exeext}" = x && bfd_cv_build_exeext=no])
166166++ EXEEXT_FOR_BUILD=""
167167++ test x"${bfd_cv_build_exeext}" != xno && EXEEXT_FOR_BUILD=${bfd_cv_build_exeext}
168168++fi
169169++AC_SUBST(EXEEXT_FOR_BUILD)])dnl
+18-3
pkgs/tools/misc/bc/default.nix
···11-{stdenv, fetchurl, flex, readline, ed, texinfo}:
11+{stdenv, autoreconfHook, buildPackages, fetchurl, flex, readline, ed, texinfo}:
2233stdenv.mkDerivation rec {
44 name = "bc-1.07.1";
···991010 configureFlags = [ "--with-readline" ];
11111212- buildInputs = [flex readline ed texinfo];
1212+ # As of 1.07 cross-compilation is quite complicated as the build system wants
1313+ # to build a code generator, bc/fbc, on the build machine.
1414+ patches = [ ./cross-bc.patch ];
1515+ depsBuildBuild = [ buildPackages.stdenv.cc ];
1616+ nativeBuildInputs = [
1717+ # Tools
1818+ autoreconfHook ed flex texinfo
1919+ # Libraries for build
2020+ buildPackages.readline buildPackages.ncurses
2121+ ];
2222+ buildInputs = [ readline ];
13231414- doCheck = true;
2424+ doCheck = true; # not cross
2525+2626+ # Hack to make sure we never to the relaxation `$PATH` and hooks support for
2727+ # compatability. This will be replaced with something clearer in a future
2828+ # masss-rebuild.
2929+ crossConfig = true;
15301631 meta = {
1732 description = "GNU software calculator";