1 From c7c769990bca3049bc389dcbd9985adaec134946 Mon Sep 17 00:00:00 2001
2 From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
3 Date: Sat, 29 Aug 2015 11:59:18 +0200
4 Subject: [PATCH] Use the native compiler to build generate_cookbook
6 The generate_cookbook binary needs to be executed at build time. When
7 cross-compiling, this means that it should be built with the native
8 compiler rather than the cross-compiler.
10 To achieve this, this commit imports the AX_CC_FOR_BUILD autoconf
11 macro from the GNU Autoconf Archive project, and adjusts
12 src/Makefile.am to use CC_FOR_BUILD to build generate_cookbook.
14 Based on initial work by Bernd Kuhls.
16 Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
20 m4/ax_cc_for_build.m4 | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++
21 src/Makefile.am | 3 ++
22 4 files changed, 83 insertions(+)
23 create mode 100644 m4/ax_cc_for_build.m4
25 diff --git a/Makefile.am b/Makefile.am
26 index 4468bca..bd3ce01 100644
29 @@ -2,6 +2,7 @@ AM_CFLAGS = -Isrc -fPIC -Wall -O3 -lm
30 AUTOMAKE_OPTIONS = gnu
32 AM_CPPFLAGS = $(AM_CFLAGS)
33 +ACLOCAL_AMFLAGS = -I m4
35 pkgconfigdir = $(libdir)/pkgconfig
36 pkgconfig_DATA = codec2.pc
37 diff --git a/configure.ac b/configure.ac
38 index 493c517..7520af6 100644
43 AC_INIT(codec2, 0.2, david@rowetel.com)
45 +AC_CONFIG_MACRO_DIR([m4])
47 # Checks for programs.
52 # Checks for libraries.
53 # FIXME: Replace `main' with a function in `-lm':
54 diff --git a/m4/ax_cc_for_build.m4 b/m4/ax_cc_for_build.m4
56 index 0000000..c880fd0
58 +++ b/m4/ax_cc_for_build.m4
60 +# ===========================================================================
61 +# http://www.gnu.org/software/autoconf-archive/ax_cc_for_build.html
62 +# ===========================================================================
70 +# Find a build-time compiler. Sets CC_FOR_BUILD and EXEEXT_FOR_BUILD.
74 +# Copyright (c) 2010 Reuben Thomas <rrt@sc3d.org>
75 +# Copyright (c) 1999 Richard Henderson <rth@redhat.com>
77 +# This program is free software: you can redistribute it and/or modify it
78 +# under the terms of the GNU General Public License as published by the
79 +# Free Software Foundation, either version 3 of the License, or (at your
80 +# option) any later version.
82 +# This program is distributed in the hope that it will be useful, but
83 +# WITHOUT ANY WARRANTY; without even the implied warranty of
84 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
85 +# Public License for more details.
87 +# You should have received a copy of the GNU General Public License along
88 +# with this program. If not, see <http://www.gnu.org/licenses/>.
90 +# As a special exception, the respective Autoconf Macro's copyright owner
91 +# gives unlimited permission to copy, distribute and modify the configure
92 +# scripts that are the output of Autoconf when processing the Macro. You
93 +# need not follow the terms of the GNU General Public License when using
94 +# or distributing such scripts, even though portions of the text of the
95 +# Macro appear in them. The GNU General Public License (GPL) does govern
96 +# all other use of the material that constitutes the Autoconf Macro.
98 +# This special exception to the GPL applies to versions of the Autoconf
99 +# Macro released by the Autoconf Archive. When you make and distribute a
100 +# modified version of the Autoconf Macro, you may extend this special
101 +# exception to the GPL to apply to your modified version as well.
105 +dnl Get a default for CC_FOR_BUILD to put into Makefile.
106 +AC_DEFUN([AX_CC_FOR_BUILD],
107 +[# Put a plausible default for CC_FOR_BUILD in Makefile.
108 +if test -z "$CC_FOR_BUILD"; then
109 + if test "x$cross_compiling" = "xno"; then
110 + CC_FOR_BUILD='$(CC)'
115 +AC_SUBST(CC_FOR_BUILD)
116 +# Also set EXEEXT_FOR_BUILD.
117 +if test "x$cross_compiling" = "xno"; then
118 + EXEEXT_FOR_BUILD='$(EXEEXT)'
120 + AC_CACHE_CHECK([for build system executable suffix], bfd_cv_build_exeext,
122 + echo 'int main () { return 0; }' > conftest.c
123 + bfd_cv_build_exeext=
124 + ${CC_FOR_BUILD} -o conftest conftest.c 1>&5 2>&5
125 + for file in conftest.*; do
127 + *.c | *.o | *.obj | *.ilk | *.pdb) ;;
128 + *) bfd_cv_build_exeext=`echo $file | sed -e s/conftest//` ;;
132 + test x"${bfd_cv_build_exeext}" = x && bfd_cv_build_exeext=no])
133 + EXEEXT_FOR_BUILD=""
134 + test x"${bfd_cv_build_exeext}" != xno && EXEEXT_FOR_BUILD=${bfd_cv_build_exeext}
136 +AC_SUBST(EXEEXT_FOR_BUILD)])dnl
137 diff --git a/src/Makefile.am b/src/Makefile.am
138 index 1153b3c..719088d 100644
139 --- a/src/Makefile.am
140 +++ b/src/Makefile.am
141 @@ -77,6 +77,9 @@ CODEBOOKSGE= \
143 noinst_PROGRAMS = generate_codebook genlspdtcb
145 +generate_codebook$(EXEEXT_FOR_BUILD): generate_codebook.c
146 + $(CC_FOR_BUILD) -o $@ generate_codebook.c -lm
148 codebook.$(OBJEXT): codebook.c
149 codebookd.$(OBJEXT): codebookd.c
150 codebookdt.$(OBJEXT): codebookdt.c