From 8f6d3f6897d8dd78959086c037ba00f0b2548ff6 Mon Sep 17 00:00:00 2001 From: Hans-Joerg Schurr Date: Fri, 21 Feb 2020 19:12:20 +0100 Subject: [PATCH] Add build system This adds a autoconfig base build system and some test files. To build: 1) autoreconf 2) ./configure 3) make --- .gitignore | 18 ++++++++ Makefile.am | 1 + configure.ac | 79 ++++++++++++++++++++++++++++++++++ m4/m4_ax_check_compile_flag.m4 | 53 +++++++++++++++++++++++ src/Makefile.am | 21 +++++++++ src/hvif-light.c | 5 +++ src/hvif-light.h | 7 +++ src/main.c | 13 ++++++ 8 files changed, 197 insertions(+) create mode 100644 Makefile.am create mode 100644 configure.ac create mode 100644 m4/m4_ax_check_compile_flag.m4 create mode 100644 src/Makefile.am create mode 100644 src/hvif-light.c create mode 100644 src/hvif-light.h create mode 100644 src/main.c diff --git a/.gitignore b/.gitignore index 02f3776..22e3fa9 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,21 @@ *.ps *.pdf +src/.deps +src/.dirstamp +src/config.h* +src/stamp-h1 +src/src + +Makefile +Makefile.in +aclocal.m4 +autom4te.cache +compile +config.log +config.status +configure +depcomp +hvif +install-sh +missing diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..e138f5f --- /dev/null +++ b/Makefile.am @@ -0,0 +1 @@ +include src/Makefile.am diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..41f21e3 --- /dev/null +++ b/configure.ac @@ -0,0 +1,79 @@ +# -*- Autoconf -*- +# Process this file with autoconf to produce a configure script. + +AC_PREREQ([2.69]) +AC_INIT([hvif-light], [0.0.1], [commits@schurr.at]) +AC_CONFIG_MACRO_DIR(m4) +AM_INIT_AUTOMAKE([subdir-objects foreign 1.13]) +AM_SILENT_RULES([yes]) +AC_CONFIG_SRCDIR([src/hvif-light.h]) +AC_CONFIG_HEADERS([src/config.h]) + +# Checks C compiler (with empty default flags). +: ${CFLAGS=""} +AC_PROG_CC + +AX_CHECK_COMPILE_FLAG([-std=c11], + [ CFLAGS+=" -std=c11" ], + [ AC_MSG_ERROR([C compiler doesn't support C11 mode])] ) + +# TODO: Update checks once we have code + +# Checks for header files. +AC_CHECK_HEADERS([limits.h stddef.h stdint.h stdlib.h string.h sys/time.h unistd.h]) + +# Checks for typedefs, structures, and compiler characteristics. +AC_CHECK_HEADER_STDBOOL +AC_C_INLINE +AC_TYPE_INT32_T +AC_TYPE_SIZE_T +AC_TYPE_UINT32_T + +# Checks for library functions. +AC_FUNC_MALLOC +AC_FUNC_REALLOC +AC_CHECK_FUNCS([memmove memset mkdir pow strchr strdup strstr strtol]) + +# User defined options: debug, lto +AC_ARG_ENABLE([debug], + [AS_HELP_STRING([--enable-debug],[compile with debug options])], + [debug=${enableval}], [debug=no]) +AC_ARG_ENABLE([lto], + [AS_HELP_STRING([--disable-lto], [disable link time optimization])], + [lto=${enableval}], [lto=yes]) + +AC_MSG_NOTICE([Setting up compiler flags]) +CFLAGS+=" -Wall -Wpedantic -Wextra" + +if test x$debug = xyes; then + CFLAGS+=" -O0" + CFLAGS+=" -g -g3 -gdwarf-2" + CFLAGS+=" -ftrapv" + CPPFLAGS+="-DDEBUG" + YFLAGS+=" --debug -v" + lto=no +else + CFLAGS+=" -O3" + CPPFLAGS+=" -DNDEBUG" + CFLAGS+=" -fomit-frame-pointer" + AX_CHECK_COMPILE_FLAG([-finline-limit=1000000 ], + [ CFLAGS+=" -finline-limit=1000000" ]) +fi + +if test x$lto = xyes; then + AX_CHECK_COMPILE_FLAG([-flto], + [ CFLAGS+=" -flto" ], + [ AC_MSG_WARN([C compiler doesn't support link time optimization])] ) +fi + +AC_CONFIG_FILES([Makefile src/Makefile]) +AC_OUTPUT + +AS_ECHO("") +AS_ECHO("") +AS_ECHO("Configuration summary") +AS_ECHO("CC = $CC") +AS_ECHO("CFLAGS = $CFLAGS") +AS_ECHO("CPPLAGS = $CPPFLAGS") +AS_ECHO("YFLAGS = $YFLAGS") +AS_ECHO("LFLAGS = $LFLAGS") diff --git a/m4/m4_ax_check_compile_flag.m4 b/m4/m4_ax_check_compile_flag.m4 new file mode 100644 index 0000000..bd753b3 --- /dev/null +++ b/m4/m4_ax_check_compile_flag.m4 @@ -0,0 +1,53 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT]) +# +# DESCRIPTION +# +# Check whether the given FLAG works with the current language's compiler +# or gives an error. (Warnings, however, are ignored) +# +# ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on +# success/failure. +# +# If EXTRA-FLAGS is defined, it is added to the current language's default +# flags (e.g. CFLAGS) when the check is done. The check is thus made with +# the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to +# force the compiler to issue an error when a bad flag is given. +# +# INPUT gives an alternative input source to AC_COMPILE_IFELSE. +# +# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this +# macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG. +# +# LICENSE +# +# Copyright (c) 2008 Guido U. Draheim +# Copyright (c) 2011 Maarten Bosmans +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 6 + +AC_DEFUN([AX_CHECK_COMPILE_FLAG], +[AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF +AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl +AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [ + ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS + _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1" + AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])], + [AS_VAR_SET(CACHEVAR,[yes])], + [AS_VAR_SET(CACHEVAR,[no])]) + _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags]) +AS_VAR_IF(CACHEVAR,yes, + [m4_default([$2], :)], + [m4_default([$3], :)]) +AS_VAR_POPDEF([CACHEVAR])dnl +])dnl AX_CHECK_COMPILE_FLAGS diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..2066c28 --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,21 @@ +NULL = + +bin_PROGRAMS = hvif + +# veriT configuration +hvif_CPPFLAGS = \ + $(AM_CPPFLAGS) \ + -I$(top_builddir)/src \ + $(NULL) +hvif_LDADD = \ + $(AM_LDADD) \ + -lm \ + $(NULL) + +hvif_SOURCES = \ + $(BUILT_SOURCES) \ + src/main.c \ + src/hvif-light.c \ + src/hvif-light.h \ + $(NULL) + diff --git a/src/hvif-light.c b/src/hvif-light.c new file mode 100644 index 0000000..a5d41f3 --- /dev/null +++ b/src/hvif-light.c @@ -0,0 +1,5 @@ +#include "hvif-light.h" + +unsigned test(unsigned x) { + return 2*x; +} diff --git a/src/hvif-light.h b/src/hvif-light.h new file mode 100644 index 0000000..4b0ac7b --- /dev/null +++ b/src/hvif-light.h @@ -0,0 +1,7 @@ +#ifndef HVIF_LIGHT_H +#define HVIF_LIGHT_H + +unsigned test(unsigned x); + +#endif // HVIF_LIGHT_H + diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..af042cd --- /dev/null +++ b/src/main.c @@ -0,0 +1,13 @@ +#include +#include + +#include "config.h" +#include "hvif-light.h" + +int main(void) { + unsigned x = 12; + unsigned y = test(x); + printf("This is " PACKAGE_STRING " and 2*%u = %u.\n", x, y); + + return EXIT_SUCCESS; +}