Skip to content

Autotools template for new projects in one page

LIU Hao edited this page Sep 12, 2022 · 7 revisions

.gitignore

*~
.*
*.lo
*.o
*.so
*.la
*.a
*.trs
*.test
*.log
*.gch
*.exe
*.dll

/aclocal.m4
/autom4te.cache/
/build-aux/
/m4/
/configure
/Makefile
/Makefile.in
/config.h
/config.h.in
/config.status
/libtool
/stamp-h1
/src/version.h
/src/precompiled.x*

/lib/
/bin/
/sbin/
/tmp/
/var/

*.save*
*.swp
*.*~
*.orig
*.rej
*.out
*.tar
*.tar.*
*.deb
*.stackdump
core.*
callgrind.*

configure.ac

AC_INIT([package], [version], [bug-report], [tarname], [url])

AC_LANG([C])                       # use `C++` if you want C++
AC_CONFIG_SRCDIR([src/main.c])     # specify any source file
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_MACRO_DIR([m4])
AC_PROG_CC                         # use `AC_PROG_CXX` if you want C++

LT_INIT([])                        # delete this if you need not build libraries
LT_LANG([C])                       # delete this if you need not build libraries

AM_INIT_AUTOMAKE([foreign subdir-objects])
AM_SILENT_RULES([yes])

AC_CONFIG_FILES([Makefile])
AC_OUTPUT

Makefile.am

ACLOCAL_AMFLAGS = -I m4
END =

## Compiler options
AM_CPPFLAGS = -pipe -Wall -Wextra -Isrc  \
  -U_FORTIFY_SOURCE -D_WIN32_WINNT=0x0601 -D_POSIX_C_SOURCE=200809  \
  -f{strict-{aliasing,overflow},merge-all-constants,fast-math}  \
  -fno-{stack-protector,align-{functions,jumps,loops},ident}  \
  -Werror={conversion,sign-{compare,conversion},write-strings}  \
  -Werror={return-type,double-promotion,missing-declarations}  \
  -W{missing-field-initializers,suggest-attribute=noreturn,shadow}  \
  -W{switch-enum,unused-{function,label,local-typedefs}}  \
  -Wunused-but-set-{variable,parameter}

AM_CFLAGS = -std=c99  \
  -Werror={discarded-qualifiers,incompatible-pointer-types}  \
  -Werror={strict-prototypes,int-conversion}  \
  -Werror=implicit-{function-declaration,int}

AM_DEFAULT_SOURCE_EXT = .c    # use a proper suffix for test source files, to allow implicit rules apply
LDADD =                       # add libraries that are to be built here, mainly for implicit rules for tests

## Initialization
noinst_LIBRARIES =
noinst_LTLIBRARIES =

include_HEADERS =
lib_LIBRARIES =
lib_LTLIBRARIES =
bin_PROGRAMS =

check_HEADERS =
check_LIBRARIES =
check_LTLIBRARIES =
check_PROGRAMS =

BUILT_SOURCES =
CLEANFILES =
EXTRA_DIST =
TESTS = ${check_PROGRAMS}

## Programs and libraries
include src/Makefile.inc.am

## Tests
include test/Makefile.inc.am

src/Makefile.inc.am

## Installable headers
include_mylibrarydir = ${includedir}/mylibrary
include_mylibrary_HEADERS =  \
  %reldir%/header_1.h  \
  %reldir%/header_2.h  \
  ${END}

## Installable libraries
##   Use `noinst_LIBRARIES` (not `noinst_LTLIBRARIES`) for libraries that are
##   not going to be installed. SOURCES should include generated files.
lib_LTLIBRARIES += lib/libmylibrary.la
lib_libmylibrary_la_SOURCES =  \
  %reldir%/mylibrary_source_1.c  \
  %reldir%/mylibrary_source_2.c  \
  ${END}

## Installable libraries
##   SOURCES should include generated files.
bin_PROGRAMS += bin/myprogram
bin_myprogram_SOURCES =  \
  %reldir%/myprogram_source_1.c  \
  %reldir%/myprogram_source_2.c  \
  ${END}

test/Makefile.inc.am

check_PROGRAMS +=  \
  %reldir%/test_program_1.test  \
  %reldir%/test_program_2.test  \
  ${END}
Clone this wiki locally