configure.ac 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. #
  2. # /*
  3. # * This program is free software: you can redistribute it and/or modify
  4. # * it under the terms of the GNU General Public License as published by
  5. # * the Free Software Foundation, either version 3 of the License, or
  6. # * (at your option) any later version.
  7. # *
  8. # * This program is distributed in the hope that it will be useful,
  9. # * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # * GNU General Public License for more details.
  12. # *
  13. # * You should have received a copy of the GNU General Public License
  14. # * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. # *
  16. # * SPDX-License-Identifier: GPL-3.0+
  17. # * License-Filename: LICENSE
  18. # *
  19. # */
  20. #
  21. # -*- Autoconf -*-
  22. # Process this file with autoconf to produce a configure script.
  23. # Macro: AC_INIT (package, version, [bug-report], [tarname], [url])
  24. # minor version number is increased at important feature change
  25. # Process with autogen.sh or manual:
  26. # aclocal
  27. # autoheader
  28. # autoconf
  29. # libtoolize --force --automake
  30. # automake -a --gnu --include-deps
  31. # or do this all using autoreconf
  32. #
  33. # test also using scan-build from llvm clang tools
  34. #
  35. AC_PREREQ([2.69])
  36. AC_INIT([kissgml], [1.0], [mooigraph@gmail.com])
  37. AC_CONFIG_SRCDIR([src/main.h])
  38. AC_CONFIG_HEADERS([config.h])
  39. AM_INIT_AUTOMAKE
  40. # Checks for programs.
  41. AC_PROG_CC
  42. AC_PROG_MAKE_SET
  43. # -DFORTIFY_SOURCE=2 does add glibc extra checks, see RedHat documentation
  44. # Need c11 mode because of %llu in printf() and (long long int) datatype and unnamed unions
  45. # Upcoming c standard is c17 using GNU GCC -std=c17
  46. # or CFLAGS="$CFLAGS ..."
  47. # do not optimize away memset()
  48. #CFLAGS="$CFLAGS -g -std=c99 -fno-builtin-memset -DFORTIFY_SOURCE=2 -fdump-rtl-expand-graph"
  49. CFLAGS="$CFLAGS -g -std=c99 -fno-builtin-memset -DFORTIFY_SOURCE=2"
  50. # Gcc compiler options
  51. # the option -frecord-gcc-switches puts the compiler options
  52. # in the binary ro read with: readelf -p .GCC.command.line a.out
  53. # https://github.com/Barro/compiler-warnings has lists of gcc options
  54. AC_DEFUN([GCC_COMPILER_WARNING],
  55. [AC_MSG_CHECKING(whether compiler accepts $1)
  56. AC_SUBST(WARNING_CFLAGS)
  57. ac_save_CFLAGS="$CFLAGS"
  58. CFLAGS="$CFLAGS $1"
  59. AC_TRY_COMPILE(,
  60. [int x;],
  61. WARNING_CFLAGS="$WARNING_CFLAGS $1"
  62. AC_MSG_RESULT(yes),
  63. AC_MSG_RESULT(no))
  64. CFLAGS="$ac_save_CFLAGS"])
  65. # the fortify -D option needs optimizing, cannot use -O0 then.
  66. # for debug with gdb the -O0 is needed or it cannot find crashes.
  67. # prints gcc settings and include files and is very verbose
  68. # GCC_COMPILER_WARNING(--verbose)
  69. # GCC_COMPILER_WARNING(-H)
  70. AC_ARG_ENABLE(gcc-warnings,
  71. AC_HELP_STRING([--enable-gcc-warnings],
  72. [turn on lots of GCC warnings (not recommended)]),
  73. [case "${enableval}" in
  74. yes|no) ;;
  75. *) AC_MSG_ERROR([unknown value ${enableval} for gcc-warnings option expected yes or no]) ;;
  76. esac],
  77. [enableval=no])
  78. if test "${enableval}" = yes; then
  79. GCC_COMPILER_WARNING(-Werror)
  80. AC_SUBST([WERROR_CFLAGS], [$WARNING_CFLAGS])
  81. WARNING_CFLAGS=
  82. GCC_COMPILER_WARNING(-O0)
  83. GCC_COMPILER_WARNING(-Wall)
  84. GCC_COMPILER_WARNING(-Wextra)
  85. GCC_COMPILER_WARNING(-W)
  86. GCC_COMPILER_WARNING(-Wbad-function-cast)
  87. GCC_COMPILER_WARNING(-Wcast-align)
  88. GCC_COMPILER_WARNING(-ftrapv)
  89. GCC_COMPILER_WARNING(-Wformat)
  90. GCC_COMPILER_WARNING(-Wmissing-declarations)
  91. GCC_COMPILER_WARNING(-Wmissing-prototypes)
  92. GCC_COMPILER_WARNING(-Wnested-externs)
  93. GCC_COMPILER_WARNING(-Wshadow)
  94. GCC_COMPILER_WARNING(-Wstrict-prototypes)
  95. GCC_COMPILER_WARNING(-Woverlength-strings)
  96. GCC_COMPILER_WARNING(-Wformat-nonliteral)
  97. GCC_COMPILER_WARNING(-Wformat-security)
  98. GCC_COMPILER_WARNING(-Winit-self)
  99. GCC_COMPILER_WARNING(-Winline)
  100. GCC_COMPILER_WARNING(-Wmisleading-indentation)
  101. GCC_COMPILER_WARNING(-Wlogical-op)
  102. GCC_COMPILER_WARNING(-Wduplicated-cond)
  103. GCC_COMPILER_WARNING(-Wtautological-compare)
  104. GCC_COMPILER_WARNING(-Wshift-count-negative)
  105. GCC_COMPILER_WARNING(-Wshift-count-overflow)
  106. GCC_COMPILER_WARNING(-Wshift-negative-value)
  107. GCC_COMPILER_WARNING(-Wshift-overflow)
  108. GCC_COMPILER_WARNING(-Wnull-dereference)
  109. GCC_COMPILER_WARNING(-Wnonnull)
  110. GCC_COMPILER_WARNING(-Woverride-init-side-effects)
  111. GCC_COMPILER_WARNING(-Wunused-const-variable)
  112. GCC_COMPILER_WARNING(-Wframe-address)
  113. else
  114. WARNING_CFLAGS=
  115. GCC_COMPILER_WARNING(-Wall)
  116. GCC_COMPILER_WARNING(-Wshadow)
  117. GCC_COMPILER_WARNING(-Wno-overlength-strings)
  118. GCC_COMPILER_WARNING(-pedantic)
  119. GCC_COMPILER_WARNING(-D_FORTIFY_SOURCE=2)
  120. GCC_COMPILER_WARNING(-fstack-protector-strong)
  121. GCC_COMPILER_WARNING(-Wl,-O1)
  122. GCC_COMPILER_WARNING(-frecord-gcc-switches)
  123. GCC_COMPILER_WARNING(-grecord-gcc-switches)
  124. GCC_COMPILER_WARNING(-Wpointer-arith)
  125. GCC_COMPILER_WARNING(-fvar-tracking-assignments)
  126. GCC_COMPILER_WARNING(-fcompare-debug)
  127. GCC_COMPILER_WARNING(-flto)
  128. GCC_COMPILER_WARNING(-fcallgraph-info)
  129. GCC_COMPILER_WARNING(-fwhole-program)
  130. fi
  131. # GCC compiler rtl and tree data generation
  132. # GCC_COMPILER_WARNING(-fdump-rtl-all-graph)
  133. # GCC_COMPILER_WARNING(-fdump-tree-all-graph)
  134. # GCC_COMPILER_WARNING(-fcallgraph-info)
  135. # Checks for libraries.
  136. AC_CHECK_LIB([m], [sqrt])
  137. # Checks for header files.
  138. AC_CHECK_HEADERS([limits.h stdlib.h stdint.h string.h inttypes.h])
  139. # Checks for typedefs, structures, and compiler characteristics.
  140. # Checks for library functions.
  141. AC_CHECK_FUNCS(memset strdup)
  142. #-------------------------------------------
  143. # Check for math.h include and math library.
  144. # Old distros, use CHECK as a SEARCH backup.
  145. AC_CHECK_HEADER([math.h],
  146. AC_SEARCH_LIBS([cos],[m],[have_libm=yes],
  147. AC_CHECK_LIB([m],[cos],[have_libm=yes])))
  148. if test x"${have_libm}" != xyes; then
  149. AC_MSG_FAILURE([ERROR: Please install Math libraries and math.h include files for libm],[1])
  150. fi
  151. #-------------------------------------------
  152. # Check for C99 hypot. Error if none found.
  153. # Older compilers will have to set/use C99.
  154. AC_CHECK_FUNCS(hypot, ,[AC_MSG_FAILURE([ERROR: hypot() required but not found.],[1])])
  155. #-------------------------------------------
  156. # Check for C99 isfinite or finite. Use one.
  157. math_isfinite=no
  158. math_finite=no
  159. AC_CHECK_FUNCS(isfinite,
  160. [AC_DEFINE(HAVE_ISFINITE, 1)
  161. math_isfinite=true],
  162. [AC_LINK_IFELSE(
  163. [AC_LANG_PROGRAM(
  164. [[#include <math.h>]],
  165. [[double f = 0.0; isfinite(f)]])],
  166. [AC_DEFINE(HAVE_ISFINITE, 1)
  167. math_isfinite=true],
  168. [AC_CHECK_FUNCS(finite,
  169. [AC_DEFINE(HAVE_FINITE, 1)
  170. math_finite=true])])])
  171. if test x"${math_isfinite}" = xno && test x"${math_finite}" = xno; then
  172. AC_MSG_FAILURE([ERROR: isfinite() or finite() required but not found.],[1])
  173. fi
  174. AC_SUBST(HAVE_FINITE)
  175. AC_SUBST(HAVE_ISFINITE)
  176. # default to gtk+-2.0 setting to 1
  177. GTK_HAVE_API_VERSION_2=1
  178. GTK_HAVE_API_VERSION_3=0
  179. GTK_HAVE_API_VERSION_4=0
  180. AC_ARG_ENABLE(gtk2,
  181. [ --enable-gtk2 Use GTK 2.0 in preference to GTK 3.0 [[default=no]]],
  182. [if test "$enableval" = "yes"
  183. then
  184. prefer_gtk2=yes
  185. else
  186. prefer_gtk2=no
  187. fi])
  188. AC_MSG_CHECKING([which gtk+ version to compile against])
  189. AC_ARG_WITH([gtk],
  190. [AS_HELP_STRING([--with-gtk=2.0|3.0|4.0],[which gtk+ version to compile against (default: 3.0)])],
  191. [case "$with_gtk" in
  192. 2.0|3.0|4.0) ;;
  193. *) AC_MSG_ERROR([invalid gtk version specified]) ;;
  194. esac],
  195. [with_gtk=2.0])
  196. AC_MSG_RESULT([$with_gtk])
  197. case "$with_gtk" in
  198. 2.0) GTK_API_VERSION=2.0
  199. GTK_REQUIRED=2.0.0
  200. GTK_HAVE_API_VERSION_2=1
  201. GTK_HAVE_API_VERSION_3=0
  202. GTK_HAVE_API_VERSION_4=0
  203. ;;
  204. 3.0) GTK_API_VERSION=3.0
  205. GTK_REQUIRED=2.91.0
  206. GTK_HAVE_API_VERSION_2=0
  207. GTK_HAVE_API_VERSION_3=1
  208. GTK_HAVE_API_VERSION_4=0
  209. ;;
  210. 4.0) GTK_API_VERSION=4.0
  211. GTK_REQUIRED=3.91.0
  212. GTK_HAVE_API_VERSION_2=0
  213. GTK_HAVE_API_VERSION_3=0
  214. GTK_HAVE_API_VERSION_4=1
  215. ;;
  216. esac
  217. #
  218. AC_SUBST([GTK_API_VERSION])
  219. AC_SUBST([GTK_REQUIRED])
  220. #
  221. AM_CONDITIONAL([HAVE_GTK_2],[test "$with_gtk" = "2.0"])
  222. AM_CONDITIONAL([HAVE_GTK_3],[test "$with_gtk" = "3.0"])
  223. AM_CONDITIONAL([HAVE_GTK_4],[test "$with_gtk" = "4.0"])
  224. #
  225. AC_DEFINE_UNQUOTED([GTK_HAVE_API_VERSION_2], [$GTK_HAVE_API_VERSION_2], [gtk version 2])
  226. AC_DEFINE_UNQUOTED([GTK_HAVE_API_VERSION_3], [$GTK_HAVE_API_VERSION_3], [gtk version 3])
  227. AC_DEFINE_UNQUOTED([GTK_HAVE_API_VERSION_4], [$GTK_HAVE_API_VERSION_4], [gtk version 4])
  228. # Preliminary check for pkg-config
  229. if test -z "$PKG_CONFIG"; then
  230. AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
  231. fi
  232. if test "$PKG_CONFIG" = "no" ; then
  233. echo "
  234. Please install pkg-config and then reconfigure mooigraph.
  235. pkg-config is available from http://www.freedesktop.org/
  236. "
  237. exit 1
  238. fi
  239. # glib 2.0 (needed even if not building GUI; we need 2.14 for regexp functions)
  240. PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.14.0, have_glib2="yes", have_glib2="no")
  241. if test "${have_glib2}" = "no" ; then
  242. echo "
  243. Please install glib-2.0 >= 2.14.0 and then reconfigure mooigraph.
  244. glib-2.0 is available from http://www.gtk.org/
  245. "
  246. exit 1
  247. fi
  248. # Initial check for GTK availability
  249. if test "$prefer_gtk2" = "yes" ; then
  250. PKG_CHECK_MODULES(GTK2, gtk+-2.0 >= 2.14.0,
  251. GTK_CFLAGS=$GTK2_CFLAGS
  252. GTK_LIBS=$GTK2_LIBS
  253. CFLAGS="$CFLAGS $GTK_CFLAGS"
  254. LIBS="$LIBS $GTK_LIBS"
  255. gtk_version="2.0",
  256. echo "GTK 2 >= 2.14.0 not found"
  257. )
  258. elif test "$prefer_gtk2" = "no" ; then
  259. PKG_CHECK_MODULES(GTK3, gtk+-3.0 >= 3.0.1,
  260. GTK_CFLAGS=$GTK3_CFLAGS
  261. GTK_LIBS=$GTK3_LIBS
  262. CFLAGS="$CFLAGS $GTK_CFLAGS"
  263. LIBS="$LIBS $GTK_LIBS"
  264. dnl AC_DEFINE(USE_GTK3)
  265. gtk_version="3.0"
  266. fake_gtkspinner="no",
  267. echo "GTK 3 >= 3.0.1 not found"
  268. )
  269. fi
  270. dnl GTK 2.0 fallback in case preference not given
  271. if test "$prefer_gtk2" = "no" && test "$gtk_version" = "none" ; then
  272. PKG_CHECK_MODULES(GTK2, gtk+-2.0 >= 2.14.0,
  273. GTK_CFLAGS=$GTK2_CFLAGS
  274. GTK_LIBS=$GTK2_LIBS
  275. CFLAGS="$CFLAGS $GTK_CFLAGS"
  276. LIBS="$LIBS $GTK_LIBS"
  277. gtk_version="2.0",
  278. build_gui="no"
  279. echo "GTK 2 >= 2.14.0 not found"
  280. )
  281. fi
  282. #
  283. PKG_CHECK_MODULES(GTK, gtk+-$GTK_API_VERSION >= $GTK_REQUIRED)
  284. AC_SUBST(GTK_CFLAGS)
  285. AC_SUBST(GTK_LIBS)
  286. # final compiler settings
  287. AC_SUBST(PACKAGE_CFLAGS)
  288. # final compiler settings
  289. AC_SUBST(PACKAGE_CFLAGS)
  290. AC_SUBST(WARNING_CFLAGS)
  291. AC_CONFIG_FILES([Makefile src/Makefile])
  292. AC_OUTPUT
  293. AC_MSG_NOTICE([
  294. Configuration:
  295. Source code location ${srcdir}
  296. Build code location ${builddir}
  297. Destination prefix ${prefix}
  298. Compiler ${CC}
  299. Config GTK version "${with_gtk}"
  300. Config warning flags "${WARNING_CFLAGS}"
  301. Config CFLAGS "${CFLAGS}"
  302. Config LIBS "${LIBS}"
  303. Config GTK_CFLAGS "${GTK_CFLAGS}"
  304. Config GTK_LIBS "${GTK_LIBS}"
  305. ])