diff options
author | Paul Moore <pmoore@redhat.com> | 2012-02-20 12:54:38 -0500 |
---|---|---|
committer | Paul Moore <pmoore@redhat.com> | 2012-02-20 12:54:38 -0500 |
commit | 7f747337f5252fad16c8aa549f1d0457e4c6cb34 (patch) | |
tree | 69ae818e745d3922776c5c63d892f16ac5cfff2d | |
parent | 83406138c4b578365df0d3ff61b07d04c29539e6 (diff) | |
download | libseccomp-7f747337f5252fad16c8aa549f1d0457e4c6cb34.tar.gz |
build: generate and use automated dependencies
Signed-off-by: Paul Moore <pmoore@redhat.com>
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | macros.mk | 22 | ||||
-rw-r--r-- | src/Makefile | 5 | ||||
-rw-r--r-- | tests/Makefile | 18 | ||||
-rw-r--r-- | tools/Makefile | 15 |
5 files changed, 37 insertions, 24 deletions
@@ -1,6 +1,7 @@ *~ *.a *.o +*.d *.swp *.orig .stgit-* @@ -45,6 +45,18 @@ CFLAGS ?= -O0 -g -Wall LDFLAGS ?= -g # +# auto dependencies +# + +# we require gcc specific functionality (see the MAKEDEP* definitions below) +GCC ?= gcc + +MAKEDEP = @$(GCC) $(INCFLAGS) -MM -MF $(patsubst %.o,%.d,$@) $<; +MAKEDEP_EXEC = \ + @$(GCC) $(INCFLAGS) -MM -MT $(patsubst %.d,%,$@) \ + -MF $@ $(patsubst %.d,%.c,$@); + +# # build constants # @@ -54,8 +66,8 @@ VERSION_HDR = src/version.h # build macros # -ARCHIVE = @echo " AR $@ (add/update: $?)"; $(AR) -cru $@ $?; -COMPILE = @echo " CC $@"; $(CC) $(CFLAGS) $(INCFLAGS) -o $*.o -c $<; +ARCHIVE = @echo " AR $@ (add/update: $?)"; $(AR) -cru $@ $?; +COMPILE = @echo " CC $@"; $(CC) $(CFLAGS) $(INCFLAGS) -o $@ -c $<; COMPILE_EXEC = @echo " CC $@"; $(CC) $(CFLAGS) $(INCFLAGS) -o $@ $< $(LDFLAGS); LINK_EXEC = @echo " LD $@"; $(CC) $(LDFLAGS) -o $@ $^ $(LIBFLAGS); LINK_LIB = @echo " LD $@ "; $(CC) $(LDFLAGS) -o $@ $^ -shared -Wl,-soname=$@; @@ -64,8 +76,6 @@ LINK_LIB = @echo " LD $@ "; $(CC) $(LDFLAGS) -o $@ $^ -shared -Wl,-soname=$@; # default build targets # -.c.o: +%.o: %.c + $(MAKEDEP) $(COMPILE) - - - diff --git a/src/Makefile b/src/Makefile index e78d395..d8bff22 100644 --- a/src/Makefile +++ b/src/Makefile @@ -35,6 +35,7 @@ LIB_STATIC = libseccomp.a LIB_SHARED = libseccomp.so.$(VERSION_RELEASE) OBJS = api.o db.o hash.o gen_pfc.o gen_bpf.o +DEPS = $(OBJS:%.o=%.d) INCFLAGS := $(INCFLAGS) -I../include @@ -46,8 +47,10 @@ INCFLAGS := $(INCFLAGS) -I../include all: $(LIB_STATIC) +-include $(DEPS) + $(LIB_STATIC): $(OBJS) $(ARCHIVE) clean: - $(RM) -f $(OBJS) $(LIB_STATIC) $(LIB_SHARED) + $(RM) -f $(DEPS) $(OBJS) $(LIB_STATIC) $(LIB_SHARED) diff --git a/tests/Makefile b/tests/Makefile index 3f26f6f..eff53fa 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -43,6 +43,8 @@ TESTS = 01-basic \ 03-chains-pfc \ 04-chains-bpf +DEPS = $(TESTS:%=%.d) + # # targets # @@ -51,19 +53,13 @@ TESTS = 01-basic \ all: $(TESTS) -# XXX - find a better way to do this using $(TESTS) - -01-basic: 01-basic.c - $(COMPILE_EXEC) - -02-basic-pfc: 02-basic-pfc.c - $(COMPILE_EXEC) +-include $(DEPS) -03-chains-pfc: 03-chains-pfc.c - $(COMPILE_EXEC) +$(DEPS): + $(MAKEDEP_EXEC) -04-chains-bpf: 04-chains-bpf.c +$(TESTS): $(COMPILE_EXEC) clean: - $(RM) -f $(TESTS) + $(RM) -f $(DEPS) $(TESTS) diff --git a/tools/Makefile b/tools/Makefile index 1985242..5ef61ec 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -33,7 +33,10 @@ include ../macros.mk # configuration # -TOOLS = bpf_disasm bpf_sim +TOOLS = bpf_disasm \ + bpf_sim + +DEPS = $(TOOLS:%=%.d) # # targets @@ -43,13 +46,13 @@ TOOLS = bpf_disasm bpf_sim all: $(TOOLS) -# XXX - find a better way to do this using $(TOOLS) +-include $(DEPS) -bpf_disasm: bpf_disasm.c - $(COMPILE_EXEC) +$(DEPS): + $(MAKEDEP_EXEC) -bpf_sim: bpf_sim.c +$(TOOLS): $(COMPILE_EXEC) clean: - $(RM) -f $(TOOLS) + $(RM) -f $(DEPS) $(TOOLS) |