configure.ac 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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([gml4gtk], [6.8], [mooigraph@gmail.com], [gml4gtk.tar.gz], [https://sourceforge.net/projects/gml4gtk])
  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. # -pg for use with gprof
  50. # -fcallgraph-info should generate graph data
  51. # using -fno-inline when testing with valgrind
  52. #CFLAGS="$CFLAGS -g -std=c99 -fno-builtin-memset -DFORTIFY_SOURCE=2"
  53. #CFLAGS="$CFLAGS -g -std=c99 -O0"
  54. CFLAGS="-g -std=c99 -O2 "
  55. # Gcc compiler options
  56. # the option -frecord-gcc-switches puts the compiler options
  57. # in the binary ro read with: readelf -p .GCC.command.line a.out
  58. # https://github.com/Barro/compiler-warnings has lists of gcc options
  59. AC_DEFUN([GCC_COMPILER_WARNING],
  60. [AC_MSG_CHECKING(whether compiler accepts $1)
  61. AC_SUBST(WARNING_CFLAGS)
  62. ac_save_CFLAGS="$CFLAGS"
  63. CFLAGS="$CFLAGS $1"
  64. AC_TRY_COMPILE(,
  65. [int x;],
  66. WARNING_CFLAGS="$WARNING_CFLAGS $1"
  67. AC_MSG_RESULT(yes),
  68. AC_MSG_RESULT(no))
  69. CFLAGS="$ac_save_CFLAGS"])
  70. # the fortify -D option needs optimizing, cannot use -O0 then.
  71. # for debug with gdb the -O0 is needed or it cannot find crashes.
  72. # prints gcc settings and include files and is very verbose
  73. # GCC_COMPILER_WARNING(--verbose)
  74. # GCC_COMPILER_WARNING(-H)
  75. AC_ARG_ENABLE(gcc-warnings,
  76. AC_HELP_STRING([--enable-gcc-warnings],
  77. [turn on lots of GCC warnings (not recommended)]),
  78. [case "${enableval}" in
  79. yes|no) ;;
  80. *) AC_MSG_ERROR([unknown value ${enableval} for gcc-warnings option expected yes or no]) ;;
  81. esac],
  82. [enableval=no])
  83. if test "${enableval}" = yes; then
  84. GCC_COMPILER_WARNING(-Werror)
  85. AC_SUBST([WERROR_CFLAGS], [$WARNING_CFLAGS])
  86. WARNING_CFLAGS=
  87. GCC_COMPILER_WARNING(-O0)
  88. GCC_COMPILER_WARNING(-Wall)
  89. GCC_COMPILER_WARNING(-Wextra)
  90. GCC_COMPILER_WARNING(-W)
  91. GCC_COMPILER_WARNING(-Wbad-function-cast)
  92. GCC_COMPILER_WARNING(-Wcast-align)
  93. GCC_COMPILER_WARNING(-ftrapv)
  94. GCC_COMPILER_WARNING(-fno-inlne)
  95. GCC_COMPILER_WARNING(-Wformat)
  96. GCC_COMPILER_WARNING(-Wmissing-declarations)
  97. GCC_COMPILER_WARNING(-Wmissing-prototypes)
  98. GCC_COMPILER_WARNING(-Wnested-externs)
  99. GCC_COMPILER_WARNING(-Wshadow)
  100. GCC_COMPILER_WARNING(-Wstrict-prototypes)
  101. GCC_COMPILER_WARNING(-Woverlength-strings)
  102. GCC_COMPILER_WARNING(-Wformat-nonliteral)
  103. GCC_COMPILER_WARNING(-Wformat-security)
  104. GCC_COMPILER_WARNING(-Winit-self)
  105. GCC_COMPILER_WARNING(-Winline)
  106. GCC_COMPILER_WARNING(-Wmisleading-indentation)
  107. GCC_COMPILER_WARNING(-Wlogical-op)
  108. GCC_COMPILER_WARNING(-Wduplicated-cond)
  109. GCC_COMPILER_WARNING(-Wtautological-compare)
  110. GCC_COMPILER_WARNING(-Wshift-count-negative)
  111. GCC_COMPILER_WARNING(-Wshift-count-overflow)
  112. GCC_COMPILER_WARNING(-Wshift-negative-value)
  113. GCC_COMPILER_WARNING(-Wshift-overflow)
  114. GCC_COMPILER_WARNING(-Wnull-dereference)
  115. GCC_COMPILER_WARNING(-Wnonnull)
  116. GCC_COMPILER_WARNING(-Woverride-init-side-effects)
  117. GCC_COMPILER_WARNING(-Wunused-const-variable)
  118. GCC_COMPILER_WARNING(-Wframe-address)
  119. else
  120. WARNING_CFLAGS=
  121. GCC_COMPILER_WARNING(-Wall)
  122. GCC_COMPILER_WARNING(-Wshadow)
  123. GCC_COMPILER_WARNING(-Wno-overlength-strings)
  124. GCC_COMPILER_WARNING(-pedantic)
  125. GCC_COMPILER_WARNING(-D_FORTIFY_SOURCE=2)
  126. GCC_COMPILER_WARNING(-fstack-protector-strong)
  127. GCC_COMPILER_WARNING(-Wl,-O1)
  128. GCC_COMPILER_WARNING(-frecord-gcc-switches)
  129. GCC_COMPILER_WARNING(-Wpointer-arith)
  130. GCC_COMPILER_WARNING(-fvar-tracking-assignments)
  131. GCC_COMPILER_WARNING(-fcompare-debug)
  132. GCC_COMPILER_WARNING(-flto)
  133. GCC_COMPILER_WARNING(-fwhole-program)
  134. fi
  135. # GCC compiler rtl and tree data generation
  136. # GCC_COMPILER_WARNING(-fdump-lang-all-graph)
  137. # GCC_COMPILER_WARNING(-fdump-rtl-all-graph)
  138. # GCC_COMPILER_WARNING(-fdump-tree-all-graph)
  139. # GCC_COMPILER_WARNING(-fdump-ipa-all-graph)
  140. # GCC_COMPILER_WARNING(-fcallgraph-info)
  141. # Checks for libraries.
  142. AC_CHECK_LIB([m], [sqrt])
  143. # Checks for header files.
  144. AC_CHECK_HEADERS([limits.h stdlib.h stdint.h string.h inttypes.h])
  145. # Checks for typedefs, structures, and compiler characteristics.
  146. # Checks for library functions.
  147. AC_CHECK_FUNCS([memset strdup])
  148. AC_CHECK_SIZEOF([void *])
  149. AC_CHECK_SIZEOF([uintptr_t])
  150. #-------------------------------------------
  151. # Check for math.h include and math library.
  152. # Old distros, use CHECK as a SEARCH backup.
  153. AC_CHECK_HEADER([math.h],
  154. AC_SEARCH_LIBS([cos],[m],[have_libm=yes],
  155. AC_CHECK_LIB([m],[cos],[have_libm=yes])))
  156. if test x"${have_libm}" != xyes; then
  157. AC_MSG_FAILURE([ERROR: Please install Math libraries and math.h include files for libm],[1])
  158. fi
  159. #-------------------------------------------
  160. # Check for C99 hypot. Error if none found.
  161. # Older compilers will have to set/use C99.
  162. AC_CHECK_FUNCS(hypot, ,[AC_MSG_FAILURE([ERROR: hypot() required but not found.],[1])])
  163. #-------------------------------------------
  164. # Check for C99 isfinite or finite. Use one.
  165. math_isfinite=no
  166. math_finite=no
  167. AC_CHECK_FUNCS(isfinite,
  168. [AC_DEFINE(HAVE_ISFINITE, 1)
  169. math_isfinite=true],
  170. [AC_LINK_IFELSE(
  171. [AC_LANG_PROGRAM(
  172. [[#include <math.h>]],
  173. [[double f = 0.0; isfinite(f)]])],
  174. [AC_DEFINE(HAVE_ISFINITE, 1)
  175. math_isfinite=true],
  176. [AC_CHECK_FUNCS(finite,
  177. [AC_DEFINE(HAVE_FINITE, 1)
  178. math_finite=true])])])
  179. if test x"${math_isfinite}" = xno && test x"${math_finite}" = xno; then
  180. AC_MSG_FAILURE([ERROR: isfinite() or finite() required but not found.],[1])
  181. fi
  182. AC_SUBST(HAVE_FINITE)
  183. AC_SUBST(HAVE_ISFINITE)
  184. # default to gtk+-2.0 setting to 1
  185. GTK_HAVE_API_VERSION_2=1
  186. GTK_HAVE_API_VERSION_3=0
  187. GTK_HAVE_API_VERSION_4=0
  188. AC_ARG_ENABLE(gtk2,
  189. [ --enable-gtk2 Use GTK 2.0 in preference to GTK 3.0 [[default=no]]],
  190. [if test "$enableval" = "yes"
  191. then
  192. prefer_gtk2=yes
  193. else
  194. prefer_gtk2=no
  195. fi])
  196. AC_MSG_CHECKING([which gtk+ version to compile against])
  197. AC_ARG_WITH([gtk],
  198. [AS_HELP_STRING([--with-gtk=2.0|3.0|4.0],[which gtk+ version to compile against (default: 3.0)])],
  199. [case "$with_gtk" in
  200. 2.0|3.0|4.0) ;;
  201. *) AC_MSG_ERROR([invalid gtk version specified]) ;;
  202. esac],
  203. [with_gtk=2.0])
  204. AC_MSG_RESULT([$with_gtk])
  205. case "$with_gtk" in
  206. 2.0) GTK_API_VERSION=2.0
  207. GTK_REQUIRED=2.0.0
  208. GTK_HAVE_API_VERSION_2=1
  209. GTK_HAVE_API_VERSION_3=0
  210. GTK_HAVE_API_VERSION_4=0
  211. ;;
  212. 3.0) GTK_API_VERSION=3.0
  213. GTK_REQUIRED=2.91.0
  214. GTK_HAVE_API_VERSION_2=0
  215. GTK_HAVE_API_VERSION_3=1
  216. GTK_HAVE_API_VERSION_4=0
  217. ;;
  218. 4.0) GTK_API_VERSION=4.0
  219. GTK_REQUIRED=3.91.0
  220. GTK_HAVE_API_VERSION_2=0
  221. GTK_HAVE_API_VERSION_3=0
  222. GTK_HAVE_API_VERSION_4=1
  223. ;;
  224. esac
  225. #
  226. AC_SUBST([GTK_API_VERSION])
  227. AC_SUBST([GTK_REQUIRED])
  228. #
  229. AM_CONDITIONAL([HAVE_GTK_2],[test "$with_gtk" = "2.0"])
  230. AM_CONDITIONAL([HAVE_GTK_3],[test "$with_gtk" = "3.0"])
  231. AM_CONDITIONAL([HAVE_GTK_4],[test "$with_gtk" = "4.0"])
  232. #
  233. AC_DEFINE_UNQUOTED([GTK_HAVE_API_VERSION_2], [$GTK_HAVE_API_VERSION_2], [gtk version 2])
  234. AC_DEFINE_UNQUOTED([GTK_HAVE_API_VERSION_3], [$GTK_HAVE_API_VERSION_3], [gtk version 3])
  235. AC_DEFINE_UNQUOTED([GTK_HAVE_API_VERSION_4], [$GTK_HAVE_API_VERSION_4], [gtk version 4])
  236. # Preliminary check for pkg-config
  237. if test -z "$PKG_CONFIG"; then
  238. AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
  239. fi
  240. if test "$PKG_CONFIG" = "no" ; then
  241. echo "
  242. Please install pkg-config and then reconfigure mooigraph.
  243. pkg-config is available from http://www.freedesktop.org/
  244. "
  245. exit 1
  246. fi
  247. # glib 2.0 (needed even if not building GUI; we need 2.14 for regexp functions)
  248. PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.14.0, have_glib2="yes", have_glib2="no")
  249. if test "${have_glib2}" = "no" ; then
  250. echo "
  251. Please install glib-2.0 >= 2.14.0 and then reconfigure mooigraph.
  252. glib-2.0 is available from http://www.gtk.org/
  253. "
  254. exit 1
  255. fi
  256. # Initial check for GTK availability
  257. if test "$prefer_gtk2" = "yes" ; then
  258. PKG_CHECK_MODULES(GTK2, gtk+-2.0 >= 2.14.0,
  259. GTK_CFLAGS=$GTK2_CFLAGS
  260. GTK_LIBS=$GTK2_LIBS
  261. CFLAGS="$CFLAGS $GTK_CFLAGS"
  262. LIBS="$LIBS $GTK_LIBS"
  263. gtk_version="2.0",
  264. echo "GTK 2 >= 2.14.0 not found"
  265. )
  266. elif test "$prefer_gtk2" = "no" ; then
  267. PKG_CHECK_MODULES(GTK3, gtk+-3.0 >= 3.0.1,
  268. GTK_CFLAGS=$GTK3_CFLAGS
  269. GTK_LIBS=$GTK3_LIBS
  270. CFLAGS="$CFLAGS $GTK_CFLAGS"
  271. LIBS="$LIBS $GTK_LIBS"
  272. dnl AC_DEFINE(USE_GTK3)
  273. gtk_version="3.0"
  274. fake_gtkspinner="no",
  275. echo "GTK 3 >= 3.0.1 not found"
  276. )
  277. fi
  278. dnl GTK 2.0 fallback in case preference not given
  279. if test "$prefer_gtk2" = "no" && test "$gtk_version" = "none" ; then
  280. PKG_CHECK_MODULES(GTK2, gtk+-2.0 >= 2.14.0,
  281. GTK_CFLAGS=$GTK2_CFLAGS
  282. GTK_LIBS=$GTK2_LIBS
  283. CFLAGS="$CFLAGS $GTK_CFLAGS"
  284. LIBS="$LIBS $GTK_LIBS"
  285. gtk_version="2.0",
  286. build_gui="no"
  287. echo "GTK 2 >= 2.14.0 not found"
  288. )
  289. fi
  290. #
  291. PKG_CHECK_MODULES(GTK, gtk+-$GTK_API_VERSION >= $GTK_REQUIRED)
  292. AC_SUBST(GTK_CFLAGS)
  293. AC_SUBST(GTK_LIBS)
  294. # final compiler settings
  295. AC_SUBST(PACKAGE_CFLAGS)
  296. # final compiler settings
  297. AC_SUBST(PACKAGE_CFLAGS)
  298. AC_SUBST(WARNING_CFLAGS)
  299. AC_CONFIG_FILES([Makefile src/Makefile])
  300. AC_OUTPUT
  301. AC_MSG_NOTICE([
  302. Configuration:
  303. Source code location ${srcdir}
  304. Build code location ${builddir}
  305. Destination prefix ${prefix}
  306. Compiler ${CC}
  307. Config GTK version "${with_gtk}"
  308. Config warning flags "${WARNING_CFLAGS}"
  309. Config CFLAGS "${CFLAGS}"
  310. Config LIBS "${LIBS}"
  311. Config GTK_CFLAGS "${GTK_CFLAGS}"
  312. Config GTK_LIBS "${GTK_LIBS}"
  313. ])