From b72e8567723c30f0e5a83675743e9380c48e5d55 Mon Sep 17 00:00:00 2001 From: "Suren A. Chilingaryan" Date: Sun, 13 Feb 2011 03:07:11 +0100 Subject: Initial import --- common.mk | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 common.mk (limited to 'common.mk') diff --git a/common.mk b/common.mk new file mode 100644 index 0000000..1758acd --- /dev/null +++ b/common.mk @@ -0,0 +1,55 @@ +# Compiler and default flags +CC ?= gcc +CFLAGS ?= -O2 + + +# Defaults for directories +ROOTDIR ?= $(shell pwd) + +INCDIR ?= $(ROOTDIR) +BINDIR ?= $(ROOTDIR) +LIBDIR ?= $(ROOTDIR) +OBJDIR ?= $(ROOTDIR) +DEPENDDIR ?= $(ROOTDIR) + +CXXFLAGS += $(addprefix -I ,$(INCDIR)) +CFLAGS += $(addprefix -I ,$(INCDIR)) + +# Source files in this directory +SRC = $(wildcard *.cpp) +SRCC = $(wildcard *.c) + +# Corresponding object files +OBJ = $(addprefix $(OBJDIR)/,$(SRC:.cpp=.o)) +OBJ += $(addprefix $(OBJDIR)/,$(SRCC:.c=.o)) + +# Corresponding dependency files +DEPEND = $(addprefix $(DEPENDDIR)/,$(SRC:.cpp=.d)) +DEPEND += $(addprefix $(DEPENDDIR)/,$(SRCC:.c=.d)) + +# This makes Verbose easier. Just prefix $(Q) to any command +ifdef VERBOSE + Q ?= +else + Q ?= @ +endif + +############################################################### +# Target definitions + +# Target for automatic dependency generation +depend: $(DEPEND) $(DEPENDC); + +# This rule generates a dependency makefile for each source +$(DEPENDDIR)/%.d: %.c + @echo -e "DEPEND \t$<" + $(Q)$(CC) $(addprefix -I ,$(INCDIR)) -MM -MF $@ \ + -MT $(OBJDIR)/$(<:.c=.o) -MT $@ $< + +# This includes the automatically +# generated dependency files +-include $(DEPEND) + +$(OBJDIR)/%.o: %.c + @echo -e "CC \t$<" + $(Q)@$(CC) $(CFLAGS) -c -o $@ $< -- cgit v1.2.3