configure.ac 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  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. # Macro: AC_INIT (package, version, [bug-report], [tarname], [url])
  22. # minor version number is increased at important feature change
  23. # Process with autogen.sh or manual:
  24. # aclocal
  25. # autoheader
  26. # autoconf
  27. # libtoolize --force --automake
  28. # automake -a --gnu --include-deps
  29. # or do this all using autoreconf
  30. # This needs GCC in c11 mode because of printf(), and stdint.h uint64_t
  31. #
  32. AC_PREREQ([2.69])
  33. AC_INIT([tuxsee], [8.0], [mooigraph@gmail.com], [tuxsee.tar.gz], [https://notabug.org/mooigraph])
  34. AC_CONFIG_SRCDIR([src/main.c])
  35. AC_CONFIG_HEADERS([config.h])
  36. AC_COPYRIGHT([
  37. # /*
  38. # * This program is free software: you can redistribute it and/or modify
  39. # * it under the terms of the GNU General Public License as published by
  40. # * the Free Software Foundation, either version 3 of the License, or
  41. # * (at your option) any later version.
  42. # *
  43. # * This program is distributed in the hope that it will be useful,
  44. # * but WITHOUT ANY WARRANTY; without even the implied warranty of
  45. # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  46. # * GNU General Public License for more details.
  47. # *
  48. # * You should have received a copy of the GNU General Public License
  49. # * along with this program. If not, see <http://www.gnu.org/licenses/>.
  50. # *
  51. # * SPDX-License-Identifier: GPL-3.0+
  52. # * License-Filename: LICENSE
  53. # *
  54. # */
  55. ])
  56. # optional gcc option can be like this AM_INIT_AUTOMAKE([-Wall])
  57. AM_INIT_AUTOMAKE
  58. AC_CONFIG_MACRO_DIR([m4])
  59. AC_USE_SYSTEM_EXTENSIONS
  60. # compilation date in config.h
  61. CONFIG_DATE=`date +%Y%m%d`
  62. AC_SUBST(CONFIG_DATE)
  63. AC_DEFINE_UNQUOTED(COMPILE_DATE, ["$CONFIG_DATE"], [Year, month and day this program is compiled.])
  64. # Add host to config.h
  65. AC_DEFINE_UNQUOTED(USED_HOST, ["$host"], [Host system under which the program will run.])
  66. AC_DEFINE_UNQUOTED(USED_BUILD, ["$build"], [Build system under which the program was compiled on.])
  67. # needed to support older automake versions
  68. AC_SUBST(abs_top_builddir)
  69. AC_SUBST(abs_top_srcdir)
  70. AC_LANG(C)
  71. # Checks for programs.
  72. AC_PROG_CC
  73. AC_PROG_MAKE_SET
  74. AC_PROG_RANLIB
  75. AM_PROG_CC_C_O
  76. # -DFORTIFY_SOURCE=2 does add glibc extra checks, see RedHat documentation
  77. # Need c11 mode because of %llu in printf() and (long long int) datatype and unnamed unions
  78. # Upcoming c standard is c17 using GNU GCC -std=c17
  79. # or CFLAGS="$CFLAGS ..."
  80. # do not optimize away memset()
  81. CFLAGS="$CFLAGS -g -std=c11 -fno-builtin-memset -DFORTIFY_SOURCE=2"
  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. # GCC_COMPILER_WARNING(--verbose)
  101. # GCC_COMPILER_WARNING(-H)
  102. AC_ARG_ENABLE(gcc-warnings,
  103. AC_HELP_STRING([--enable-gcc-warnings],
  104. [turn on lots of GCC warnings (not recommended)]),
  105. [case "${enableval}" in
  106. yes|no) ;;
  107. *) AC_MSG_ERROR([unknown value ${enableval} for gcc-warnings option expected yes or no]) ;;
  108. esac],
  109. [enableval=no])
  110. if test "${enableval}" = yes; then
  111. GCC_COMPILER_WARNING(-Werror)
  112. AC_SUBST([WERROR_CFLAGS], [$WARNING_CFLAGS])
  113. WARNING_CFLAGS=
  114. GCC_COMPILER_WARNING(-O0)
  115. GCC_COMPILER_WARNING(-Wall)
  116. GCC_COMPILER_WARNING(-Wextra)
  117. GCC_COMPILER_WARNING(-W)
  118. GCC_COMPILER_WARNING(-Wbad-function-cast)
  119. GCC_COMPILER_WARNING(-Wcast-align)
  120. GCC_COMPILER_WARNING(-ftrapv)
  121. GCC_COMPILER_WARNING(-Wformat)
  122. GCC_COMPILER_WARNING(-Wmissing-declarations)
  123. GCC_COMPILER_WARNING(-Wmissing-prototypes)
  124. GCC_COMPILER_WARNING(-Wnested-externs)
  125. GCC_COMPILER_WARNING(-Wshadow)
  126. GCC_COMPILER_WARNING(-Wstrict-prototypes)
  127. GCC_COMPILER_WARNING(-Woverlength-strings)
  128. GCC_COMPILER_WARNING(-Wformat-nonliteral)
  129. GCC_COMPILER_WARNING(-Wformat-security)
  130. GCC_COMPILER_WARNING(-Winit-self)
  131. GCC_COMPILER_WARNING(-Winline)
  132. GCC_COMPILER_WARNING(-Wmisleading-indentation)
  133. GCC_COMPILER_WARNING(-Wlogical-op)
  134. GCC_COMPILER_WARNING(-Wduplicated-cond)
  135. GCC_COMPILER_WARNING(-Wtautological-compare)
  136. GCC_COMPILER_WARNING(-Wshift-count-negative)
  137. GCC_COMPILER_WARNING(-Wshift-count-overflow)
  138. GCC_COMPILER_WARNING(-Wshift-negative-value)
  139. GCC_COMPILER_WARNING(-Wshift-overflow)
  140. GCC_COMPILER_WARNING(-Wnull-dereference)
  141. GCC_COMPILER_WARNING(-Wnonnull)
  142. GCC_COMPILER_WARNING(-Woverride-init-side-effects)
  143. GCC_COMPILER_WARNING(-Wunused-const-variable)
  144. GCC_COMPILER_WARNING(-Wframe-address)
  145. GCC_COMPILER_WARNING(-Wtype-limits)
  146. else
  147. WARNING_CFLAGS=
  148. GCC_COMPILER_WARNING(-Wall)
  149. GCC_COMPILER_WARNING(-Wshadow)
  150. GCC_COMPILER_WARNING(-Wno-overlength-strings)
  151. GCC_COMPILER_WARNING(-D_FORTIFY_SOURCE=2)
  152. GCC_COMPILER_WARNING(-fstack-protector-strong)
  153. GCC_COMPILER_WARNING(-Wl,-O1)
  154. GCC_COMPILER_WARNING(-frecord-gcc-switches)
  155. GCC_COMPILER_WARNING(-grecord-gcc-switches)
  156. GCC_COMPILER_WARNING(-Wpointer-arith)
  157. GCC_COMPILER_WARNING(-fvar-tracking-assignments)
  158. GCC_COMPILER_WARNING(-fcompare-debug)
  159. GCC_COMPILER_WARNING(-flto)
  160. GCC_COMPILER_WARNING(-fwhole-program)
  161. fi
  162. # GCC compiler rtl and tree data generation
  163. # GCC_COMPILER_WARNING(-fdump-rtl-all-graph)
  164. # GCC_COMPILER_WARNING(-fdump-tree-all-graph)
  165. AC_ARG_ENABLE(crosswin32,
  166. AC_HELP_STRING([--enable-crosswin32],
  167. [cross-compile on GNU/Linux with mingw a 32bits windows exe]),
  168. [case "${enableval}" in
  169. yes|no) ;;
  170. *) AC_MSG_ERROR([bad value ${enableval} for crosswin32 option]) ;;
  171. esac],
  172. [enableval=no])
  173. if test "${enableval}" = yes; then
  174. # cross compile
  175. CC="i686-w64-mingw32-gcc"
  176. AC_MSG_RESULT(yes cross compilation)
  177. else
  178. # linux compile
  179. AC_MSG_RESULT(no cross compilation)
  180. fi
  181. # we want to avoid tests in case we're crosscompiling
  182. # since we wouldn't be able to run the executable in that case
  183. AM_CONDITIONAL(NO_CROSSCOMPILING, test "$cross_compiling" = no )
  184. # Checks for libraries.
  185. AC_CHECK_LIB([m], [sqrt])
  186. # Checks for header files.
  187. AC_CHECK_HEADERS([limits.h stdlib.h stdint.h string.h inttypes.h])
  188. # Checks for typedefs, structures, and compiler characteristics.
  189. AC_TYPE_SIZE_T
  190. AC_TYPE_UID_T
  191. AC_CHECK_SIZEOF(char)
  192. AC_CHECK_SIZEOF(short)
  193. AC_CHECK_SIZEOF(long)
  194. AC_CHECK_SIZEOF(int)
  195. AC_CHECK_SIZEOF(void *)
  196. AC_CHECK_SIZEOF(char *)
  197. #AC_CHECK_SIZEOF(size_t) mingw issue
  198. AC_CHECK_SIZEOF(ssize_t)
  199. AC_CHECK_SIZEOF(long long)
  200. AC_CHECK_SIZEOF(__int64)
  201. AC_CHECK_SIZEOF(int64_t)
  202. AC_CHECK_SIZEOF(__int128)
  203. # Checks for library functions.
  204. AC_FUNC_MALLOC
  205. AC_FUNC_REALLOC
  206. AC_CHECK_FUNCS(memset memset_s mtrace strdup)
  207. # Joystick plugin
  208. AC_ARG_ENABLE(joystick,
  209. [ --enable-joystick joystick control (default enabled)])
  210. if test "${enable_joystick}" = "yes"; then
  211. AC_CHECK_HEADER(linux/joystick.h)
  212. fi
  213. # prepare for gtk-4.0 here
  214. # default to gtk+-2.0 setting to 1
  215. GTK_HAVE_API_VERSION_2=0
  216. GTK_HAVE_API_VERSION_3=1
  217. GTK_HAVE_API_VERSION_4=0
  218. AC_ARG_ENABLE(gtk2,
  219. [ --enable-gtk2 Use GTK 2.0 in preference to GTK 3.0 [[default=no]]],
  220. [if test "$enableval" = "yes"
  221. then
  222. prefer_gtk2=yes
  223. else
  224. prefer_gtk2=no
  225. fi])
  226. AC_MSG_CHECKING([which gtk+ version to compile against])
  227. AC_ARG_WITH([gtk],
  228. [AS_HELP_STRING([--with-gtk=2.0|3.0|4.0],[which gtk+ version to compile against (default: 3.0)])],
  229. [case "$with_gtk" in
  230. 2.0|3.0|4.0) ;;
  231. *) AC_MSG_ERROR([invalid gtk version specified]) ;;
  232. esac],
  233. [with_gtk=3.0])
  234. AC_MSG_RESULT([$with_gtk])
  235. case "$with_gtk" in
  236. 2.0) GTK_API_VERSION=2.0
  237. GTK_REQUIRED=2.0.0
  238. GTK_HAVE_API_VERSION_2=1
  239. GTK_HAVE_API_VERSION_3=0
  240. GTK_HAVE_API_VERSION_4=0
  241. ;;
  242. 3.0) GTK_API_VERSION=3.0
  243. GTK_REQUIRED=2.91.0
  244. GTK_HAVE_API_VERSION_2=0
  245. GTK_HAVE_API_VERSION_3=1
  246. GTK_HAVE_API_VERSION_4=0
  247. ;;
  248. 4.0) GTK_API_VERSION=4.0
  249. GTK_REQUIRED=3.91.0
  250. GTK_HAVE_API_VERSION_2=0
  251. GTK_HAVE_API_VERSION_3=0
  252. GTK_HAVE_API_VERSION_4=1
  253. ;;
  254. esac
  255. #
  256. AC_SUBST([GTK_API_VERSION])
  257. AC_SUBST([GTK_REQUIRED])
  258. #
  259. AM_CONDITIONAL([HAVE_GTK_2],[test "$with_gtk" = "2.0"])
  260. AM_CONDITIONAL([HAVE_GTK_3],[test "$with_gtk" = "3.0"])
  261. AM_CONDITIONAL([HAVE_GTK_4],[test "$with_gtk" = "4.0"])
  262. #
  263. AC_DEFINE_UNQUOTED([GTK_HAVE_API_VERSION_2], [$GTK_HAVE_API_VERSION_2], [gtk version 2])
  264. AC_DEFINE_UNQUOTED([GTK_HAVE_API_VERSION_3], [$GTK_HAVE_API_VERSION_3], [gtk version 3])
  265. AC_DEFINE_UNQUOTED([GTK_HAVE_API_VERSION_4], [$GTK_HAVE_API_VERSION_4], [gtk version 4])
  266. # Preliminary check for pkg-config
  267. if test -z "$PKG_CONFIG"; then
  268. AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
  269. fi
  270. if test "$PKG_CONFIG" = "no" ; then
  271. echo "
  272. Please install pkg-config and then reconfigure mooigraph.
  273. pkg-config is available from http://www.freedesktop.org/
  274. "
  275. exit 1
  276. fi
  277. # glib 2.0 (needed even if not building GUI; we need 2.14 for regexp functions)
  278. PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.14.0, have_glib2="yes", have_glib2="no")
  279. if test "${have_glib2}" = "no" ; then
  280. echo "
  281. Please install glib-2.0 >= 2.14.0 and then reconfigure mooigraph.
  282. glib-2.0 is available from http://www.gtk.org/
  283. "
  284. exit 1
  285. fi
  286. # Initial check for GTK availability
  287. if test "$prefer_gtk2" = "yes" ; then
  288. PKG_CHECK_MODULES(GTK2, gtk+-2.0 >= 2.14.0,
  289. GTK_CFLAGS=$GTK2_CFLAGS
  290. GTK_LIBS=$GTK2_LIBS
  291. CFLAGS="$CFLAGS $GTK_CFLAGS"
  292. LIBS="$LIBS $GTK_LIBS"
  293. gtk_version="2.0",
  294. echo "GTK 2 >= 2.14.0 not found"
  295. )
  296. elif test "$prefer_gtk2" = "no" ; then
  297. PKG_CHECK_MODULES(GTK3, gtk+-3.0 >= 3.0.1,
  298. GTK_CFLAGS=$GTK3_CFLAGS
  299. GTK_LIBS=$GTK3_LIBS
  300. CFLAGS="$CFLAGS $GTK_CFLAGS"
  301. LIBS="$LIBS $GTK_LIBS"
  302. dnl AC_DEFINE(USE_GTK3)
  303. gtk_version="3.0"
  304. fake_gtkspinner="no",
  305. echo "GTK 3 >= 3.0.1 not found"
  306. )
  307. fi
  308. dnl GTK 2.0 fallback in case preference not given
  309. if test "$prefer_gtk2" = "no" && test "$gtk_version" = "none" ; then
  310. PKG_CHECK_MODULES(GTK2, gtk+-2.0 >= 2.14.0,
  311. GTK_CFLAGS=$GTK2_CFLAGS
  312. GTK_LIBS=$GTK2_LIBS
  313. CFLAGS="$CFLAGS $GTK_CFLAGS"
  314. LIBS="$LIBS $GTK_LIBS"
  315. gtk_version="2.0",
  316. build_gui="no"
  317. echo "GTK 2 >= 2.14.0 not found"
  318. )
  319. fi
  320. #
  321. PKG_CHECK_MODULES(GTK, gtk+-$GTK_API_VERSION >= $GTK_REQUIRED)
  322. AC_SUBST(GTK_CFLAGS)
  323. AC_SUBST(GTK_LIBS)
  324. # final compiler settings
  325. AC_SUBST(PACKAGE_CFLAGS)
  326. AC_CONFIG_FILES([Makefile src/Makefile])
  327. AC_OUTPUT
  328. # ST_REPORT(NAME, VALUE)
  329. AC_DEFUN([ST_REPORT], [ m4_format([%-30s %s], [$1], [$2])])
  330. # ST_REPORT_ARG(NAME)
  331. AC_DEFUN([ST_REPORT_ARG], [ST_REPORT([--[$1]], [$translit([$1], -, _)])
  332. ])
  333. # ST_REPORT_ARGS(NAMES)
  334. AC_DEFUN([ST_REPORT_ARGS], [m4_foreach(name, [$1], [ST_REPORT_ARG(name)])
  335. ])
  336. # ST_REPORT_FEATURE(FEATURE)
  337. AC_DEFUN([ST_REPORT_FEATURE],
  338. [ST_REPORT([--enable-[$1]],
  339. [$ST_FEATURE_VAR_NAME([$1]) $ST_FEATURE_DISABLE_REASON_VAR_NAME([$1])])])
  340. # ST_REPORT_FEATURES(FEATURES)
  341. AC_DEFUN([ST_REPORT_FEATURES], [m4_foreach(feature, [$1], [ST_REPORT_FEATURE(feature)])
  342. ])
  343. echo "$0 complete, type 'make' to build"
  344. echo
  345. echo " "
  346. echo " "
  347. echo " "
  348. echo " , , "
  349. echo " / \ "
  350. echo " ((__-^^-,-^^-__)) "
  351. echo " '-__- - '--__- "
  352. echo " -O O- "
  353. echo " \ / "
  354. echo " ): :( "
  355. echo " :o_o: "
  356. echo " - "
  357. echo " "
  358. echo " "
  359. echo " "
  360. echo This system is `uname -a`;
  361. cat <<EOF
  362. $PACKAGE_NAME $VERSION is ready to be built.
  363. The following settings will be used:
  364. Installation prefixes
  365. ST_REPORT_ARGS([prefix, exec-prefix])
  366. Installation directories
  367. ST_REPORT_ARGS([bindir, datadir, libdir, includedir])
  368. Use "make" to compile $PACKAGE_NAME $VERSION.
  369. use ./configure --with-gtk=2.0 for gtk-2
  370. use ./configure --with-gtk=3.0 for gtk-3
  371. use ./configure --with-gtk=4.0 for gtk-4
  372. use ./configure --enable-gcc-warnings to enable gcc warnings and checks
  373. EOF
  374. AC_MSG_RESULT([
  375. Building programs with prefix=$prefix
  376. c-compiler: $CC
  377. c-flags: $CFLAGS
  378. gtk-version: $GTK_API_VERSION
  379. gtk-c-flags: $GTK_CFLAGS
  380. gtk-libs: $GTK_LIBS
  381. ]);
  382. # end