From 96a4f76f2e9dad7fdbd6fd7740de44bc90d5769e Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Thu, 18 Dec 2008 16:05:18 -0500 Subject: Unify all common build system parts Rather than duplicating the same thing over and over in every Makefile, move it all to common.mk. Other things fixed here: - doing subdirs in parallel - fix src!=build compiling in subdirs Signed-off-by: Mike Frysinger Signed-off-by: Artem Bityutskiy --- common.mk | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 common.mk (limited to 'common.mk') diff --git a/common.mk b/common.mk new file mode 100644 index 0000000..5dd21ab --- /dev/null +++ b/common.mk @@ -0,0 +1,58 @@ +CC := $(CROSS)gcc +AR := $(CROSS)ar +RANLIB := $(CROSS)ranlib +CFLAGS ?= -O2 -g +CFLAGS += -Wall -Wwrite-strings -W + +DESTDIR ?= /usr/local +PREFIX=/usr +EXEC_PREFIX=$(PREFIX) +SBINDIR=$(EXEC_PREFIX)/sbin +MANDIR=$(PREFIX)/share/man +INCLUDEDIR=$(PREFIX)/include + +ifndef BUILDDIR +ifeq ($(origin CROSS),undefined) + BUILDDIR := $(PWD) +else +# Remove the trailing slash to make the directory name + BUILDDIR := $(PWD)/$(CROSS:-=) +endif +endif + +override TARGETS := $(addprefix $(BUILDDIR)/,$(TARGETS)) + +SUBDIRS_ALL = $(patsubst %,subdirs_%_all,$(SUBDIRS)) +SUBDIRS_CLEAN = $(patsubst %,subdirs_%_clean,$(SUBDIRS)) +SUBDIRS_INSTALL = $(patsubst %,subdirs_%_install,$(SUBDIRS)) + +all:: $(TARGETS) $(SUBDIRS_ALL) + +clean:: $(SUBDIRS_CLEAN) + rm -f $(BUILDDIR)/*.o $(TARGETS) $(BUILDDIR)/.*.c.dep + +install:: $(TARGETS) $(SUBDIRS_INSTALL) + +$(BUILDDIR)/%: $(BUILDDIR)/%.o + $(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_$(notdir $@)) -g -o $@ $^ $(LDLIBS) $(LDLIBS_$(notdir $@)) + +$(BUILDDIR)/%.a: + $(AR) crv $@ $^ + $(RANLIB) $@ + +$(BUILDDIR)/%.o: %.c + mkdir -p $(dir $@) + $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $< -g -Wp,-MD,$(BUILDDIR)/.$(