summaryrefslogtreecommitdiffstats
path: root/configure.ac
blob: 7590896a0e94f692422d191f85f70261c427302d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 Her Majesty the
# Queen in Right of Canada (Communications Research Center Canada)

# Copyright (C) 2022 Matthias P. Braendli, http://opendigitalradio.org

# This file is part of ODR-DabMod.
#
# ODR-DabMod is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# ODR-DabMod is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with ODR-DabMod.  If not, see <http://www.gnu.org/licenses/>.

AC_PREREQ([2.69])
AC_INIT([ODR-DabMod],[2.6.0],[matthias.braendli@mpb.li])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_MACRO_DIR([m4])
AC_CANONICAL_TARGET
AM_INIT_AUTOMAKE([-Wall foreign subdir-objects])
AC_CONFIG_SRCDIR([src/DabMod.cpp])
AC_CONFIG_HEADERS([config.h])
AM_SILENT_RULES([yes])

# Checks for programs.
AC_PROG_CXX
AC_PROG_CC
AM_PROG_CC_C_O
AC_PROG_INSTALL

AX_CXX_COMPILE_STDCXX(11,noext,mandatory)

EXTRA=""
AC_ARG_ENABLE([prof],
        [AS_HELP_STRING([--enable-prof], [Enable profiling])],
        [], [enable_prof=no])
AC_ARG_ENABLE([fast-math],
        [AS_HELP_STRING([--enable-fast-math], [Set -ffast-math])],
        [], [enable_fast_math=no])
AC_ARG_ENABLE([trace],
        [AS_HELP_STRING([--enable-trace], [Enable trace output])],
        [], [enable_trace=no])
AC_ARG_ENABLE([zeromq],
        [AS_HELP_STRING([--disable-zeromq], [Disable ZeroMQ input, output and remote control])],
        [], [enable_zeromq=yes])
AC_ARG_ENABLE([native],
        [AS_HELP_STRING([--disable-native], [Do not compile with -march=native])],
        [], [enable_native=yes])
AC_ARG_ENABLE([easydabv3],
        [AS_HELP_STRING([--enable-easydabv3], [Build for EasyDABv3 board])],
        [], [enable_easydabv3=no])
AC_ARG_ENABLE([limesdr],
        [AS_HELP_STRING([--enable-limesdr], [Build for LimeSDR board])],
        [], [enable_limesdr=no])
AC_ARG_ENABLE([bladerf],
        [AS_HELP_STRING([--enable-bladerf], [Build for BladeRF boards])],
        [], [enable_bladerf=no])

# UHD support control
AC_ARG_ENABLE([output_uhd],
        [AS_HELP_STRING([--disable-output-uhd], [Disable UHD output])],
        [], [enable_output_uhd=yes])

AC_LANG_PUSH([C++])
AX_CHECK_COMPILE_FLAG([-Wduplicated-cond], [CXXFLAGS="$CXXFLAGS -Wduplicated-cond"], [], ["-Werror"])
AX_CHECK_COMPILE_FLAG([-Wduplicated-branches], [CXXFLAGS="$CXXFLAGS -Wduplicated-branches"], [], ["-Werror"])
AX_CHECK_COMPILE_FLAG([-Wlogical-op], [CXXFLAGS="$CXXFLAGS -Wlogical-op"], [], ["-Werror"])
AX_CHECK_COMPILE_FLAG([-Wrestrict], [CXXFLAGS="$CXXFLAGS -Wrestrict"], [], ["-Werror"])
AX_CHECK_COMPILE_FLAG([-Wno-pragmas], [CXXFLAGS="$CXXFLAGS -Wno-pragmas"], [], ["-Werror"])
AX_CHECK_COMPILE_FLAG([-Wdouble-promotion], [CXXFLAGS="$CXXFLAGS -Wdouble-promotion"], [], ["-Werror"])
AX_CHECK_COMPILE_FLAG(["-Wformat=2"], [CXXFLAGS="$CXXFLAGS -Wformat=2"], [], ["-Werror"])
AC_LANG_POP([C++])


AS_IF([test "x$enable_easydabv3" = "xno"],
    [PKG_CHECK_MODULES([FFTW], [fftw3f], [], [AC_MSG_ERROR([FFTW is required])])])

echo "Checking zeromq"

AS_IF([test "x$enable_zeromq" = "xyes"],
         [AC_CHECK_LIB([zmq], [zmq_init], [ZMQ_LIBS="-lzmq"],
                       [AC_MSG_ERROR([ZeroMQ libzmq is required])])])

AS_IF([test "x$enable_zeromq" = "xyes"],
        [AC_DEFINE(HAVE_ZEROMQ, [1], [Define if ZeroMQ is enabled])])

AS_IF([test "x$enable_prof" != "xno"],
        [EXTRA="$EXTRA -pg"])

AS_IF([test "x$enable_fast_math" != "xno"],
        [EXTRA="$EXTRA -ffast-math"])

AS_IF([test "x$enable_trace" != "xno"],
        AC_DEFINE(TRACE, [1], [Enable trace output for all blocks]))

# Define conditionals for Makefile.am
AM_CONDITIONAL([IS_GIT_REPO], [test -d '.git'])
AM_CONDITIONAL([COMPILE_FOR_EASYDABV3], [test "x$enable_easydabv3" = "xyes"])

# Defines for config.h
AX_PTHREAD([], AC_MSG_ERROR([requires pthread]))

AS_IF([test "x$enable_easydabv3" = "xno"],
    [PKG_CHECK_MODULES([SOAPYSDR], [SoapySDR], enable_soapysdr=yes, enable_soapysdr=no)])

AS_IF([test "x$enable_limesdr" = "xyes"],
         [AC_CHECK_LIB([LimeSuite], [LMS_Init], [LIMESDR_LIBS="-lLimeSuite"],
                       [AC_MSG_ERROR([LimeSDR LimeSuite is required])])])

AS_IF([test "x$enable_bladerf" = "xyes"],
         [AC_CHECK_LIB([bladeRF], [bladerf_open], [BLADERF_LIBS="-lbladeRF"],
                       [AC_MSG_ERROR([BladeRF library is required])])])

AC_SUBST([CFLAGS], ["$CFLAGS $EXTRA $FFTW_CFLAGS $SOAPYSDR_CFLAGS $PTHREAD_CFLAGS"])
AC_SUBST([CXXFLAGS], ["$CXXFLAGS $EXTRA $FFTW_CFLAGS $SOAPYSDR_CFLAGS $PTHREAD_CFLAGS"])
AC_SUBST([LIBS], ["$FFTW_LIBS $SOAPYSDR_LIBS $PTHREAD_LIBS $ZMQ_LIBS $LIMESDR_LIBS $BLADERF_LIBS"])

AS_IF([test "x$enable_easydabv3" = "xyes" && test "x$enable_output_uhd" == "xyes"],
      AC_MSG_ERROR([Cannot enable both EasyDABv3 and UHD output]))

# Checks for UHD.
AS_IF([test "x$enable_output_uhd" = "xyes"],
      [ PKG_CHECK_MODULES([UHD], [uhd], [], [AC_MSG_ERROR([UHD is required])])
      ])

AS_IF([test "x$enable_output_uhd" = "xyes"],
      [AC_DEFINE(HAVE_OUTPUT_UHD, [1], [Define if UHD output is enabled])])

# I don't know why this is needed, I think the uhd pkg-config file should also
# tell us to link against boost thread, but it doesn't.
AS_IF([test "x$enable_output_uhd" = "xyes"],
    [ AX_BOOST_BASE([1.55.0], [], AC_MSG_ERROR([BOOST 1.55 or later is required]))
      AX_BOOST_THREAD ])

AS_IF([test "x$enable_soapysdr" = "xyes"],
      [AC_DEFINE(HAVE_SOAPYSDR, [1], [Define if SoapySDR output is enabled])])

AS_IF([test "x$enable_limesdr" = "xyes"],
      [AC_DEFINE(HAVE_LIMESDR, [1], [Define if LimeSDR output is enabled]) ])

AS_IF([test "x$enable_bladerf" = "xyes"],
      [AC_DEFINE(HAVE_BLADERF, [1], [Define if BladeRF output is enabled]) ])

AS_IF([test "x$enable_easydabv3" = "xyes"],
      AC_DEFINE(BUILD_FOR_EASYDABV3, [1], [Define if we are building for EasyDABv3]))


# Checks for header files.
AC_CHECK_HEADERS([fcntl.h limits.h memory.h netinet/in.h stdint.h stdlib.h string.h sys/time.h sys/timeb.h unistd.h])

AC_MSG_CHECKING(for M_PIl existence)
AC_LANG_PUSH([C++])
AC_COMPILE_IFELSE(
        [AC_LANG_PROGRAM([[#include <math.h>]], [[double pi = M_PIl;]])],
        [AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no]) AC_DEFINE([M_PIl], [M_PI], [Replacing define])])
AC_LANG_POP([C++])

# Linux has prctl to set thread names
AC_MSG_CHECKING(for prctl and PR_SET_NAME)
AC_COMPILE_IFELSE([ AC_LANG_PROGRAM([[
                    #include <sys/prctl.h>
                    void set_thread_name() {
                        prctl(PR_SET_NAME,"test",0,0,0);
                    }
                    ]])],
                   [ AC_MSG_RESULT(yes)
                     AC_DEFINE(HAVE_PRCTL, 1, [Define this symbol if you have prctl and PR_SET_NAME]) ],
                   [ AC_MSG_RESULT(no) ])

# Linux defines MSG_NOSIGNAL, some other systems have SO_NOSIGPIPE instead
AC_MSG_CHECKING(for MSG_NOSIGNAL)
AC_COMPILE_IFELSE([ AC_LANG_PROGRAM([[
                    #include <sys/socket.h>
                    int f = MSG_NOSIGNAL;
                    ]])],
                   [ AC_MSG_RESULT(yes)
                     AC_DEFINE(HAVE_MSG_NOSIGNAL, 1, [Define this symbol if you have MSG_NOSIGNAL]) ],
                   [ AC_MSG_RESULT(no) ])

AC_MSG_CHECKING(for SO_NOSIGPIPE)
AC_COMPILE_IFELSE([ AC_LANG_PROGRAM([[
                    #include <sys/socket.h>
                    int f = SO_NOSIGPIPE;
                    ]])],
                   [ AC_MSG_RESULT(yes)
                     AC_DEFINE(HAVE_SO_NOSIGPIPE, 1, [Define this symbol if you have SO_NOSIGPIPE]) ],
                   [ AC_MSG_RESULT(no) ])

# Check for march
AS_IF([test "x$enable_native" = "xyes"],
      [AC_MSG_CHECKING(if we can add -march=native to CFLAGS)
       save_CXXFLAGS="$CXXFLAGS"
       CXXFLAGS="$CXXFLAGS -march=native"
       AC_COMPILE_IFELSE(  [AC_LANG_PROGRAM([[
                            void testfunc(void) {}
                            ]])],
                            [supports_march_native=yes],
                            [supports_march_native=no]
                            )
       AC_MSG_RESULT($supports_march_native)
       if test x"$supports_march_native" = xno; then
           CXXFLAGS="$save_CXXFLAGS"
       fi
      ])

AC_CONFIG_FILES([Makefile])
AC_OUTPUT

echo
echo "***********************************************"
echo
enabled=""
disabled=""
for feat in prof trace output_uhd zeromq soapysdr easydabv3 limesdr bladerf
do
    eval var=\$enable_$feat
    AS_IF([test "x$var" = "xyes"],
          [enabled="$enabled $feat"],
          [disabled="$disabled $feat"])
done
echo "  Features"
echo "  Enabled: $enabled"
echo "  Disabled: $disabled"
echo
echo
enabled=""
disabled=""
for feat in supports_march_native enable_fast_math
do
    eval var=\$$feat
    AS_IF([test "x$var" != "xno"],
          [enabled="$enabled $feat"],
          [disabled="$disabled $feat"])
done
echo "  Options"
echo "  Active: $enabled"
echo "  Disabled: $disabled"

echo
echo "***********************************************"
echo