summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@netsurf-browser.org>2009-02-14 15:56:52 +0000
committerDaniel Silverstone <dsilvers@netsurf-browser.org>2009-02-14 15:56:52 +0000
commit41124cff3e5e20f7b7542bdfec653ef8e852c306 (patch)
treea73fb0bfe92f66cb127312a31e29cb69980a77a6 /Makefile
parentbe1ffaeca7cdb002d30817383aeb1f47fe9df79b (diff)
downloadlibwapcaplet-41124cff3e5e20f7b7542bdfec653ef8e852c306.tar.gz
libwapcaplet-41124cff3e5e20f7b7542bdfec653ef8e852c306.tar.bz2
100% of tests pass. Ship it.
svn path=/trunk/libwapcaplet/; revision=6497
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile89
1 files changed, 89 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..d15458a
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,89 @@
+# Simple Makefile for libwapcaplet
+
+LIB := libwapcaplet.a
+
+SRCS := libwapcaplet.c
+HDRS := libwapcaplet/libwapcaplet.h
+
+TESTSRCS := testmain.c basictests.c
+
+TARGET ?= debug
+
+BUILDDIR := build-$(TARGET)
+
+all: $(BUILDDIR)/$(LIB)
+
+test: $(BUILDDIR)/testrunner
+ $(BUILDDIR)/testrunner
+
+CFLAGS := -Iinclude -Wall -Werror
+
+ifeq ($(TARGET),debug)
+CFLAGS += -O0 -g
+else
+CFLAGS += -O2
+endif
+
+
+clean:
+ rm -fr build-*
+
+$(BUILDDIR)/stamp:
+ mkdir -p $(BUILDDIR)
+ touch $(BUILDDIR)/stamp
+
+define srcfile
+src/$1
+endef
+
+define objfile
+$(BUILDDIR)/$(1:.c=.o)
+endef
+
+define depfile
+$(BUILDDIR)/$(1:.c=.d)
+endef
+
+DEPS :=
+OBJS :=
+
+define _depandbuild
+
+$2: $1 $(BUILDDIR)/stamp
+ $(CC) -MMD -MP $($5) -o $2 -c $1
+
+$4 += $2
+DEPS += $3
+
+endef
+
+define depandbuild
+$(call _depandbuild,$(call srcfile,$1),$(call objfile,$1),$(call depfile,$1),OBJS,CFLAGS)
+endef
+
+$(eval $(foreach SOURCE,$(SRCS),$(call depandbuild,$(SOURCE))))
+
+ifneq ($(MAKECMDGOALS),clean)
+-include $(DEPS)
+endif
+
+$(BUILDDIR)/$(LIB): $(BUILDDIR)/stamp $(OBJS)
+ $(AR) cru $@ $^
+
+define testsrc
+test/$1
+endef
+
+define depandbuildtest
+$(call _depandbuild,$(call testsrc,$1),$(call objfile,test-$1),$(call depfile,test-$1),TOBJS,TESTCFLAGS)
+endef
+
+TOBJS :=
+
+TESTCFLAGS := $(CFLAGS) $(shell pkg-config --cflags check)
+TESTLDFLAGS := $(LDFLAGS) $(shell pkg-config --libs check)
+
+$(eval $(foreach TESTSRC,$(TESTSRCS),$(call depandbuildtest,$(TESTSRC))))
+
+$(BUILDDIR)/testrunner: $(BUILDDIR)/stamp $(TOBJS) $(BUILDDIR)/$(LIB)
+ $(CC) -o $@ $(TOBJS) $(BUILDDIR)/$(LIB) $(TESTLDFLAGS)