]> git.draconx.ca Git - rrace.git/blobdiff - configure.ac
Bump dxcommon to get curses configure fixes.
[rrace.git] / configure.ac
index b0c7fb06355cb0916ee5d021694cbc7c0cc36f24..9f290c113c11f6ad243f4dfb14ce7bd282155cf7 100644 (file)
@@ -1,9 +1,11 @@
-dnl Copyright © 2022 Nick Bowler
+dnl Copyright © 2022-2024 Nick Bowler
 dnl
 dnl License WTFPL2: Do What The Fuck You Want To Public License, version 2.
 dnl This is free software: you are free to do what the fuck you want to.
 dnl There is NO WARRANTY, to the extent permitted by law.
 
+DX_PATCH_GNULIB
+
 AC_INIT([rrace], [0], [nbowler@draconx.ca])
 AC_CONFIG_HEADERS([config.h])
 
@@ -12,8 +14,39 @@ AM_SILENT_RULES([yes])
 DX_AUTOMAKE_COMPAT
 
 AC_PROG_CC_C99
+gl_EARLY
+
+AC_C_INLINE
+AC_C_FLEXIBLE_ARRAY_MEMBER
+DX_C_FOR_DECLARATIONS
+
 LT_INIT
+gl_INIT
+
+AC_CACHE_SAVE
+m4_include([lib/gnulib.mk])
+AH_BOTTOM([#include <conf_post.h>])
+
+# Checks for curses
+AC_ARG_WITH([curses], [AS_HELP_STRING([--with-curses],
+  [build UI for text mode via curses (default: auto)])],
+  [], [with_curses=auto])
+AS_IF([test x"$with_curses" != x"no"],
+  [DX_LIB_CURSES([have_curses=yes], [have_curses=no])])
+AS_IF([test x"$with_curses" = x"yes" && test x"$have_curses" != x"yes"],
+  [AC_MSG_FAILURE([--with-curses requested but curses was not found])])
+AM_CONDITIONAL([HAVE_CURSES], [test x"$have_curses" = x"yes"])
 
+AM_COND_IF([HAVE_CURSES],
+[DX_CHECK_CURSES_FUNC([wresize], [0,0,0])
+DX_CHECK_CURSES_MOUSE_SUPPORT])
+
+# Checks for X11
+m4_copy([AC_ARG_WITH], [save_AC_ARG_WITH])
+m4_pushdef([AC_ARG_WITH], [m4_case([$1], [x],
+  [m4_popdef([$0])$0([x], AS_HELP_STRING([--with-x],
+    [build UI for the X Window System (default: auto)]), m4_shift2($@))],
+  [m4_pushdef([$0], m4_defn([save_$0]))$0($@)m4_popdef([$0])])])
 AC_PATH_XTRA
 AS_IF([test x"$no_x" != x"yes"],
 [AC_CACHE_CHECK([for Motif], [dx_cv_have_motif],
@@ -27,17 +60,117 @@ AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <Xm/XmAll.h>],
   [dx_cv_have_motif=yes], [dx_cv_have_motif=no])
 CFLAGS=$save_CFLAGS LIBS=$save_LIBS])])
 
-AS_IF([test x"$with_x" = x"yes" && test "$dx_cv_have_motif" != x"yes"],
+AS_IF([test x"$with_x" = x"yes" && test x"$dx_cv_have_motif" != x"yes"],
   [AC_MSG_FAILURE([--with-x requested but Motif was not found])])
 
 AC_SUBST([MOTIF_CFLAGS], [@&t@])
 AC_SUBST([MOTIF_LIBS], [@&t@])
-AS_IF([test x"$dx_cv_have_motif" = x"yes"],
-  [MOTIF_CFLAGS=$dx_cv_motif_cflags MOTIF_LIBS=$dx_cv_motif_libs])
+AM_CONDITIONAL([HAVE_MOTIF],
+  [test x"$with_x" != x"no" && test x"$dx_cv_have_motif" = x"yes"])
+AM_COND_IF([HAVE_MOTIF],
+  [MOTIF_CFLAGS=$dx_cv_motif_cflags MOTIF_LIBS=$dx_cv_motif_libs],
+  [AC_DEFINE([X_DISPLAY_MISSING])])
+AH_TEMPLATE([X11_RENDER_DEBUG],
+  [Define to 1 to enable visual aids for debugging X11 rendering.])
+
+# Check for XmPIXMAP_AND_STRING.
+#
+# Just checking for the existence of this identifier is sufficient, to ensure
+# that the C compiler accepts the name.  If it turns out to not actually be
+# supported by the library used at runtime, Motif itself will catch this
+# and set to the default (i.e., XmSTRING).
+AM_COND_IF([HAVE_MOTIF],
+[AC_CACHE_CHECK([whether Motif supports XmPIXMAP_AND_STRING],
+[dx_cv_motif_have_pixmap_and_string],
+[save_CFLAGS=$CFLAGS save_LIBS=$LIBS
+CFLAGS="$MOTIF_CFLAGS $CFLAGS" LIBS="$MOTIF_LIBS $LIBS"
+AC_COMPUTE_INT([dx_tmp],
+  [XmPIXMAP != XmPIXMAP_AND_STRING && XmSTRING != XmPIXMAP_AND_STRING],
+  [#include <Xm/Label.h>], [dx_tmp=0])
+AS_IF([test x"$dx_tmp" = x"1"],
+  [dx_cv_motif_have_pixmap_and_string=yes],
+  [dx_cv_motif_have_pixmap_and_string=no])
+CFLAGS=$save_CFLAGS LIBS=$save_LIBS])
+AS_IF([test x"$dx_cv_motif_have_pixmap_and_string" = x"yes"],
+  [AC_DEFINE([HAVE_MOTIF_PIXMAP_AND_STRING], [1],
+    [Define to 1 if Motif supports XmPIXMAP_AND_STRING])])
+])
+
+dnl On ELF systems, linking a program against a string table in shared
+dnl library is very expensive and actually makes things much worse than
+dnl just duplicating the needed strings in the program.
+dnl
+dnl It may help a little bit when static linking or on other shared
+dnl library implementations, which could maybe be auto-detected with
+dnl a configure test, but the penalty for setting these anyway is
+dnl very small (couple hundred bytes of rodata).
+m4_foreach_w([lib], [Xt Xm],
+[AC_DEFINE(m4_toupper(m4_defn([lib]))[STRINGDEFINES], [1],
+[Define to 1 to avoid using the string tables from lib]m4_defn([lib])[.
+On some platforms, or when statically linking lib]m4_defn([lib])[,
+leaving this undefined may reduce the executable size somewhat.])])
 
 AC_CONFIG_TESTDIR([.], [t:.])
-DX_PROG_AUTOTEST
-AM_CONDITIONAL([HAVE_AUTOTEST], [test x"$dx_cv_autotest_works" = x"yes"])
+DX_PROG_AUTOTEST_AM
+
+AC_CHECK_PROGS([XPMTOPPM], [xpmtoppm])
+AC_CHECK_PROGS([PNMTOPNG], [pnmtopng])
+AC_CHECK_PROGS([CONVERT], [convert])
+AC_CHECK_PROGS([GM], [gm])
+AC_CACHE_CHECK([how to convert XPM to PNG], [dx_cv_xpm_to_png],
+[cat >conftest.xpm <<'EOF'
+/* XPM */
+static char *x[] = {
+"1 1 1 1",
+"x c #123456",
+"x"
+};
+EOF
+check_conftest_png () {
+  od conftest.png | $AWK 'BEGIN { success=0; }
+NR == 1 && $2 == "050211" && $3 == "043516" { success=1; }
+NR == 1 && $2 == "104520" && $3 == "047107" { success=1; }
+END { exit(!success); }'
+}
+rm -f conftest.png
+for dx_cv_xpm_to_png in netpbm 'gm convert' convert unknown; do
+AS_CASE([$dx_cv_xpm_to_png],
+
+[netpbm],
+[AS_IF([$XPMTOPPM conftest.xpm >conftest.ppm 2>&AS_MESSAGE_LOG_FD],
+  [], [continue])
+AS_IF([$PNMTOPNG conftest.ppm >conftest.png 2>&AS_MESSAGE_LOG_FD],
+  [], [continue])
+AS_IF([check_conftest_png], [break])],
+
+[*convert],
+[AS_CASE([$dx_cv_xpm_to_png],
+  [gm*], [test_convert="$GM convert"],
+  [test_convert="$CONVERT"])
+AS_IF([$test_convert conftest.xpm conftest.png >&AS_MESSAGE_LOG_FD 2>&1],
+  [], [continue])
+AS_IF([check_conftest_png], [break])])
+done
+rm -f conftest.xpm conftest.ppm conftest.png])
+
+AM_CONDITIONAL([USE_NETPBM], [test x"$dx_cv_xpm_to_png" = x"netpbm"])
+AM_CONDITIONAL([USE_CONVERT],
+  [AS_CASE([$dx_cv_xpm_to_png], [*convert], [], [false])])
+
+AS_IF([test x"$dx_cv_xpm_to_png" = x"gm convert"],
+  [CONVERT="$GM convert"])
+
+AC_CHECK_PROGS([OPTIPNG], [optipng])
+: "${OPTIPNG:=:}"
+
+AM_CONDITIONAL([USE_NLS], [test x"$USE_NLS" = x"yes"])
 
 AC_CONFIG_FILES([Makefile])
 AC_OUTPUT
+
+have_ui=false
+AM_COND_IF([HAVE_CURSES], [have_ui=:])
+AM_COND_IF([HAVE_MOTIF], [have_ui=:])
+AS_IF([$have_ui], [],
+[AC_MSG_WARN([No user interface is enabled.])
+AC_MSG_WARN([It will not be possible to play the game.])])