use my nice build system rather than custom makefiles
authorPierre Habouzit <madcoder@debian.org>
Fri, 10 Nov 2006 22:04:52 +0000 (23:04 +0100)
committerPierre Habouzit <madcoder@debian.org>
Fri, 10 Nov 2006 22:04:52 +0000 (23:04 +0100)
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
19 files changed:
.gitignore
Makefile [new file with mode: 0644]
am/.gitignore [new file with mode: 0644]
am/cflags.mk [new file with mode: 0644]
am/footer.mk [new file with mode: 0644]
am/header.mk [new file with mode: 0644]
am/vars.mk.in [new file with mode: 0644]
configure.ac
madtty/.gitignore [new file with mode: 0644]
madtty/Makefile [new file with mode: 0644]
madtty/Makefile.in [moved from Makefile.in with 54% similarity]
madtty/inject.c [moved from inject.c with 100% similarity]
madtty/inject_csi.c [moved from inject_csi.c with 100% similarity]
madtty/inject_csi.h [moved from inject_csi.h with 100% similarity]
madtty/madtty.h [moved from madtty.h with 100% similarity]
madtty/madtty.pc.in [moved from madtty.pc.in with 100% similarity]
madtty/rote.c [moved from rote.c with 100% similarity]
madtty/rote_keymap.c [moved from rote_keymap.c with 100% similarity]
madtty/roteprivate.h [moved from roteprivate.h with 100% similarity]

index 12c0349..a48f4ca 100644 (file)
@@ -1,9 +1,4 @@
-*.o
-*.so*
 config.*
-
 .depends
 autom4te.cache
 configure
-madtty.pc
-Makefile
diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..e36fd9f
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,7 @@
+DEPTH=.
+include $(DEPTH)/am/header.mk
+
+SUBDIRS = madtty
+
+include $(DEPTH)/am/footer.mk
+# vim:set ft=automake:
diff --git a/am/.gitignore b/am/.gitignore
new file mode 100644 (file)
index 0000000..05c6144
--- /dev/null
@@ -0,0 +1 @@
+vars.mk
diff --git a/am/cflags.mk b/am/cflags.mk
new file mode 100644 (file)
index 0000000..cde512c
--- /dev/null
@@ -0,0 +1,54 @@
+ifneq (,$(filter gcc%,$(CC)))
+    _gccversion:=$(shell $(CC) -dumpversion)
+    _gccmachine:=$(shell $(CC) -dumpmachine)
+    _cobjs := .objs-$(_gccmachine:-linux-gnu=)-$(_gccversion)
+
+    # Use pipes and not temp files.
+    CFLAGS += -pipe
+    # optimize even more
+    CFLAGS += -O2
+    # let the type char be unsigned by default
+    CFLAGS += -funsigned-char
+    CFLAGS += -fstrict-aliasing
+    # turn on all common warnings
+    CFLAGS += -Wall
+    # turn on extra warnings
+    CFLAGS += $(if $(filter 4.%,$(GCCVERSION)),-W,-Wextra)
+    # treat warnings as errors
+    CFLAGS += -Werror
+    CFLAGS += -Wchar-subscripts
+    # warn about undefined preprocessor identifiers
+    CFLAGS += -Wundef
+    # warn about local variable shadowing another local variable
+    CFLAGS += -Wshadow
+    # warn about casting of pointers to increased alignment requirements
+    CFLAGS += -Wcast-align
+    # make string constants const
+    CFLAGS += -Wwrite-strings
+    # warn about implicit conversions with side effects
+    # fgets, calloc and friends take an int, not size_t...
+    #CFLAGS += -Wconversion
+    # warn about comparisons between signed and unsigned values
+    CFLAGS += -Wsign-compare
+    # warn about unused declared stuff
+    CFLAGS += -Wunused
+    # don not warn about unused return value
+    CFLAGS += -Wno-unused-value
+    # warn about variable use before initialization
+    CFLAGS += -Wuninitialized
+    # warn about pointer arithmetic on void* and function pointers
+    CFLAGS += -Wpointer-arith
+    # warn about multiple declarations
+    CFLAGS += -Wredundant-decls
+    # warn if the format string is not a string literal
+    CFLAGS += -Wformat-nonliteral
+    # do not warn about strftime format with y2k issues
+    CFLAGS += -Wno-format-y2k
+
+    CFLAGS += -I$(DEPTH)
+else
+    CFLAGS += -Wall
+    _cobjs := .objs
+endif
+
+LDFLAGS += -Wl,--warn-common
diff --git a/am/footer.mk b/am/footer.mk
new file mode 100644 (file)
index 0000000..5b935b7
--- /dev/null
@@ -0,0 +1,99 @@
+#[ Rules and Depends ]##################################################{{{#
+
+AUTO_DEPENDS += filter_c
+filter_c = $(addprefix $2/,$(patsubst %.c,%.o,$(filter %.c,$1)))
+
+# this is some ad-hoc last resort dependency method
+%.a: FORCE
+       @$(MAKE) -q -rC $(dir $(@D)) $(_cobjs)/$(@F) || $(MAKE) -rC $(dir $(@D)) $(_cobjs)/$(@F)
+
+# this implicit rule is used to force directory existence, without depending
+# on the directory itself, since its mtime changes too often.
+%/.exists: Makefile $(CONFDIR)/$(wildcard *.mk)
+       @$(RM) -r $*
+       @-mkdir -p $*
+       @touch $@
+# We don't want make to remove these files because of default rules.
+.PRECIOUS: %/.exists
+
+define RULE_C_tpl
+$(_cobjs)/$1/%.o: %.c $(_cobjs)/$1/.exists
+       $(CC) $$(CFLAGS) $$($1_CPPFLAGS) $2 -MMD -MT "$$(@D)/$$*.d $$(@D)/$$*.o" -MF $$(@D)/$$*.d -g -c -o $$@ $$<
+
+$(_cobjs)/$1/%.d: %.c $(_cobjs)/$1/.exists
+       @$(CPP) $$(CFLAGS) $$($1_CPPFLAGS) $2 -MM -MT "$$(@D)/$$*.d $$(@D)/$$*.o" -MF $$(@D)/$$*.d $$<
+
+-include $$(wildcard $(_cobjs)/$1/*.d) /dev/null
+endef
+
+########################################################################}}}#
+#[ Classes ]############################################################{{{#
+
+deps_create = $(foreach f,$(AUTO_DEPENDS),$(call $f,$1,$2))
+
+define CLASS_LIBRARIES_tpl
+all:: $1.so
+
+$1.so: $(_cobjs)/$1/.exists $$(call deps_create,$$($1_SOURCES),$(_cobjs)/$1)
+       $(CC) $$(CFLAGS) $$($1_CPPFLAGS) -fPIC -shared -o $$@ \
+           $$(filter %.o,$$^) $$(LDFLAGS) $$($1_LDFLAGS) $$($1_LIBADD)
+
+$$(eval $$(call RULE_C_tpl,$1,-fPIC $2))
+
+clean::
+       $(RM) $1.so
+endef
+$(foreach l, \
+    $(foreach l,$(filter %_LIBRARIES,$(.VARIABLES)),$($l)), \
+    $(eval $(call CLASS_LIBRARIES_tpl,$l,)))
+
+#define CLASS_EXE_tpl
+#all:: $1
+#$1: $(_cobjs)/$1/.exists $$(call deps_create,$$($1_SOURCES),$(_cobjs)/$1)
+#      $(CC) -o $$@ $$(CFLAGS) $$($1_CPPFLAGS) $$(filter %.o,$$^) \
+#               $$(LDFLAGS) $$($1_LDFLAGS) $$(filter %.a,$$^)
+#
+#$$(eval $$(call RULE_C_tpl,$1,$2))
+#
+#clean::
+#      $(RM) $1
+#endef
+#$(foreach x,$(__EXE__),$(eval $(call CLASS_EXE_tpl,$x,)))
+
+########################################################################}}}#
+#[ Candy ]##############################################################{{{#
+
+echo-root:
+       @echo $(DEPTH)
+
+echo-tags:
+       @echo $(DEPTH)/.tags
+
+ifeq (".","$(DEPTH)")
+tags:
+       ctags -o .$@ --recurse=yes --exclude=.svn --exclude=\*.mk --totals=yes;
+
+distclean clober::
+       $(RM) -f .tags
+else
+tags:
+       $(MAKE) -C $(DEPTH) $@
+endif
+
+.PHONY: tags
+
+########################################################################}}}#
+
+all check clobber distclean::
+       @set -e $(patsubst %,; $(MAKE) -rC % $@,$(SUBDIRS))
+
+CLEAN_RECURSE=1
+clean::
+       $(RM) -r $(_cobjs)
+       @$(if $(CLEAN_RECURSE),$(patsubst %,$(MAKE) -rC % $@;,$(SUBDIRS)))
+
+clobber distclean:: CLEAN_RECURSE=
+clobber distclean:: clean
+       $(RM) -r .objs*
+
+.PHONY: all check clean clobber distclean FORCE
diff --git a/am/header.mk b/am/header.mk
new file mode 100644 (file)
index 0000000..1309171
--- /dev/null
@@ -0,0 +1,16 @@
+# Disable most default rules
+.SUFFIXES:
+
+# where is admin/ wrt us ?
+CONFDIR := $(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
+
+ifeq ("","$(DEPTH)")
+    $(error you have to define DEPTH)
+endif
+
+include $(CONFDIR)/vars.mk
+include $(CONFDIR)/cflags.mk
+
+# trick : make all always be the default target !
+# note that it breaks default Makefile semantics
+all::
diff --git a/am/vars.mk.in b/am/vars.mk.in
new file mode 100644 (file)
index 0000000..e0bece1
--- /dev/null
@@ -0,0 +1,10 @@
+CC=@CC@
+CFLAGS=@CFLAGS@
+LDFLAGS=@LDFLAGS@
+
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+bindir=@bindir@
+
index 29d47f0..4fbfb79 100644 (file)
@@ -5,7 +5,7 @@ AC_INIT([maddty], 0.0.0)
 AC_SUBST(PACKAGE_NAME)
 AC_SUBST(PACKAGE_VERSION)
 
-AC_CONFIG_SRCDIR([rote.c])
+AC_CONFIG_SRCDIR([madtty/madtty.h])
 
 dnl Checks for programs.
 AC_PROG_CC
@@ -44,6 +44,6 @@ AC_C_INLINE
 AC_TYPE_PID_T
 AC_TYPE_SIGNAL
 
-AC_CONFIG_FILES([Makefile madtty.pc])
+AC_CONFIG_FILES([am/vars.mk madtty/madtty.pc])
 AC_OUTPUT
 
diff --git a/madtty/.gitignore b/madtty/.gitignore
new file mode 100644 (file)
index 0000000..9beaa91
--- /dev/null
@@ -0,0 +1 @@
+madtty.pc
diff --git a/madtty/Makefile b/madtty/Makefile
new file mode 100644 (file)
index 0000000..da4af4c
--- /dev/null
@@ -0,0 +1,12 @@
+DEPTH=..
+include $(DEPTH)/am/header.mk
+
+lib_LIBRARIES = libmadtty
+libmadtty_SOURCES = inject.c inject_csi.c inject_csi.h madtty.h rote.c rote_keymap.c roteprivate.h
+libmadtty_CPPFLAGS = -Wno-error
+libmadtty_LDFLAGS =
+libmadtty_LIBADD =
+
+include $(DEPTH)/am/footer.mk
+
+# vim:set ft=automake:
similarity index 54%
rename from Makefile.in
rename to madtty/Makefile.in
index 318c1f4..d2760cd 100644 (file)
@@ -1,33 +1,15 @@
-# Makefile for libmadtty
-# 
-# LICENSE INFORMATION:
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public
-# License as published by the Free Software Foundation; either
-# version 2 of the License, or (at your option) any later version.
-# 
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# General Public License for more details.
-# 
-# You should have received a copy of the GNU General Public
-# License along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
-#
-# Copyright © 2002-2004 Bruno T. C. de Oliveira
-# Copyright © 2006 Pierre Habouzit
+DEPTH=..
+include $(DEPTH)/admin/header.mk
 
-SOURCES=$(wildcard *.c)
-HEADERS=$(wildcard *.h)
+__LIB__ = madtty
 
-OBJECTS=$(patsubst %.c,%.o,$(SOURCES))
+madtty_SOURCES = inject.c inject_csi.c inject_csi.h madtty.h rote.c rote_keymap.c roteprivate.h
 
 MADTTY_VERSION=@PACKAGE_VERSION@
 MADTTY_SONAME=libmadtty.so.0
 
 CC=@CC@
-CFLAGS=@CFLAGS@ -Wall -fPIC
+CFLAGS=@CFLAGS@ -Wall -W -fPIC
 LIBS=@LIBS@
 LDFLAGS=@LDFLAGS@
 prefix=@prefix@
@@ -36,7 +18,7 @@ libdir=@libdir@
 includedir=@includedir@
 bindir=@bindir@
 
-all: libmadtty.so.$(MADTTY_VERSION)
+#all: libmadtty.so.$(MADTTY_VERSION)
 
 install: all
        mkdir -p $(DESTDIR)$(includedir)/madtty
@@ -63,11 +45,10 @@ libmadtty.so.$(MADTTY_VERSION): $(OBJECTS)
 
 -include .depends
 
-clean:
-       rm -f *.o .depends libmadtty.so.*
+clean::
+       libmadtty.so.*
 
-pristine: clean
+distclean::
        rm -rf autom4te.cache configure config.status config.log Makefile madtty.pc
 
-.PHONY: clean all install pristine
-
+include $(DEPTH)/admin/footer.mk
similarity index 100%
rename from inject.c
rename to madtty/inject.c
similarity index 100%
rename from inject_csi.c
rename to madtty/inject_csi.c
similarity index 100%
rename from inject_csi.h
rename to madtty/inject_csi.h
similarity index 100%
rename from madtty.h
rename to madtty/madtty.h
similarity index 100%
rename from madtty.pc.in
rename to madtty/madtty.pc.in
similarity index 100%
rename from rote.c
rename to madtty/rote.c
similarity index 100%
rename from rote_keymap.c
rename to madtty/rote_keymap.c
similarity index 100%
rename from roteprivate.h
rename to madtty/roteprivate.h