summaryrefslogtreecommitdiff
path: root/common.mk
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2008-12-18 16:05:18 -0500
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2008-12-22 10:13:37 +0200
commit96a4f76f2e9dad7fdbd6fd7740de44bc90d5769e (patch)
tree9367832bd2a5df10897fa7f2835cc4b24f468c87 /common.mk
parentef1e909207cd901871d60a916e4b7ff7b3e97d7d (diff)
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 <vapier@gentoo.org> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Diffstat (limited to 'common.mk')
-rw-r--r--common.mk58
1 files changed, 58 insertions, 0 deletions
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)/.$(<F).dep
+
+subdirs_%:
+ d=$(patsubst subdirs_%,%,$@); \
+ t=`echo $$d | sed s:.*_::` d=`echo $$d | sed s:_.*::`; \
+ $(MAKE) BUILDDIR=$(BUILDDIR)/$$d -C $$d $$t
+
+.SUFFIXES:
+
+IGNORE=${wildcard $(BUILDDIR)/.*.c.dep}
+-include ${IGNORE}
+
+PHONY += all clean install
+.PHONY: $(PHONY)