source: git/configure.ac @ 2f7e6d6

stereo-2025
Last change on this file since 2f7e6d6 was c0f9e1e, checked in by Olly Betts <olly@…>, 5 months ago

Use more unlocked stdio functions

Probe for unlocked versions of feof(), ferror(), fread() and fwrite()
as well as getc() and putc().

We don't ever access the same FILE* from multiple threads concurrently
and the unlocked versions have measurably lower overhead.

  • Property mode set to 100644
File size: 13.6 KB
Line 
1dnl Process this file with autoconf to produce a configure script
2
3dnl Need autoconf 2.50 or later for AC_ARG_VAR.  2.59 has been around for
4dnl long enough, that we might as well just require that.
5AC_PREREQ(2.59)
6AC_INIT([survex], [1.4.16], [https://trac.survex.com/])
7AM_INIT_AUTOMAKE([1.5 gnu -Wall -Wportability -Werror])
8RELEASE=1
9
10AC_SUBST(RELEASE)
11AC_CONFIG_HEADERS([config.h])
12AC_CONFIG_SRCDIR([src/aven.cc])
13
14COPYRIGHT_MSG="Copyright (C) 1990-2025 Olly Betts"
15AVEN_COPYRIGHT_MSG="Copyright (C) 1999-2003,2005,2006 Mark R. Shinwell"
16
17AC_DEFINE_UNQUOTED(COPYRIGHT_MSG, ["$COPYRIGHT_MSG"], [Copyright Message])
18AC_DEFINE_UNQUOTED(AVEN_COPYRIGHT_MSG, ["$AVEN_COPYRIGHT_MSG"],
19                   [Copyright Message for Aven])
20
21AC_SUBST(COPYRIGHT_MSG)
22AC_SUBST(AVEN_COPYRIGHT_MSG)
23
24COPYRIGHT_MSG_UTF8=`echo "$COPYRIGHT_MSG"|sed 's/(C)/©/'`
25AVEN_COPYRIGHT_MSG_UTF8=`echo "$AVEN_COPYRIGHT_MSG"|sed 's/(C)/©/'`
26
27AC_DEFINE_UNQUOTED(COPYRIGHT_MSG_UTF8, ["$COPYRIGHT_MSG_UTF8"],
28                   [Copyright Message in UTF-8])
29AC_DEFINE_UNQUOTED(AVEN_COPYRIGHT_MSG_UTF8, ["$AVEN_COPYRIGHT_MSG_UTF8"],
30                   [Copyright Message for Aven in UTF-8])
31
32dnl set PRETTYPACKAGE to PACKAGE with the first character capitalised
33PRETTYPACKAGE=`echo "$PACKAGE"|cut -b1|tr a-z A-Z``echo "$PACKAGE"|cut -b2-`
34AC_DEFINE_UNQUOTED(PRETTYPACKAGE, "$PRETTYPACKAGE",
35                   [Name of package (capitalised)])
36AC_SUBST(PRETTYPACKAGE)
37
38dnl set COMMAVERSION to VERSION with the dots replaced by commas -
39dnl e.g. "0,99" or "1,0,22"
40COMMAVERSION=`echo "$VERSION"|tr '.' ','`
41AC_DEFINE_UNQUOTED(COMMAVERSION, $COMMAVERSION,
42                   [Version number of package (comma-separated)])
43AC_SUBST(COMMAVERSION)
44
45PKGDOCDIR='${prefix}/share/doc/${PACKAGE}'
46AC_ARG_ENABLE(docdir,
47[  --enable-docdir=DIR Set directory for installing documentation to DIR],
48[case $enableval in
49 yes|no)
50  AC_MSG_ERROR([configure: Syntax: configure --enable-docdir=DIR]) ;;
51esac
52PKGDOCDIR="$enableval"
53]
54)
55PKGDOCDIR_EXPANDED=`
56 test NONE = "$prefix" && prefix="$ac_default_prefix"
57 test NONE = "$exec_prefix" && exec_prefix="$prefix"
58 eval echo "$PKGDOCDIR"
59`
60AC_SUBST(PKGDOCDIR)
61AC_SUBST(PKGDOCDIR_EXPANDED)
62
63AC_CANONICAL_HOST
64
65dnl Checks for programs.
66AC_PROG_CC
67AC_PROG_CPP
68
69AC_PROG_CXX
70AC_PROG_CXXCPP
71
72dnl Probe for any options needed to enable C++11 support.
73AX_CXX_COMPILE_STDCXX_11
74
75AM_PROG_CC_C_O
76
77AC_LANG([C])
78
79AC_EXEEXT
80AC_OBJEXT
81
82mswindows=no
83macos=no
84case $host_os in
85darwin*) macos=yes ;;
86*mingw*|*cygwin*|windows*) mswindows=yes ;;
87esac
88
89AC_C_BIGENDIAN
90
91AC_ARG_VAR(STRIP, [Command for discarding symbols from object files])
92AC_PATH_TOOL(STRIP, strip, [echo "not stripping "])
93
94AC_CHECK_LIB(m, sqrt)
95
96dnl x86 has excess precision issues with 387 FP instructions, which are
97dnl avoided by using SSE instructions instead.  By default we require SSE2
98dnl which for Intel means a Pentium 4 which was launched in 2000; Pentium
99dnl 3 was finally discontinued in 2007.
100AC_ARG_ENABLE([sse],
101[AS_HELP_STRING([--disable-sse],
102                [disable use of SSE FP instructions on x86])]
103[AS_HELP_STRING([[--enable-sse[=sse|sse2]]],
104                [set which SSE FP instructions to use on x86 (default: sse2)])],
105  [case ${enableval} in
106    sse|sse2|yes|no) ;;
107    *) AC_MSG_ERROR([bad value ${enableval} for --enable-sse or --disable-sse]) ;;
108  esac],
109  [enable_sse=yes])
110
111AC_MSG_CHECKING([whether to use SSE instructions on x86])
112case $host_cpu in
113  i*86)
114    if test "$enable_sse" = no ; then
115      AC_MSG_RESULT([no - WARNING: Testsuite will probably fail])
116      if test yes = "$msvc"; then
117        dnl MSVC defaults to SSE2.
118        AM_CXXFLAGS="$AM_CXXFLAGS -arch:IA32"
119      fi
120    else
121      dnl Default to sse2.
122      test "$enable_sse" != yes || enable_sse=sse2
123      if test yes = "$GXX"; then
124        AC_MSG_RESULT([yes (configure with --disable-sse to disable)])
125        dnl We can unconditionally use -mtune=generic as it was added in GCC
126        dnl 4.2, and supported at least as far back as clang 3.0.
127        AM_CXXFLAGS="$AM_CXXFLAGS -mfpmath=sse -m$enable_sse -mtune=generic"
128      elif test yes = "$msvc"; then
129        AC_MSG_RESULT([yes (configure with --disable-sse to disable)])
130        if test sse = "$enable_sse"; then
131          dnl MSVC defaults to SSE2.
132          AM_CXXFLAGS="$AM_CXXFLAGS -arch:SSE"
133        fi
134      else
135        AC_MSG_RESULT([don't know how to for compiler $CXX])
136      fi
137    fi
138    ;;
139  *)
140    AC_MSG_RESULT([non-x86 arch ($host_cpu)]) ;;
141esac
142
143dnl The wxWidgets libraries we need:
144wx_libs="core,gl"
145
146AC_ARG_VAR(WXCONFIG, [Old name for WX_CONFIG, accepted for compatibility])
147AC_ARG_VAR(WX_CONFIG, [wxWidgets configuration script to use to build Aven])
148: ${WX_CONFIG="$WXCONFIG"}
149
150AM_CONDITIONAL(WIN32, [test yes = "$mswindows"])
151AM_CONDITIONAL(MACOS, [test yes = "$macos"])
152
153if test -n "$WX_CONFIG" ; then
154  dnl WX_CONFIG specified - sanity check the value
155  dnl don't check for --ldflags - older wx-config didn't do that
156  if (exec >&5 2>&5;$WX_CONFIG --libs --cflags --cxxflags "$wx_libs";exit $?) then
157    :
158  else
159    AC_MSG_ERROR(['$WX_CONFIG --libs --cflags --cxxflags "$wx_libs"' does not work, bailing out])
160  fi
161else
162  if test yes = "$macos" ; then
163    wxdef=__WXMAC__
164  elif test yes = "$mswindows" ; then
165    wxdef=__WXMSW__
166  else
167    wxdef=__WXGTK__
168  fi
169  dnl See if wx-config exists and is for the correct version.
170  dnl Fedora install wx3's wx-config as wx-config-3.0, so look for that in
171  dnl preference.
172  dnl Arch Linux uses wx-config-gtk3.
173  AC_PATH_PROGS(WX_CONFIG, [wx-config-3.0 wx-config-gtk3 wx-config])
174  if test -n "$WX_CONFIG" ; then
175    if (exec >&5 2>&5;$WX_CONFIG --cflags "$wx_libs"|grep -e -D"$wxdef";exit $?) then
176      :
177    else
178      AC_MSG_ERROR([wxWidgets not for the right toolkit.  Run ./configure WX_CONFIG=/path/to/wx-config])
179    fi
180  else
181    AC_MSG_ERROR([wxWidgets not found.  Run ./configure WX_CONFIG=/path/to/wx-config])
182  fi
183fi
184
185dnl Unless the user has explicitly specified a --unicode setting, prefer
186dnl --unicode=yes if we can get it.
187case $WX_CONFIG in
188  *--unicode=*) ;;
189  *)
190    if (exec >&5 2>&5;$WX_CONFIG --unicode=yes --version "$wx_libs";exit $?) ; then
191      WX_CONFIG="$WX_CONFIG --unicode=yes"
192    elif (exec >&5 2>&5;$WX_CONFIG --unicode=no --version "$wx_libs";exit $?) ; then
193      WX_CONFIG="$WX_CONFIG --unicode=no"
194    fi ;;
195esac
196
197WX_LIBS=`$WX_CONFIG --libs "$wx_libs"`
198dnl Needed for nvidia drivers on linux (for some setups anyway).
199AC_CHECK_LIB(Xxf86vm, XF86VidModeQueryVersion, [WX_LIBS="$WX_LIBS -lXxf86vm"], [], [$WX_LIBS])
200
201save_LIBS=$LIBS
202dnl Check if we need a library for OpenGL functions.  Usually it's the "GL"
203dnl library, but it's called opengl32 on Microsoft Windows).
204AC_SEARCH_LIBS([glPushMatrix], [GL opengl32], [WX_LIBS="$WX_LIBS $ac_cv_search_glPushMatrix"], [], [$WX_LIBS])
205dnl Check if we need a library for GLU functions.  Usually it's the "GLU"
206dnl library, but it's called glu32 on Microsoft Windows).
207AC_SEARCH_LIBS([gluProject], [GLU glu32], [WX_LIBS="$WX_LIBS $ac_cv_search_gluProject"], [], [$WX_LIBS])
208LIBS=$save_LIBS
209
210AC_SUBST(WX_LIBS)
211dnl macOS has OpenGL/gl.h.
212AC_CHECK_HEADERS([GL/gl.h OpenGL/gl.h], [], [], [ ])
213dnl The Debian mingw-w64 packages lack GL/glext.h; macOS has OpenGL/glext.h.
214AC_CHECK_HEADERS([GL/glext.h OpenGL/glext.h], [], [], [#include <GL/gl.h>])
215
216WX_CFLAGS=`$WX_CONFIG --cflags "$wx_libs"`
217AC_SUBST(WX_CFLAGS)
218WX_CXXFLAGS=`$WX_CONFIG --cxxflags "$wx_libs"`
219AC_SUBST(WX_CXXFLAGS)
220
221AC_LANG([C])
222save_CFLAGS=$CFLAGS
223CFLAGS="$CFLAGS $WX_CFLAGS"
224AC_CHECK_SIZEOF([wxChar], [], [
225  #include <wx/defs.h>
226  #include <wx/chartype.h>
227])
228CFLAGS=$save_CFLAGS
229
230dnl Check for FFmpeg libraries.
231PKG_CHECK_MODULES([FFMPEG], [libavcodec libavformat libswscale libavutil], [
232  AC_DEFINE([WITH_FFMPEG], [1], [Use FFmpeg for movie export])
233  save_CXXFLAGS=$CXXFLAGS
234  save_LIBS=$LIBS
235  CFLAGS="$CFLAGS $FFMPEG_CFLAGS"
236  LIBS="$LIBS $FFMPEG_LIBS"
237  AC_CHECK_FUNCS([av_guess_format avio_open avio_close avformat_write_header avcodec_encode_video2 avcodec_free_frame avcodec_open2 avformat_new_stream av_frame_alloc av_frame_free])
238  AC_CHECK_DECLS([AVMEDIA_TYPE_VIDEO], [], [], [#include <libavcodec/avcodec.h>])
239  AC_CHECK_DECLS([AV_CODEC_ID_NONE], [], [], [#include <libavcodec/avcodec.h>])
240  AC_CHECK_DECLS([AV_PIX_FMT_RGB24], [], [], [#include <libavutil/pixfmt.h>])
241  AC_CHECK_DECLS([AV_PIX_FMT_YUV420P], [], [], [#include <libavutil/pixfmt.h>])
242  CXXFLAGS=$save_CXXFLAGS
243  LIBS=$save_LIBS
244], [
245  dnl Build without movie export feature.
246])
247AC_SUBST([FFMPEG_LIBS])
248AC_SUBST([FFMPEG_CFLAGS])
249
250dnl Check for PROJ.
251PKG_CHECK_MODULES([PROJ], [proj >= 6.2.0], [
252], [
253  dnl pkg-config support in proj seems quite new, so probe directly if not
254  dnl found.  We need proj_create_crs_to_crs_from_pj() which was added in
255  dnl 6.2.0.
256  AC_CHECK_LIB([proj], [proj_create_crs_to_crs_from_pj], [
257      PROJ_LIBS=-lproj
258      PROJ_CFLAGS=
259    ], [
260      AC_MSG_ERROR([PROJ required for coordinate transformations])
261    ])
262])
263AC_SUBST([PROJ_LIBS])
264AC_SUBST([PROJ_CFLAGS])
265
266dnl Check for GDAL.
267PKG_CHECK_MODULES([GDAL], [gdal >= 2.3], [
268  AC_DEFINE([HAVE_GDAL], [1], [Define to 1 if you have the 'GDAL' library.])
269], [
270  if test "$mswindows" = no ; then
271    AC_MSG_ERROR([GDAL required for geodata handling])
272  else
273    AC_MSG_WARN([GDAL required for geodata handling])
274  fi
275])
276AC_SUBST([GDAL_LIBS])
277AC_SUBST([GDAL_CFLAGS])
278
279dnl Checks for header files.
280
281AC_CHECK_HEADERS(string.h)
282
283AC_CHECK_FUNCS([popen hypot mmap])
284
285dnl We don't access a FILE* from multiple threads and using the unlocked
286dnl versions has significantly less overhead, especially when reading/writing
287dnl byte-by-byte.  These are specified by POSIX:
288AC_CHECK_FUNCS([getc_unlocked putc_unlocked])
289dnl These are GNU extensions in glibc:
290AC_CHECK_FUNCS([feof_unlocked ferror_unlocked fread_unlocked fwrite_unlocked])
291
292AC_CHECK_FUNCS([setenv unsetenv])
293
294AC_CHECK_FUNCS([fmemopen])
295
296dnl Microsoft-specific functions which support positional argument specifiers.
297AC_CHECK_FUNCS([_vfprintf_p _vsprintf_p])
298
299AC_PATH_PROG([SPHINX_BUILD], [sphinx-build], [$MISSING sphinx-build])
300AC_ARG_VAR([SPHINX_BUILD], [sphinx-build from python3-sphinx])
301
302AC_PATH_PROG([MSGFMT], [msgfmt], [$MISSING msgfmt])
303AC_ARG_VAR([MSGFMT], [msgfmt from gettext])
304
305AC_ARG_ENABLE([werror],
306  [AS_HELP_STRING([--enable-werror], [enable treating compiler warnings as errors [default=no]])],
307  [case ${enableval} in
308    yes|no) ;;
309  *) AC_MSG_ERROR([bad value ${enableval} for --enable-werror]) ;;
310  esac],
311  [enable_werror=no])
312
313dnl Put -Werror or equivalent in its own make variable so that it can easily
314dnl be overridden by `make WERROR=` if needed during development (e.g. if
315dnl you want to get a full list of compile warnings to fix rather than
316dnl stopping at the first file with warnings).
317WERROR=
318AC_SUBST([WERROR])
319
320dnl extra warning flags for building with GCC
321if test yes = "$GCC"; then
322  WERROR=-Werror
323  if test yes = "$cross_compiling"; then
324dnl    AM_CFLAGS="$AM_CFLAGS -Werror -Wall -Wunused -Wpointer-arith\
325dnl      -Wwrite-strings -Wcast-align"
326dnl -Wsign-compare causes a warning with the mingw FD_SET macro, so we have
327dnl to disable it for mingw builds.
328    AM_CFLAGS="$AM_CFLAGS -Wall -Wunused -Wpointer-arith\
329      -Wwrite-strings -Wcast-align"
330    AM_CXXFLAGS="$AM_CXXFLAGS -Wall -Wunused -Wpointer-arith\
331      -Wwrite-strings -Wcast-align -Wno-sign-compare"
332  else
333    AM_CFLAGS="$AM_CFLAGS -Wall -W -Wunused -Wshadow -Wpointer-arith\
334      -Wmissing-prototypes -Wwrite-strings -Wredundant-decls -Wnested-externs\
335      -Wcast-align"
336    AM_CXXFLAGS="$AM_CXXFLAGS -Wall -W -Wunused -Wshadow -Wpointer-arith\
337      -Wwrite-strings -Wcast-align"
338  fi
339  dnl too many complaints from headers, etc: -Wconversion
340fi
341AC_SUBST(AM_CFLAGS)
342AC_SUBST(AM_CXXFLAGS)
343
344if test x$enable_werror != xyes; then
345  WERROR=
346fi
347
348dnl See if large file support is available.  Survex is unlikely to need to
349dnl process files > 2GB in size, but LFS is also needed for stat() to work
350dnl on filing systems which return 64 bit inode values, such as CIFS mounts.
351AC_SYS_LARGEFILE
352
353AC_ARG_ENABLE(profiling,
354[  --enable-profiling Build binaries to generate profiling information],
355[case $enableval in
356  yes) AM_CXXFLAGS="$AM_CXXFLAGS -pg"
357       AM_CFLAGS="$AM_CFLAGS -pg"
358       AC_MSG_RESULT(building binaries to generate profiling information);;
359  no) ;;
360  *) AC_MSG_ERROR(bad value $enableval for --enable-profiling) ;;
361esac])
362
363EXTRA_TEXT="AUTHORS COPYING NEWS TODO ChangeLog"
364AC_SUBST(EXTRA_TEXT)
365
366AC_SUBST_FILE(DESC)
367DESC=desc.txt
368AC_SUBST_FILE(AVENDESC)
369AVENDESC=desc-aven.txt
370
371dnl Don't define DATADIR if building for MS Windows - it won't be used, and
372dnl can conflict with the DATADIR typedef in objidl.h
373if test no = "$mswindows"; then
374  AC_DEFINE_DIR(DATADIR, datadir, [Location of platform independent support files])
375fi
376
377AH_BOTTOM(
378[/* Use _unlocked() variants of stdio functions where available, since they are
379 * faster, and we don't multithread file accesses.
380 */
381
382#ifdef HAVE_FEOF_UNLOCKED
383# define FEOF(F) feof_unlocked(F)
384#else
385# define FEOF(F) feof(F)
386#endif
387
388#ifdef HAVE_FERROR_UNLOCKED
389# define FERROR(F) ferror_unlocked(F)
390#else
391# define FERROR(F) ferror(F)
392#endif
393
394#ifdef HAVE_FREAD_UNLOCKED
395# define FREAD(P, S, N, F) fread_unlocked(P, S, N, F)
396#else
397# define FREAD(P, S, N, F) fread(P, S, N, F)
398#endif
399
400#ifdef HAVE_FWRITE_UNLOCKED
401# define FWRITE(P, S, N, F) fwrite_unlocked(P, S, N, F)
402#else
403# define FWRITE(P, S, N, F) fwrite(P, S, N, F)
404#endif
405
406#ifdef HAVE_GETC_UNLOCKED
407# define GETC(F) getc_unlocked(F)
408#else
409# define GETC(F) getc(F)
410#endif
411
412#ifdef HAVE_PUTC_UNLOCKED
413# define PUTC(C, F) putc_unlocked(C, F)
414#else
415# define PUTC(C, F) putc(C, F)
416#endif
417
418#ifndef __cplusplus
419/* C23 added bool, false and true as keywords - let's emulate that and
420 * avoid every C file which uses these needing to include <stdbool.h>.
421 */
422# include <stdbool.h>
423#endif
424])
425
426AC_CONFIG_FILES([
427 Makefile src/Makefile doc/Makefile lib/Makefile lib/icons/Makefile
428 lib/images/Makefile
429 tests/Makefile vim/Makefile survex.iss doc/index.htm
430 survex.spec lib/Info.plist
431 ])
432AC_OUTPUT
433dnl FIXME update msvc makefile for 1.2 branch
434dnl src/msvc/config.h
Note: See TracBrowser for help on using the repository browser.