build: add autotools build system

This commit is contained in:
lohhiiccc 2026-03-29 01:10:20 +01:00
parent adf84ccb8e
commit 04e067875a
6 changed files with 96 additions and 0 deletions

13
Makefile.am Normal file
View file

@ -0,0 +1,13 @@
ACLOCAL_AMFLAGS = -I m4
SUBDIRS = src example
if BUILD_TESTS
SUBDIRS += tests
endif
pkgincludedir = $(includedir)/cli
pkginclude_HEADERS = \
include/cli.h \
include/cli_parse_utils.h \
include/compiler.h

3
autogen.sh Executable file
View file

@ -0,0 +1,3 @@
#!/bin/sh
set -e
autoreconf --install --verbose

47
configure.ac Normal file
View file

@ -0,0 +1,47 @@
AC_PREREQ([2.69])
AC_INIT([libcli], [0.1.0], [])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_MACRO_DIRS([m4])
AM_INIT_AUTOMAKE([foreign -Wall -Werror subdir-objects])
AC_PROG_CC
AM_PROG_AR
LT_PREREQ([2.2])
LT_INIT
# --enable-tests
AC_ARG_ENABLE([tests],
[AS_HELP_STRING([--enable-tests], [Build Criterion unit tests (default: no)])],
[enable_tests=$enableval],
[enable_tests=no])
AM_CONDITIONAL([BUILD_TESTS], [test "x$enable_tests" = "xyes"])
AS_IF([test "x$enable_tests" = "xyes"], [
PKG_CHECK_MODULES([CRITERION], [criterion], [], [
AC_MSG_NOTICE([pkg-config could not find criterion -- trying manual detection])
AC_CHECK_HEADER([criterion/criterion.h], [], [
AC_MSG_ERROR([criterion/criterion.h not found])])
AC_CHECK_LIB([criterion], [main],
[CRITERION_LIBS="-lcriterion"],
[AC_MSG_ERROR([libcriterion not found])])
])
])
AC_CONFIG_FILES([
Makefile
src/Makefile
tests/Makefile
example/Makefile
])
AC_OUTPUT
AC_MSG_NOTICE([
libcli $VERSION
---------------
prefix : $prefix
CC : $CC
CFLAGS : $CFLAGS
tests : $enable_tests
])

6
example/Makefile.am Normal file
View file

@ -0,0 +1,6 @@
noinst_PROGRAMS = greet
greet_SOURCES = main.c
greet_CPPFLAGS = -I$(top_srcdir)/include
greet_CFLAGS = -std=c99 -Wall -Wextra
greet_LDADD = $(top_builddir)/src/libcli.la

12
src/Makefile.am Normal file
View file

@ -0,0 +1,12 @@
lib_LTLIBRARIES = libcli.la
libcli_la_SOURCES = \
parse.c \
parse_utils/parse_int.c \
parse_utils/parse_float.c
libcli_la_CPPFLAGS = -I$(top_srcdir)/include
libcli_la_CFLAGS = -std=c99 -Wall -Wextra
# Libtool versioning: current:revision:age
libcli_la_LDFLAGS = -version-info 0:1:0

15
tests/Makefile.am Normal file
View file

@ -0,0 +1,15 @@
AM_CPPFLAGS = -I$(top_srcdir)/include $(CRITERION_CFLAGS)
AM_CFLAGS = -std=c99
check_PROGRAMS = test_cli
test_cli_SOURCES = \
test_main.c \
parse_utils/test_parse_int.c \
parse_utils/test_parse_float.c
test_cli_LDADD = \
$(top_builddir)/src/libcli.la \
$(CRITERION_LIBS)
TESTS = test_cli