configure.ac 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. #
  2. # /*
  3. # * Copyright 2021
  4. # *
  5. # * This program is free software: you can redistribute it and/or modify
  6. # * it under the terms of the GNU General Public License as published by
  7. # * the Free Software Foundation, either version 3 of the License, or
  8. # * (at your option) any later version.
  9. # *
  10. # * This program is distributed in the hope that it will be useful,
  11. # * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # * GNU General Public License for more details.
  14. # *
  15. # * You should have received a copy of the GNU General Public License
  16. # * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. # *
  18. # * SPDX-License-Identifier: GPL-3.0+
  19. # * License-Filename: LICENSE
  20. # *
  21. # */
  22. #
  23. # -*- Autoconf -*-
  24. # Process this file with autoconf to produce a configure script.
  25. # Macro: AC_INIT (package, version, [bug-report], [tarname], [url])
  26. # minor version number is increased at important feature change
  27. # Process with autogen.sh or manual:
  28. # aclocal
  29. # autoheader
  30. # autoconf
  31. # libtoolize --force --automake
  32. # automake -a --gnu --include-deps
  33. # or do this all using autoreconf -fvim
  34. #
  35. # test also using scan-build from llvm clang tools
  36. #
  37. AC_PREREQ([2.69])
  38. AC_INIT([gml4gtk], [7.4], [mooigraph@gmail.com], [gml4gtk.tar.gz], [https://sourceforge.net/projects/gml4gtk])
  39. AC_CONFIG_SRCDIR([src/main.h])
  40. AC_CONFIG_HEADERS([config.h])
  41. AM_INIT_AUTOMAKE
  42. AC_COPYRIGHT([
  43. # /*
  44. # * This program is free software: you can redistribute it and/or modify
  45. # * it under the terms of the GNU General Public License as published by
  46. # * the Free Software Foundation, either version 3 of the License, or
  47. # * (at your option) any later version.
  48. # *
  49. # * This program is distributed in the hope that it will be useful,
  50. # * but WITHOUT ANY WARRANTY; without even the implied warranty of
  51. # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  52. # * GNU General Public License for more details.
  53. # *
  54. # * You should have received a copy of the GNU General Public License
  55. # * along with this program. If not, see <http://www.gnu.org/licenses/>.
  56. # *
  57. # * SPDX-License-Identifier: GPL-3.0+
  58. # * License-Filename: LICENSE
  59. # *
  60. # */
  61. ])
  62. AC_LANG(C)
  63. # Checks for programs.
  64. AC_PROG_CC
  65. AC_PROG_MAKE_SET
  66. # -DFORTIFY_SOURCE=2 does add glibc extra checks, see RedHat documentation
  67. # Need c11 mode because of %llu in printf() and (long long int) datatype and unnamed unions
  68. # Upcoming c standard is c17 using GNU GCC -std=c17
  69. # or CFLAGS="$CFLAGS ..."
  70. # do not optimize away memset()
  71. #CFLAGS="$CFLAGS -g -std=c99 -fno-builtin-memset -DFORTIFY_SOURCE=2 -fdump-rtl-expand-graph"
  72. # -pg for use with gprof
  73. # -fcallgraph-info should generate graph data
  74. # using -fno-inline when testing with valgrind
  75. #CFLAGS="$CFLAGS -g -std=c99 -fno-builtin-memset -DFORTIFY_SOURCE=2"
  76. #CFLAGS="$CFLAGS -g -std=c99 -O0"
  77. # asm output: -S -fverbose-asm
  78. # asm output: -Wa,-adhln=test-O3.s -g -fverbose-asm -masm=intel
  79. # asm output: -fverbose-asm -save-temps=obj
  80. # -fplugin=$HOME/scallgraph_plugin.so.0.0.0
  81. CFLAGS="$CFLAGS -g -std=c99 "
  82. # Gcc compiler options
  83. # the option -frecord-gcc-switches puts the compiler options
  84. # in the binary ro read with: readelf -p .GCC.command.line a.out
  85. # https://github.com/Barro/compiler-warnings has lists of gcc options
  86. AC_DEFUN([GCC_COMPILER_WARNING],
  87. [AC_MSG_CHECKING(whether compiler accepts $1)
  88. AC_SUBST(WARNING_CFLAGS)
  89. ac_save_CFLAGS="$CFLAGS"
  90. CFLAGS="$CFLAGS $1"
  91. AC_TRY_COMPILE(,
  92. [int x;],
  93. WARNING_CFLAGS="$WARNING_CFLAGS $1"
  94. AC_MSG_RESULT(yes),
  95. AC_MSG_RESULT(no))
  96. CFLAGS="$ac_save_CFLAGS"])
  97. # the fortify -D option needs optimizing, cannot use -O0 then.
  98. # for debug with gdb the -O0 is needed or it cannot find crashes.
  99. # prints gcc settings and include files and is very verbose
  100. # when extra warnings are enabled then -DMEMCHECK is set
  101. # extra code in dpmem.c starts checking for memory leaks.
  102. # GCC_COMPILER_WARNING(--verbose)
  103. # GCC_COMPILER_WARNING(-H)
  104. AC_ARG_ENABLE(gcc-warnings,
  105. AC_HELP_STRING([--enable-gcc-warnings],
  106. [turn on lots of GCC warnings (not recommended)]),
  107. [case "${enableval}" in
  108. yes|no) ;;
  109. *) AC_MSG_ERROR([unknown value ${enableval} for gcc-warnings option expected yes or no]) ;;
  110. esac],
  111. [enableval=no])
  112. if test "${enableval}" = yes; then
  113. GCC_COMPILER_WARNING(-Werror)
  114. AC_SUBST([WERROR_CFLAGS], [$WARNING_CFLAGS])
  115. WARNING_CFLAGS=
  116. GCC_COMPILER_WARNING(-O0)
  117. GCC_COMPILER_WARNING(-Wall)
  118. GCC_COMPILER_WARNING(-Wextra)
  119. GCC_COMPILER_WARNING(-W)
  120. GCC_COMPILER_WARNING(-Wbad-function-cast)
  121. GCC_COMPILER_WARNING(-Wcast-align)
  122. GCC_COMPILER_WARNING(-ftrapv)
  123. GCC_COMPILER_WARNING(-fno-inlne)
  124. GCC_COMPILER_WARNING(-Wformat)
  125. GCC_COMPILER_WARNING(-Wmissing-declarations)
  126. GCC_COMPILER_WARNING(-Wmissing-prototypes)
  127. GCC_COMPILER_WARNING(-Wnested-externs)
  128. GCC_COMPILER_WARNING(-Wshadow)
  129. GCC_COMPILER_WARNING(-Wstrict-prototypes)
  130. GCC_COMPILER_WARNING(-Woverlength-strings)
  131. GCC_COMPILER_WARNING(-Wformat-nonliteral)
  132. GCC_COMPILER_WARNING(-Wformat-security)
  133. GCC_COMPILER_WARNING(-Winit-self)
  134. GCC_COMPILER_WARNING(-Winline)
  135. GCC_COMPILER_WARNING(-Wmisleading-indentation)
  136. GCC_COMPILER_WARNING(-Wlogical-op)
  137. GCC_COMPILER_WARNING(-Wduplicated-cond)
  138. GCC_COMPILER_WARNING(-Wtautological-compare)
  139. GCC_COMPILER_WARNING(-Wshift-count-negative)
  140. GCC_COMPILER_WARNING(-Wshift-count-overflow)
  141. GCC_COMPILER_WARNING(-Wshift-negative-value)
  142. GCC_COMPILER_WARNING(-Wshift-overflow)
  143. GCC_COMPILER_WARNING(-Wnull-dereference)
  144. GCC_COMPILER_WARNING(-Wnonnull)
  145. GCC_COMPILER_WARNING(-Woverride-init-side-effects)
  146. GCC_COMPILER_WARNING(-Wunused-const-variable)
  147. GCC_COMPILER_WARNING(-Wframe-address)
  148. GCC_COMPILER_WARNING(-ftrack-macro-expansion=1)
  149. GCC_COMPILER_WARNING(-DMEMCHECK)
  150. else
  151. WARNING_CFLAGS=
  152. GCC_COMPILER_WARNING(-Wall)
  153. GCC_COMPILER_WARNING(-Wshadow)
  154. GCC_COMPILER_WARNING(-Wno-overlength-strings)
  155. GCC_COMPILER_WARNING(-pedantic)
  156. GCC_COMPILER_WARNING(-D_FORTIFY_SOURCE=2)
  157. GCC_COMPILER_WARNING(-fstack-protector-strong)
  158. GCC_COMPILER_WARNING(-Wl,-O1)
  159. GCC_COMPILER_WARNING(-frecord-gcc-switches)
  160. GCC_COMPILER_WARNING(-Wpointer-arith)
  161. GCC_COMPILER_WARNING(-fvar-tracking-assignments)
  162. GCC_COMPILER_WARNING(-fcompare-debug)
  163. GCC_COMPILER_WARNING(-flto)
  164. GCC_COMPILER_WARNING(-fwhole-program)
  165. fi
  166. # GCC compiler rtl and tree data generation
  167. # GCC_COMPILER_WARNING(-fdump-lang-all-graph)
  168. # GCC_COMPILER_WARNING(-fdump-rtl-all-graph)
  169. # GCC_COMPILER_WARNING(-fdump-tree-all-graph)
  170. # GCC_COMPILER_WARNING(-fdump-ipa-all-graph)
  171. # GCC_COMPILER_WARNING(-fcallgraph-info)
  172. #? AC_INCLUDE_DEFAULTS([stdio.h math.h])
  173. # Checks for libraries.
  174. AC_CHECK_LIB([m], [sqrt])
  175. # Checks for header files.
  176. AC_CHECK_HEADERS([limits.h stdlib.h stdint.h string.h inttypes.h])
  177. # Checks for typedefs, structures, and compiler characteristics.
  178. # Checks for library functions.
  179. AC_CHECK_FUNCS([memset strdup])
  180. AC_CHECK_SIZEOF([void *])
  181. AC_CHECK_SIZEOF([uintptr_t])
  182. #-------------------------------------------
  183. # Check for math.h include and math library.
  184. # Old distros, use CHECK as a SEARCH backup.
  185. AC_CHECK_HEADER([math.h],
  186. AC_SEARCH_LIBS([cos],[m],[have_libm=yes],
  187. AC_CHECK_LIB([m],[cos],[have_libm=yes])))
  188. if test x"${have_libm}" != xyes; then
  189. AC_MSG_FAILURE([gml4gtk-configure.ac-ERROR: Please install Math libraries and math.h include files for libm],[1])
  190. fi
  191. #-------------------------------------------
  192. # Check for C99 hypot. Error if none found.
  193. # Older compilers will have to set/use C99.
  194. AC_CHECK_FUNCS(hypot, ,[AC_MSG_FAILURE([ERROR: hypot() required but not found.],[1])])
  195. #-------------------------------------------
  196. # Check for C99 isfinite or finite. Use one.
  197. math_isfinite=no
  198. math_finite=no
  199. AC_CHECK_FUNCS(isfinite,
  200. [AC_DEFINE(HAVE_ISFINITE, 1)
  201. math_isfinite=true],
  202. [AC_LINK_IFELSE(
  203. [AC_LANG_PROGRAM(
  204. [[#include <math.h>]],
  205. [[double f = 0.0; isfinite(f)]])],
  206. [AC_DEFINE(HAVE_ISFINITE, 1)
  207. math_isfinite=true],
  208. [AC_CHECK_FUNCS(finite,
  209. [AC_DEFINE(HAVE_FINITE, 1)
  210. math_finite=true])])])
  211. if test x"${math_isfinite}" = xno && test x"${math_finite}" = xno; then
  212. AC_MSG_FAILURE([ERROR: isfinite() or finite() required but not found.],[1])
  213. fi
  214. AC_SUBST(HAVE_FINITE)
  215. AC_SUBST(HAVE_ISFINITE)
  216. # default to gtk+-2.0 setting to 1
  217. GTK_HAVE_API_VERSION_0=0
  218. GTK_HAVE_API_VERSION_1=0
  219. GTK_HAVE_API_VERSION_2=0
  220. GTK_HAVE_API_VERSION_3=1
  221. GTK_HAVE_API_VERSION_4=0
  222. AC_ARG_ENABLE(gtk2,
  223. [ --enable-gtk2 Use GTK 2.0 in preference to GTK 3.0 [[default=no]]],
  224. [if test "$enableval" = "yes"
  225. then
  226. prefer_gtk2=yes
  227. else
  228. prefer_gtk2=no
  229. fi])
  230. AC_MSG_CHECKING([which gtk+ version to compile against])
  231. # set [with_gtk=0.0] to default for gtk-0
  232. # set [with_gtk=1.0] to default for gtk-1
  233. # set [with_gtk=2.0] to default for gtk-2
  234. # set [with_gtk=3.0] to default for gtk-3
  235. # set [with_gtk=4.0] to default for gtk-4
  236. AC_ARG_WITH([gtk],
  237. [AS_HELP_STRING([--with-gtk=0.0|1.0|2.0|3.0|4.0],[which gtk+ version to compile against (default: 3.0)])],
  238. [case "$with_gtk" in
  239. 0.0|1.0|2.0|3.0|4.0) ;;
  240. *) AC_MSG_ERROR([invalid gtk version specified]) ;;
  241. esac],
  242. [with_gtk=3.0])
  243. AC_MSG_RESULT([$with_gtk])
  244. case "$with_gtk" in
  245. 0.0) GTK_API_VERSION=0.0
  246. GTK_REQUIRED=0.0.0
  247. GTK_HAVE_API_VERSION_0=1
  248. GTK_HAVE_API_VERSION_1=0
  249. GTK_HAVE_API_VERSION_2=0
  250. GTK_HAVE_API_VERSION_3=0
  251. GTK_HAVE_API_VERSION_4=0
  252. ;;
  253. 1.0) GTK_API_VERSION=1.0
  254. GTK_REQUIRED=1.0.0
  255. GTK_HAVE_API_VERSION_0=0
  256. GTK_HAVE_API_VERSION_1=1
  257. GTK_HAVE_API_VERSION_2=0
  258. GTK_HAVE_API_VERSION_3=0
  259. GTK_HAVE_API_VERSION_4=0
  260. ;;
  261. 2.0) GTK_API_VERSION=2.0
  262. GTK_REQUIRED=2.0.0
  263. GTK_HAVE_API_VERSION_0=0
  264. GTK_HAVE_API_VERSION_1=0
  265. GTK_HAVE_API_VERSION_2=1
  266. GTK_HAVE_API_VERSION_3=0
  267. GTK_HAVE_API_VERSION_4=0
  268. ;;
  269. 3.0) GTK_API_VERSION=3.0
  270. GTK_REQUIRED=2.91.0
  271. GTK_HAVE_API_VERSION_0=0
  272. GTK_HAVE_API_VERSION_1=0
  273. GTK_HAVE_API_VERSION_2=0
  274. GTK_HAVE_API_VERSION_3=1
  275. GTK_HAVE_API_VERSION_4=0
  276. ;;
  277. 4.0) GTK_API_VERSION=4.0
  278. GTK_REQUIRED=3.91.0
  279. GTK_HAVE_API_VERSION_0=0
  280. GTK_HAVE_API_VERSION_1=0
  281. GTK_HAVE_API_VERSION_2=0
  282. GTK_HAVE_API_VERSION_3=0
  283. GTK_HAVE_API_VERSION_4=1
  284. ;;
  285. esac
  286. #
  287. AC_SUBST([GTK_API_VERSION])
  288. AC_SUBST([GTK_REQUIRED])
  289. #
  290. AM_CONDITIONAL([HAVE_GTK_0],[test "$with_gtk" = "0.0"])
  291. AM_CONDITIONAL([HAVE_GTK_1],[test "$with_gtk" = "1.0"])
  292. AM_CONDITIONAL([HAVE_GTK_2],[test "$with_gtk" = "2.0"])
  293. AM_CONDITIONAL([HAVE_GTK_3],[test "$with_gtk" = "3.0"])
  294. AM_CONDITIONAL([HAVE_GTK_4],[test "$with_gtk" = "4.0"])
  295. #
  296. AC_DEFINE_UNQUOTED([GTK_HAVE_API_VERSION_0], [$GTK_HAVE_API_VERSION_0], [gtk version 0])
  297. AC_DEFINE_UNQUOTED([GTK_HAVE_API_VERSION_1], [$GTK_HAVE_API_VERSION_1], [gtk version 1])
  298. AC_DEFINE_UNQUOTED([GTK_HAVE_API_VERSION_2], [$GTK_HAVE_API_VERSION_2], [gtk version 2])
  299. AC_DEFINE_UNQUOTED([GTK_HAVE_API_VERSION_3], [$GTK_HAVE_API_VERSION_3], [gtk version 3])
  300. AC_DEFINE_UNQUOTED([GTK_HAVE_API_VERSION_4], [$GTK_HAVE_API_VERSION_4], [gtk version 4])
  301. # Preliminary check for pkg-config
  302. if test -z "$PKG_CONFIG"; then
  303. AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
  304. fi
  305. if test "$PKG_CONFIG" = "no" ; then
  306. echo "
  307. Please install pkg-config and then reconfigure mooigraph.
  308. pkg-config is available from http://www.freedesktop.org/
  309. "
  310. exit 1
  311. fi
  312. # glib 2.0 (needed even if not building GUI; we need 2.14 for regexp functions)
  313. PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.14.0, have_glib2="yes", have_glib2="no")
  314. if test "${have_glib2}" = "no" ; then
  315. echo "
  316. Please install glib-2.0 >= 2.14.0 and then reconfigure mooigraph.
  317. glib-2.0 is available from http://www.gtk.org/
  318. "
  319. exit 1
  320. fi
  321. # Initial check for GTK availability
  322. if test "$prefer_gtk2" = "yes" ; then
  323. PKG_CHECK_MODULES(GTK2, gtk+-2.0 >= 2.14.0,
  324. GTK_CFLAGS=$GTK2_CFLAGS
  325. GTK_LIBS=$GTK2_LIBS
  326. CFLAGS="$CFLAGS $GTK_CFLAGS"
  327. LIBS="$LIBS $GTK_LIBS"
  328. gtk_version="2.0",
  329. echo "GTK 2 >= 2.14.0 not found"
  330. )
  331. elif test "$prefer_gtk2" = "no" ; then
  332. PKG_CHECK_MODULES(GTK3, gtk+-3.0 >= 3.0.1,
  333. GTK_CFLAGS=$GTK3_CFLAGS
  334. GTK_LIBS=$GTK3_LIBS
  335. CFLAGS="$CFLAGS $GTK_CFLAGS"
  336. LIBS="$LIBS $GTK_LIBS"
  337. gtk_version="3.0"
  338. fake_gtkspinner="no",
  339. echo "GTK 3 >= 3.0.1 not found"
  340. )
  341. fi
  342. dnl GTK 2.0 fallback in case preference not given
  343. if test "$prefer_gtk2" = "no" && test "$gtk_version" = "none" ; then
  344. PKG_CHECK_MODULES(GTK2, gtk+-2.0 >= 2.14.0,
  345. GTK_CFLAGS=$GTK2_CFLAGS
  346. GTK_LIBS=$GTK2_LIBS
  347. CFLAGS="$CFLAGS $GTK_CFLAGS"
  348. LIBS="$LIBS $GTK_LIBS"
  349. gtk_version="2.0",
  350. build_gui="no"
  351. echo "GTK 2 >= 2.14.0 not found"
  352. )
  353. fi
  354. dnl Detect Win32 compiler
  355. AC_MSG_CHECKING([for some Win32 platform])
  356. case "$host" in
  357. *-*-mingw*|*-*-cygwin*)
  358. platform_win32=yes
  359. HAVE_PLATFORM_WIN32=1
  360. ;;
  361. *)
  362. platform_win32=no
  363. HAVE_PLATFORM_WIN32=0
  364. ;;
  365. esac
  366. AC_MSG_RESULT([$platform_win32])
  367. AM_CONDITIONAL(PLATFORM_WIN32, test "$platform_win32" = "yes")
  368. AC_SUBST([PLATFORM_WIN32])
  369. AC_DEFINE_UNQUOTED([PLATFORM_WIN32], [$HAVE_PLATFORM_WIN32], [using a windows compiler])
  370. # compilation date in config.h
  371. # CONFIG_DATE=`date +"%a %x %Y"`
  372. CONFIG_DATE=`date +"%a %d %b %Y"`
  373. AC_SUBST(CONFIG_DATE)
  374. AC_DEFINE_UNQUOTED(COMPILE_DATE, ["$CONFIG_DATE"], [Year, month and day this program is compiled.])
  375. # short system name in config.h
  376. CONFIG_UNAME=`uname -s`
  377. AC_SUBST(CONFIG_UNAME)
  378. AC_DEFINE_UNQUOTED(COMPILE_UNAME, ["$CONFIG_UNAME"], [System where this is compiled.])
  379. #
  380. PKG_CHECK_MODULES(GTK, gtk+-$GTK_API_VERSION >= $GTK_REQUIRED)
  381. AC_SUBST(GTK_CFLAGS)
  382. AC_SUBST(GTK_LIBS)
  383. # final compiler settings
  384. AC_SUBST(PACKAGE_CFLAGS)
  385. AC_SUBST(WARNING_CFLAGS)
  386. AC_CONFIG_FILES([Makefile src/Makefile])
  387. AC_OUTPUT
  388. echo " "
  389. echo " "
  390. echo " "
  391. echo " , , "
  392. echo " / \ "
  393. echo " ((__-^^-,-^^-__)) "
  394. echo " '-__- - '--__- "
  395. echo " -O O- "
  396. echo " \ / "
  397. echo " ): :( "
  398. echo " :o_o: "
  399. echo " - "
  400. echo " "
  401. echo " "
  402. echo " "
  403. echo This system is `uname -a`;
  404. cat <<EOF
  405. $PACKAGE_NAME $VERSION is ready to be built.
  406. The following settings will be used:
  407. Use "make" to compile $PACKAGE_NAME $VERSION.
  408. use ./configure --with-gtk=0.0 for gtk-0
  409. use ./configure --with-gtk=1.0 for gtk-1
  410. use ./configure --with-gtk=2.0 for gtk-2
  411. use ./configure --with-gtk=3.0 for gtk-3
  412. use ./configure --with-gtk=4.0 for gtk-4
  413. use ./configure --enable-gcc-warnings to enable gcc warnings and checks
  414. EOF
  415. AC_MSG_NOTICE([
  416. Configuration:
  417. Source code location ${srcdir}
  418. Build code location ${builddir}
  419. Destination prefix ${prefix}
  420. C-Compiler ${CC}
  421. Config GTK version "${with_gtk}"
  422. Config warning flags "${WARNING_CFLAGS}"
  423. Config CFLAGS "${CFLAGS}"
  424. Config LIBS "${LIBS}"
  425. Config GTK_CFLAGS "${GTK_CFLAGS}"
  426. Config GTK_LIBS "${GTK_LIBS}"
  427. Config PACKAGE_CFLAGS "$PACKAGE_CFLAGS"
  428. Config PLATFORM_WIN32 "$platform_win32"
  429. Config COMPILE_DATE "$CONFIG_DATE"
  430. Config COMPILE_UNAME "$CONFIG_UNAME"
  431. ])