Skip to content

Commit ef4f9e4

Browse files
authored
Switch to autotools (#163)
This was largely copied from the i3 configure.ac and Makefile.am.
1 parent be02e80 commit ef4f9e4

19 files changed

+1679
-72
lines changed

.gitignore

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,31 @@
1-
i3lock
1+
/i3lock
22
*.o
33
tags
44
*.swp
5+
6+
################################################################################
7+
# https://raw.githubusercontent.com/github/gitignore/master/Autotools.gitignore
8+
################################################################################
9+
10+
# http://www.gnu.org/software/automake
11+
12+
Makefile.in
13+
/ar-lib
14+
/test-driver
15+
16+
# http://www.gnu.org/software/autoconf
17+
18+
/autom4te.cache
19+
/autoscan.log
20+
/autoscan-*.log
21+
/aclocal.m4
22+
/compile
23+
/config.h.in
24+
/config.guess
25+
/config.sub
26+
/configure
27+
/configure.scan
28+
/depcomp
29+
/install-sh
30+
/missing
31+
/stamp-h1

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ before_install:
2525
- sudo apt-get update
2626
- sudo apt-get --force-yes -y install -t xenial libxkbcommon-dev libxkbcommon-x11-dev
2727
script:
28-
- make -j
28+
- autoreconf -fi && mkdir -p build && cd build && (../configure || (cat config.log; false)) && make -j CFLAGS="-Wformat -Wformat-security -Wextra -Wno-unused-parameter -Werror"
2929
- clang-format-3.5 -i *.[ch] && git diff --exit-code || (echo 'Code was not formatted using clang-format!'; false)

Makefile

-67
This file was deleted.

Makefile.am

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
@CODE_COVERAGE_RULES@
2+
3+
echo-version:
4+
@echo "@I3LOCK_VERSION@"
5+
6+
bin_PROGRAMS = i3lock
7+
8+
dist_man1_MANS = i3lock.1
9+
10+
pamddir = $(sysconfdir)/pam.d
11+
pamd_files = pam/i3lock
12+
pamd_DATA = $(pamd_files)
13+
14+
AM_CPPFLAGS = \
15+
@AX_EXTEND_SRCDIR_CPPFLAGS@
16+
17+
i3lock_CFLAGS = \
18+
$(AM_CFLAGS) \
19+
$(XCB_CFLAGS) \
20+
$(XCB_IMAGE_CFLAGS) \
21+
$(XCB_UTIL_CFLAGS) \
22+
$(XKBCOMMON_CFLAGS) \
23+
$(CAIRO_CFLAGS) \
24+
$(CODE_COVERAGE_CFLAGS)
25+
26+
i3lock_CPPFLAGS = \
27+
$(AM_CPPFLAGS) \
28+
$(CODE_COVERAGE_CPPFLAGS)
29+
30+
i3lock_LDADD = \
31+
$(XCB_LIBS) \
32+
$(XCB_IMAGE_LIBS) \
33+
$(XCB_UTIL_LIBS) \
34+
$(XKBCOMMON_LIBS) \
35+
$(CAIRO_LIBS) \
36+
$(CODE_COVERAGE_LDFLAGS)
37+
38+
i3lock_SOURCES = \
39+
cursors.h \
40+
i3lock.c \
41+
i3lock.h \
42+
randr.c \
43+
randr.h \
44+
unlock_indicator.c \
45+
unlock_indicator.h \
46+
xcb.c \
47+
xcb.h
48+
49+
EXTRA_DIST = \
50+
$(pamd_files) \
51+
CHANGELOG \
52+
LICENSE \
53+
README.md

configure.ac

+145
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# -*- Autoconf -*-
2+
# Run autoreconf -fi to generate a configure script from this file.
3+
4+
AC_PREREQ([2.69])
5+
AC_INIT([i3lock], [2.10], [https://github.com/i3/i3lock/issues])
6+
# For AX_EXTEND_SRCDIR
7+
AX_ENABLE_BUILDDIR
8+
AM_INIT_AUTOMAKE([foreign subdir-objects -Wall no-dist-gzip dist-bzip2])
9+
# Default to silent rules, use V=1 to get verbose compilation output.
10+
AM_SILENT_RULES([yes])
11+
# Make it possible to disable maintainer mode to disable re-generation of build
12+
# system files.
13+
AM_MAINTAINER_MODE([enable])
14+
AC_CONFIG_SRCDIR([i3lock.c])
15+
AC_CONFIG_HEADERS([config.h])
16+
AC_CONFIG_MACRO_DIR([m4])
17+
18+
dnl Verify macros defined in m4/ such as AX_SANITIZERS are not present in the
19+
dnl output, i.e. are replaced as expected. This line results in a better error
20+
dnl message when using aclocal < 1.13 (which does not understand
21+
dnl AC_CONFIG_MACRO_DIR) without passing the -I m4 parameter.
22+
m4_pattern_forbid([AX_SANITIZERS])
23+
24+
# Verify we are using GNU make because we use '%'-style pattern rules in
25+
# Makefile.am, which are a GNU make extension. Pull requests to replace
26+
# '%'-style pattern rules with a more portable alternative are welcome.
27+
AX_CHECK_GNU_MAKE
28+
AS_VAR_IF([_cv_gnu_make_command], [""], [AC_MSG_ERROR([the i3lock Makefile.am requires GNU make])])
29+
30+
AX_EXTEND_SRCDIR
31+
32+
AS_IF([test -d ${srcdir}/.git],
33+
[
34+
VERSION="$(git -C ${srcdir} describe --tags --abbrev=0)"
35+
I3LOCK_VERSION="$(git -C ${srcdir} describe --tags --always) ($(git -C ${srcdir} log --pretty=format:%cd --date=short -n1), branch \\\"$(git -C ${srcdir} describe --tags --always --all | sed s:heads/::)\\\")"
36+
# Mirrors what libi3/is_debug_build.c does:
37+
is_release=$(test $(echo "${I3LOCK_VERSION}" | cut -d '(' -f 1 | wc -m) -lt 10 && echo yes || echo no)
38+
],
39+
[
40+
VERSION="$(cut -d '-' -f 1 ${srcdir}/I3LOCK_VERSION | cut -d ' ' -f 1)"
41+
I3LOCK_VERSION="$(sed -e 's/@<:@\"?\\@:>@/\\&/g' ${srcdir}/I3LOCK_VERSION)"
42+
is_release="$(grep -q non-git ${srcdir}/I3LOCK_VERSION && echo no || echo yes)"
43+
])
44+
AC_SUBST([I3LOCK_VERSION], [$I3LOCK_VERSION])
45+
AC_DEFINE_UNQUOTED([I3LOCK_VERSION], ["${I3LOCK_VERSION}"], [i3lock version])
46+
47+
AX_CODE_COVERAGE
48+
49+
dnl is_release must be lowercase because AX_CHECK_ENABLE_DEBUG calls m4_tolower
50+
dnl on its fourth argument.
51+
AX_CHECK_ENABLE_DEBUG([yes], , [UNUSED_NDEBUG], [$is_release])
52+
53+
AC_PROG_CC_C99
54+
55+
# For strnlen() and vasprintf().
56+
AC_USE_SYSTEM_EXTENSIONS
57+
58+
# Checks for typedefs, structures, and compiler characteristics.
59+
AC_CHECK_HEADER_STDBOOL
60+
dnl The error message should include the specific type which could not be
61+
dnl found, but I do not see a way to achieve that.
62+
AC_CHECK_TYPES([mode_t, off_t, pid_t, size_t, ssize_t], , [AC_MSG_FAILURE([cannot find required type])])
63+
64+
# Checks for library functions.
65+
AC_FUNC_FORK
66+
AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
67+
AC_FUNC_STRNLEN
68+
AC_CHECK_FUNCS([atexit dup2 ftruncate getcwd gettimeofday localtime_r memchr memset mkdir rmdir setlocale socket strcasecmp strchr strdup strerror strncasecmp strndup strrchr strspn strstr strtol strtoul], , [AC_MSG_FAILURE([cannot find the $ac_func function, which i3lock requires])])
69+
70+
# Checks for libraries.
71+
72+
AC_SEARCH_LIBS([floor], [m], , [AC_MSG_FAILURE([cannot find the required floor() function despite trying to link with -lm])])
73+
74+
# libev does not ship with a pkg-config file :(.
75+
AC_SEARCH_LIBS([ev_run], [ev], , [AC_MSG_FAILURE([cannot find the required ev_run() function despite trying to link with -lev])])
76+
77+
AC_SEARCH_LIBS([shm_open], [rt])
78+
79+
AC_SEARCH_LIBS([pam_authenticate], [pam])
80+
81+
AC_SEARCH_LIBS([iconv_open], [iconv], , [AC_MSG_FAILURE([cannot find the required iconv_open() function despite trying to link with -liconv])])
82+
83+
dnl Each prefix corresponds to a source tarball which users might have
84+
dnl downloaded in a newer version and would like to overwrite.
85+
PKG_CHECK_MODULES([XCB], [xcb xcb-xkb xcb-xinerama xcb-randr])
86+
PKG_CHECK_MODULES([XCB_IMAGE], [xcb-image])
87+
PKG_CHECK_MODULES([XCB_UTIL], [xcb-event xcb-util xcb-atom])
88+
PKG_CHECK_MODULES([XKBCOMMON], [xkbcommon xkbcommon-x11])
89+
PKG_CHECK_MODULES([CAIRO], [cairo])
90+
91+
# Checks for programs.
92+
AC_PROG_AWK
93+
AC_PROG_CPP
94+
AC_PROG_INSTALL
95+
AC_PROG_MAKE_SET
96+
AC_PROG_RANLIB
97+
AC_PROG_LN_S
98+
99+
AM_PROG_AR
100+
101+
AX_FLAGS_WARN_ALL
102+
AX_CHECK_COMPILE_FLAG([-Wunused-value], [AX_APPEND_FLAG([-Wunused-value], [AM_CFLAGS])])
103+
AC_SUBST(AM_CFLAGS)
104+
105+
# Checks for header files.
106+
AC_CHECK_HEADERS([fcntl.h float.h inttypes.h limits.h locale.h netinet/in.h paths.h stddef.h stdint.h stdlib.h string.h sys/param.h sys/socket.h sys/time.h unistd.h], , [AC_MSG_FAILURE([cannot find the $ac_header header, which i3lock requires])])
107+
108+
AC_CONFIG_FILES([Makefile])
109+
110+
# Enable address sanitizer for non-release builds. The performance hit is a
111+
# 50% increase of wallclock time for the testsuite on my machine.
112+
if test x$is_release = xyes; then
113+
default_sanitizers=
114+
else
115+
default_sanitizers=address
116+
fi
117+
AX_SANITIZERS(, [$default_sanitizers], [AC_DEFINE([I3LOCK_ASAN_ENABLED], [], [Enable ASAN])])
118+
119+
AC_OUTPUT
120+
121+
in_git_worktree=`git rev-parse --is-inside-work-tree 2>/dev/null`
122+
if [[ "$in_git_worktree" = "true" ]]; then
123+
git_dir=`git rev-parse --git-dir 2>/dev/null`
124+
srcdir=`dirname "$git_dir"`
125+
exclude_dir=`pwd | sed "s,^$srcdir,,g"`
126+
if ! grep -q "^$exclude_dir" "$git_dir/info/exclude"; then
127+
echo "$exclude_dir" >> "$git_dir/info/exclude"
128+
fi
129+
fi
130+
131+
echo \
132+
"--------------------------------------------------------------------------------
133+
build configured:
134+
135+
AS_HELP_STRING([i3lock version:], [`echo ${I3LOCK_VERSION} | sed 's,\\\\,,g'`])
136+
AS_HELP_STRING([is release version:], [${is_release}])
137+
138+
AS_HELP_STRING([enable debug flags:], [${ax_enable_debug}])
139+
AS_HELP_STRING([code coverage:], [${CODE_COVERAGE_ENABLED}])
140+
AS_HELP_STRING([enabled sanitizers:], [${ax_enabled_sanitizers}])
141+
142+
To compile, run:
143+
144+
cd `pwd` && make -j8
145+
--------------------------------------------------------------------------------"

i3lock.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* See LICENSE for licensing information
77
*
88
*/
9+
#include <config.h>
10+
911
#include <stdio.h>
1012
#include <stdlib.h>
1113
#include <pwd.h>
@@ -178,7 +180,7 @@ static void clear_password_memory(void) {
178180
/* A volatile pointer to the password buffer to prevent the compiler from
179181
* optimizing this out. */
180182
volatile char *vpassword = password;
181-
for (int c = 0; c < sizeof(password); c++)
183+
for (size_t c = 0; c < sizeof(password); c++)
182184
/* We store a non-random pattern which consists of the (irrelevant)
183185
* index plus (!) the value of the beep variable. This prevents the
184186
* compiler from optimizing the calls away, since the value of 'beep'
@@ -486,7 +488,7 @@ static void handle_key_press(xcb_key_press_event_t *event) {
486488
return;
487489
}
488490

489-
if ((input_position + 8) >= sizeof(password))
491+
if ((input_position + 8) >= (int)sizeof(password))
490492
return;
491493

492494
#if 0
@@ -852,7 +854,7 @@ int main(int argc, char *argv[]) {
852854
while ((o = getopt_long(argc, argv, optstring, longopts, &longoptind)) != -1) {
853855
switch (o) {
854856
case 'v':
855-
errx(EXIT_SUCCESS, "version " VERSION " © 2010 Michael Stapelberg");
857+
errx(EXIT_SUCCESS, "version " I3LOCK_VERSION " © 2010 Michael Stapelberg");
856858
case 'n':
857859
dont_fork = true;
858860
break;

0 commit comments

Comments
 (0)