[PATCH 2/3] build: make use of automake

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



- Manually writing Makefile rules is error-prone.

- Gets rid of the silencers (@, make -s) which cannot be turned off
  from the command line. While Automake is verbose by default,
  version 1.11 will provide a way to (un)silence it on demand.

- Essentially fixes the bug that (cd src; make) fails.

- Dependency generation is done on-the-fly where possible
  (no extra DEP stage!).

Signed-off-by: Jan Engelhardt <jengelh@xxxxxxxxxx>
---
 .gitignore                 |   22 ++--
 Makefile.am                |    3 +
 Makefile.defs.in           |   40 -------
 Makefile.in                |    5 -
 configure.ac               |   50 +++++----
 doc/.gitignore             |    4 +-
 doc/Makefile.am            |   18 +++
 doc/Makefile.in            |   20 ----
 files/Makefile.in          |    4 -
 files/nftables/Makefile.am |    4 +
 install-sh                 |  269 --------------------------------------------
 src/Makefile.am            |   22 ++++
 src/Makefile.in            |   30 -----
 src/cli.c                  |    1 +
 src/erec.c                 |    1 +
 src/main.c                 |    1 +
 16 files changed, 92 insertions(+), 402 deletions(-)
 create mode 100644 Makefile.am
 delete mode 100644 Makefile.defs.in
 delete mode 100644 Makefile.in
 create mode 100644 doc/Makefile.am
 delete mode 100644 doc/Makefile.in
 delete mode 100644 files/Makefile.in
 create mode 100644 files/nftables/Makefile.am
 delete mode 100755 install-sh
 create mode 100644 src/Makefile.am
 delete mode 100644 src/Makefile.in

diff --git a/.gitignore b/.gitignore
index d26b395..d929d9c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,18 +1,20 @@
 # Dependency and object files
-.*.d
+.deps
 *.o
 
 # Generated by autoconf/configure
 Makefile
-Makefile.defs
-Makefile.rules
-config.h
-config.h.in
-config.h.in~
-config.log
-config.status
-configure
-autom4te.cache
+Makefile.in
+/aclocal.m4
+/autom4te.cache
+/compile
+/config.*
+/configure
+/depcomp
+/install-sh
+/missing
+/stamp-h1
+/ylwrap
 
 # Debian package build temporary files
 build-stamp
diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 0000000..c988bf2
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1,3 @@
+# -*- Makefile -*-
+
+SUBDIRS = doc files/nftables src
diff --git a/Makefile.defs.in b/Makefile.defs.in
deleted file mode 100644
index 545c4ee..0000000
--- a/Makefile.defs.in
+++ /dev/null
@@ -1,40 +0,0 @@
-DEBUG		= @CONFIG_DEBUG@
-CC		= @CC@
-CPP		= @CPP@
-LEX		= @LEX@
-YACC		= @YACC@
-MKDIR_P		= @MKDIR_P@
-INSTALL		= @INSTALL@
-
-PACKAGE_TARNAME	= @PACKAGE_TARNAME@
-
-prefix		= @prefix@
-exec_prefix	= @exec_prefix@
-sysconfdir	= @sysconfdir@
-datarootdir	= @datarootdir@
-mandir		= @mandir@
-docdir		= @docdir@
-pdfdir		= @pdfdir@
-confdir		= @sysconfdir@/nftables
-
-LDFLAGS		+= @LDFLAGS@
-LDFLAGS		+= @LIBS@
-
-CPPFLAGS	+= @CPPFLAGS@
-
-CFLAGS		+= @CFLAGS@ @DEFS@
-CFLAGS		+= -DDEFAULT_INCLUDE_PATH="\"$(confdir)\""
-CFLAGS		+= -include config.h
-CFLAGS		+= -Iinclude
-CFLAGS		+= -fno-strict-aliasing
-
-CFLAGS		+= -Wall -Werror
-CFLAGS		+= -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations
-CFLAGS		+= -Wdeclaration-after-statement -Wsign-compare -Winit-self
-CFLAGS		+= -Wformat-nonliteral -Wformat-security -Wmissing-format-attribute
-CFLAGS		+= -Wcast-align -Wundef -Wbad-function-cast # -Wshadow
-CFLAGS		+= -Waggregate-return -Wunused -Wwrite-strings
-
-ifeq ($(DEBUG),y)
-CFLAGS		+= -g -DDEBUG
-endif
diff --git a/Makefile.in b/Makefile.in
deleted file mode 100644
index 5d42541..0000000
--- a/Makefile.in
+++ /dev/null
@@ -1,5 +0,0 @@
-SUBDIRS		+= src
-SUBDIRS		+= files
-SUBDIRS		+= doc
-
-include Makefile.rules
diff --git a/configure.ac b/configure.ac
index d8a850c..0227817 100644
--- a/configure.ac
+++ b/configure.ac
@@ -20,32 +20,30 @@ AC_ARG_ENABLE([debug],
 AC_SUBST([CONFIG_DEBUG])
 
 # Checks for programs.
+AM_INIT_AUTOMAKE([-Wall foreign subdir-objects])
 AC_PROG_CC
+AM_PROG_CC_C_O
 AC_PROG_MKDIR_P
-AC_PROG_INSTALL
-
-AC_CHECK_PROG(CONFIG_MAN, docbook2x-man, y, n)
-if test "$CONFIG_MAN" != "y"
-then
+AM_PROG_INSTALL
+AC_PROG_LEX
+AC_PROG_YACC
+
+AC_ARG_WITH([confdir], AS_HELP_STRING([--with-confdir=PATH],
+	[Path to the nftables config directory [[SYSCONFDIR/nftables]]]),
+	[confdir="$withval"], [confdir='${sysconfdir}/${PACKAGE_NAME}'])
+AC_SUBST([confdir])
+
+AC_CHECK_PROGS([DB2MAN], [docbook2x-man docbook-to-man])
+AM_CONDITIONAL([CONFIG_DOC_MAN], [test -n "$DB2MAN"])
+if test -z "$DB2MAN"; then
 	AC_MSG_WARN([docbookx2-man not found, no manpages will be built])
 fi
 
-AC_CHECK_PROG(CONFIG_PDF, db2pdf, y, n)
-if test "$CONFIG_PDF" != "y"
-then
-	AC_MSG_WARN([db2pdf not found, no PDF manpages will be built])
-fi
 
-AC_PATH_PROG(LEX, [flex])
-if test -z "$LEX"
-then
-	AC_MSG_ERROR([No suitable version of flex found])
-fi
-
-AC_PATH_PROG(YACC, [bison])
-if test -z "$YACC"
-then
-	AC_MSG_ERROR([No suitable version of bison found])
+AC_CHECK_PROGS([DB2PDF], [db2pdf])
+AM_CONDITIONAL([CONFIG_DOC_PDF], [test -n "$DB2PDF"])
+if test -z "$DB2PDF"; then
+	AC_MSG_WARN([db2pdf not found, no PDF manpages will be built])
 fi
 
 # Checks for libraries.
@@ -94,6 +92,14 @@ AC_FUNC_MALLOC
 AC_FUNC_REALLOC
 AC_CHECK_FUNCS([memmove memset strchr strdup strerror strtoull])
 
-AC_CONFIG_FILES([Makefile Makefile.defs Makefile.rules])
-AC_CONFIG_FILES([src/Makefile doc/Makefile files/Makefile])
+regular_CFLAGS="-D_FILE_OFFSET_BITS=64 -D_REENTRANT -Wall -Waggregate-return \
+	-Wbad-function-cast -Wcast-align -Wdeclaration-after-statement \
+	-Werror -Wformat=2 -Winit-self -Winline -Wmissing-declarations \
+	-Wmissing-format-attribute -Wmissing-prototypes \
+	-Wsign-compare -Wstrict-prototypes -Wundef -Wunused \
+	-Wwrite-strings -fno-strict-aliasing -pipe";
+AC_SUBST([regular_CFLAGS])
+
+AC_CONFIG_FILES([Makefile])
+AC_CONFIG_FILES([src/Makefile doc/Makefile files/nftables/Makefile])
 AC_OUTPUT
diff --git a/doc/.gitignore b/doc/.gitignore
index fc24d49..21300b7 100644
--- a/doc/.gitignore
+++ b/doc/.gitignore
@@ -1,2 +1,2 @@
-nftables.8
-nftables.pdf
+/nftables.8
+/nftables.pdf
diff --git a/doc/Makefile.am b/doc/Makefile.am
new file mode 100644
index 0000000..27bd6c1
--- /dev/null
+++ b/doc/Makefile.am
@@ -0,0 +1,18 @@
+# -*- Makefile -*-
+
+man8_MANS =
+doc_DATA =
+
+if CONFIG_DOC_MAN
+man8_MANS += nftables.8
+endif
+
+if CONFIG_DOC_PDF
+doc_DATA += nftables.pdf
+endif
+
+nftables.8: nftables.xml
+	${AM_V_GEN}docbook2x-man $<
+
+nftables.pdf: nftables.xml
+	${AM_V_GEN}db2pdf -o . $<
diff --git a/doc/Makefile.in b/doc/Makefile.in
deleted file mode 100644
index 2c42d7e..0000000
--- a/doc/Makefile.in
+++ /dev/null
@@ -1,20 +0,0 @@
-mandocs-@CONFIG_MAN@	+= doc/nftables.8
-pdfdocs-@CONFIG_PDF@	+= doc/nftables.pdf
-
-all:		$(mandocs-y) $(pdfdocs-y)
-clean:
-		@echo -e "  CLEAN\t\tdoc"
-		$(RM) $(mandocs-y) $(pdfdocs-y)
-
-install:	$(mandocs-y) $(pdfdocs-y)
-		@echo -e "  INSTALL\tdoc"
-		if test -n "$(mandocs-y)"; then \
-			$(MKDIR_P) $(DESTDIR)/${mandir}/man8 ;\
-			$(INSTALL) -m 755 -o root -g root $(mandocs-y) \
-					$(DESTDIR)/${mandir}/man8/ ;\
-		fi
-		if test -n "$(pdfdocs-y)"; then \
-			$(MKDIR_P) $(DESTDIR)/${pdfdir} ;\
-			$(INSTALL) -m 755 -o root -g root $(pdfdocs-y) \
-					$(DESTDIR)/${pdfdir}/ ;\
-		fi
diff --git a/files/Makefile.in b/files/Makefile.in
deleted file mode 100644
index cd67c37..0000000
--- a/files/Makefile.in
+++ /dev/null
@@ -1,4 +0,0 @@
-install:
-	@echo -e "  INSTALL\tfiles"
-	$(MKDIR_P) $(DESTDIR)/$(confdir)
-	$(INSTALL) -m 755 -o root -g root $(SUBDIR)nftables/* $(DESTDIR)/$(confdir)/
diff --git a/files/nftables/Makefile.am b/files/nftables/Makefile.am
new file mode 100644
index 0000000..c45167c
--- /dev/null
+++ b/files/nftables/Makefile.am
@@ -0,0 +1,4 @@
+# -*- Makefile -*-
+
+conf_DATA = ipv4-filter ipv4-mangle ipv4-raw ipv4-security \
+	ipv6-filter ipv6-mangle ipv6-raw ipv6-security
diff --git a/install-sh b/install-sh
deleted file mode 100755
index d4744f0..0000000
--- a/install-sh
+++ /dev/null
@@ -1,269 +0,0 @@
-#!/bin/sh
-#
-# install - install a program, script, or datafile
-#
-# This originates from X11R5 (mit/util/scripts/install.sh), which was
-# later released in X11R6 (xc/config/util/install.sh) with the
-# following copyright and license.
-#
-# Copyright (C) 1994 X Consortium
-#
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to
-# deal in the Software without restriction, including without limitation the
-# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
-# sell copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-#
-# The above copyright notice and this permission notice shall be included in
-# all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
-# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
-# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-#
-# Except as contained in this notice, the name of the X Consortium shall not
-# be used in advertising or otherwise to promote the sale, use or other deal-
-# ings in this Software without prior written authorization from the X Consor-
-# tium.
-#
-#
-# FSF changes to this file are in the public domain.
-#
-# Calling this script install-sh is preferred over install.sh, to prevent
-# `make' implicit rules from creating a file called install from it
-# when there is no Makefile.
-#
-# This script is compatible with the BSD install script, but was written
-# from scratch.  It can only install one file at a time, a restriction
-# shared with many OS's install programs.
-
-
-# set DOITPROG to echo to test this script
-
-# Don't use :- since 4.3BSD and earlier shells don't like it.
-doit="${DOITPROG-}"
-
-
-# put in absolute paths if you don't have them in your path; or use env. vars.
-
-mvprog="${MVPROG-mv}"
-cpprog="${CPPROG-cp}"
-chmodprog="${CHMODPROG-chmod}"
-chownprog="${CHOWNPROG-chown}"
-chgrpprog="${CHGRPPROG-chgrp}"
-stripprog="${STRIPPROG-strip}"
-rmprog="${RMPROG-rm}"
-mkdirprog="${MKDIRPROG-mkdir}"
-
-transformbasename=""
-transform_arg=""
-instcmd="$mvprog"
-chmodcmd="$chmodprog 0755"
-chowncmd=""
-chgrpcmd=""
-stripcmd=""
-rmcmd="$rmprog -f"
-mvcmd="$mvprog"
-src=""
-dst=""
-dir_arg=""
-
-while [ x"$1" != x ]; do
-    case $1 in
-	-c) instcmd="$cpprog"
-	    shift
-	    continue;;
-
-	-d) dir_arg=true
-	    shift
-	    continue;;
-
-	-m) chmodcmd="$chmodprog $2"
-	    shift
-	    shift
-	    continue;;
-
-	-o) chowncmd="$chownprog $2"
-	    shift
-	    shift
-	    continue;;
-
-	-g) chgrpcmd="$chgrpprog $2"
-	    shift
-	    shift
-	    continue;;
-
-	-s) stripcmd="$stripprog"
-	    shift
-	    continue;;
-
-	-t=*) transformarg=`echo $1 | sed 's/-t=//'`
-	    shift
-	    continue;;
-
-	-b=*) transformbasename=`echo $1 | sed 's/-b=//'`
-	    shift
-	    continue;;
-
-	*)  if [ x"$src" = x ]
-	    then
-		src=$1
-	    else
-		# this colon is to work around a 386BSD /bin/sh bug
-		:
-		dst=$1
-	    fi
-	    shift
-	    continue;;
-    esac
-done
-
-if [ x"$src" = x ]
-then
-	echo "install:	no input file specified"
-	exit 1
-else
-	true
-fi
-
-if [ x"$dir_arg" != x ]; then
-	dst=$src
-	src=""
-	
-	if [ -d $dst ]; then
-		instcmd=:
-		chmodcmd=""
-	else
-		instcmd=mkdir
-	fi
-else
-
-# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
-# might cause directories to be created, which would be especially bad 
-# if $src (and thus $dsttmp) contains '*'.
-
-	if [ -f $src -o -d $src ]
-	then
-		true
-	else
-		echo "install:  $src does not exist"
-		exit 1
-	fi
-	
-	if [ x"$dst" = x ]
-	then
-		echo "install:	no destination specified"
-		exit 1
-	else
-		true
-	fi
-
-# If destination is a directory, append the input filename; if your system
-# does not like double slashes in filenames, you may need to add some logic
-
-	if [ -d $dst ]
-	then
-		dst="$dst"/`basename $src`
-	else
-		true
-	fi
-fi
-
-## this sed command emulates the dirname command
-dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
-
-# Make sure that the destination directory exists.
-#  this part is taken from Noah Friedman's mkinstalldirs script
-
-# Skip lots of stat calls in the usual case.
-if [ ! -d "$dstdir" ]; then
-defaultIFS=' 	
-'
-IFS="${IFS-${defaultIFS}}"
-
-oIFS="${IFS}"
-# Some sh's can't handle IFS=/ for some reason.
-IFS='%'
-set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
-IFS="${oIFS}"
-
-pathcomp=''
-
-while [ $# -ne 0 ] ; do
-	pathcomp="${pathcomp}${1}"
-	shift
-
-	if [ ! -d "${pathcomp}" ] ;
-        then
-		$mkdirprog "${pathcomp}"
-	else
-		true
-	fi
-
-	pathcomp="${pathcomp}/"
-done
-fi
-
-if [ x"$dir_arg" != x ]
-then
-	$doit $instcmd $dst &&
-
-	if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
-	if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
-	if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
-	if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
-else
-
-# If we're going to rename the final executable, determine the name now.
-
-	if [ x"$transformarg" = x ] 
-	then
-		dstfile=`basename $dst`
-	else
-		dstfile=`basename $dst $transformbasename | 
-			sed $transformarg`$transformbasename
-	fi
-
-# don't allow the sed command to completely eliminate the filename
-
-	if [ x"$dstfile" = x ] 
-	then
-		dstfile=`basename $dst`
-	else
-		true
-	fi
-
-# Make a temp file name in the proper directory.
-
-	dsttmp=$dstdir/#inst.$$#
-
-# Move or copy the file name to the temp name
-
-	$doit $instcmd $src $dsttmp &&
-
-	trap "rm -f ${dsttmp}" 0 &&
-
-# and set any options; do chmod last to preserve setuid bits
-
-# If any of these fail, we abort the whole thing.  If we want to
-# ignore errors from any of these, just make sure not to ignore
-# errors from the above "$doit $instcmd $src $dsttmp" command.
-
-	if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
-	if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
-	if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
-	if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
-
-# Now rename the file to the real destination.
-
-	$doit $rmcmd -f $dstdir/$dstfile &&
-	$doit $mvcmd $dsttmp $dstdir/$dstfile 
-
-fi &&
-
-
-exit 0
diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644
index 0000000..b55a579
--- /dev/null
+++ b/src/Makefile.am
@@ -0,0 +1,22 @@
+# -*- Makefile -*-
+
+AM_CFLAGS = ${regular_CFLAGS} -I${top_srcdir}/include \
+            -DDEFAULT_INCLUDE_PATH=\"${confdir}\"
+AM_LFLAGS = --header-file=$(<:.l=.h)
+AM_YFLAGS = -d --skeleton=../../../../../../../../${abs_srcdir}/parser-skeleton.c
+
+CLEANFILES = parser.c parser.h scanner.c scanner.h
+
+sbin_PROGRAMS = nft
+
+nft_SOURCES = \
+	scanner.l parser.y \
+	main.c cli.c rule.c statement.c datatype.c expression.c \
+	evaluate.c payload.c exthdr.c meta.c ct.c netlink.c \
+	netlink_linearize.c netlink_delinearize.c segtree.c rbtree.c \
+	gmputil.c utils.c erec.c
+
+parser.y: scanner.c
+
+scanner.c scanner.h: scanner.l
+	${AM_V_LEX}${LEX} --header-file=$(<:.l=.h) -t $< >$@
diff --git a/src/Makefile.in b/src/Makefile.in
deleted file mode 100644
index 3c93307..0000000
--- a/src/Makefile.in
+++ /dev/null
@@ -1,30 +0,0 @@
-PROGRAMS		+= nft
-YACCFLAGS               += --skeleton=../../..$(shell pwd)/src/parser-skeleton.c
-
-nft-destdir		:= @sbindir@
-
-nft-obj			+= main.o
-nft-obj			+= cli.o
-nft-obj			+= rule.o
-nft-obj			+= statement.o
-nft-obj			+= datatype.o
-nft-obj			+= expression.o
-nft-obj			+= evaluate.o
-nft-obj			+= payload.o
-nft-obj			+= exthdr.o
-nft-obj			+= meta.o
-nft-obj			+= ct.o
-nft-obj			+= netlink.o
-nft-obj			+= netlink_linearize.o
-nft-obj			+= netlink_delinearize.o
-nft-obj			+= segtree.o
-nft-obj			+= rbtree.o
-nft-obj			+= gmputil.o
-nft-obj			+= utils.o
-nft-obj			+= erec.o
-
-nft-obj			+= parser.o
-nft-extra-clean-files	+= parser.c parser.h
-
-nft-obj			+= scanner.o
-nft-extra-clean-files	+= scanner.c scanner.h
diff --git a/src/cli.c b/src/cli.c
index bb519f4..1de572a 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -12,6 +12,7 @@
  * Development of this code funded by Astaro AG (http://www.astaro.com/)
  */
 
+#include "config.h"
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdarg.h>
diff --git a/src/erec.c b/src/erec.c
index 501bf4b..75f1f7e 100644
--- a/src/erec.c
+++ b/src/erec.c
@@ -8,6 +8,7 @@
  * Development of this code funded by Astaro AG (http://www.astaro.com/)
  */
 
+#include "config.h"
 #include <stdio.h>
 #include <string.h>
 #include <stdarg.h>
diff --git a/src/main.c b/src/main.c
index 11dd21e..2fa540c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -24,6 +24,7 @@
 #include <rule.h>
 #include <netlink.h>
 #include <erec.h>
+#include "config.h"
 
 unsigned int numeric_output;
 
-- 
1.6.2

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netfitler Users]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux