From: Boyuan Yang <byang@debian.org>
Date: Thu, 14 Apr 2022 11:32:38 -0400
Subject: use autoconf

---
 Makefile.am     |  9 +++++++++
 configure.ac    | 40 ++++++++++++++++++++++++++++++++++++++++
 m4/.placeholder |  0
 3 files changed, 49 insertions(+)
 create mode 100644 Makefile.am
 create mode 100644 configure.ac
 create mode 100644 m4/.placeholder

diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 0000000..096b39a
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1,9 @@
+ACLOCAL_AMFLAGS = -I m4
+
+bin_PROGRAMS = xcalib
+
+xcalib_SOURCES = xcalib.c
+xcalib_CFLAGS = @X_CFLAGS@
+# AX_PATH_XTRA only specify the root of X11
+# we still have to include -lX11 ourselves
+xcalib_LDFLAGS = @X_LIBS@ -lX11 -lm -lXxf86vm -lXext
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 0000000..0a0e624
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,40 @@
+#                                               -*- Autoconf -*-
+# Process this file with autoconf to produce a configure script.
+
+AC_PREREQ([2.69])
+AC_INIT([xcalib], [0.8], [http://xcalib.sourceforge.net/])
+AC_DEFINE([XCALIB_VERSION], ["0.8"], [XCalib version])
+
+AC_CONFIG_SRCDIR([xcalib.c])
+AC_CONFIG_HEADERS([config.h])
+AC_CONFIG_AUX_DIR([build-aux])
+AC_CONFIG_MACRO_DIR([m4])
+
+AM_INIT_AUTOMAKE([foreign])
+
+# Checks for programs.
+AC_PROG_CC
+
+# Checks for libraries.
+AC_PATH_XTRA
+AS_IF([test "X$no_x" = "Xyes"],
+      [AC_MSG_ERROR([Could not find X11])])
+AC_CHECK_LIB([X11], [XOpenDisplay], , [AC_MSG_ERROR([Could not find X11])])
+AC_CHECK_LIB([Xext], [XextAddDisplay], , [AC_MSG_ERROR([Could not find Xext])])
+AC_CHECK_LIB([Xxf86vm], [XF86VidModeQueryExtension], , [AC_MSG_ERROR([Could not find Xxf86vm])])
+# No FGLRX support for now
+AC_CHECK_LIB([m], [sin])
+
+# Checks for header files.
+AC_PATH_X
+AC_CHECK_HEADERS([fcntl.h])
+
+# Checks for typedefs, structures, and compiler characteristics.
+
+# Checks for library functions.
+AC_FUNC_ERROR_AT_LINE
+AC_FUNC_MALLOC
+AC_CHECK_FUNCS([pow])
+
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
diff --git a/m4/.placeholder b/m4/.placeholder
new file mode 100644
index 0000000..e69de29
