-#########################
-sp := $(sp).x
-dirstack_$(sp) := $(d)
-d := $(dir)
-#########################
-
-#
-# Include the subdirectories--order is not important.
-#
-
-dir := $(d)/moof
-include $(dir)/rules.mk
-
-dir := $(d)/stlplus
-include $(dir)/rules.mk
-
-
#
# Define rules and targets for Yoink.
#
-OBJECTS_$(d) := $(patsubst %.c,%.o,$(wildcard $(d)/*.c)) \
- $(patsubst %.cc,%.o,$(wildcard $(d)/*.cc))
-D_FILES_$(d) := $(OBJECTS_$(d):%=%.d)
+$(call include,moof stlplus) # Recurse into subdirectories.
+
+objects = $(patsubst %.c,$(builddir)/%.o,$(patsubst %.cc,$(builddir)/%.o,$(wildcard $d/*.c $d/*.cc)))
-ifeq ($(HOST),win32)
-OBJECTS_$(d) += $(d)/yoink.o
+ifeq (win32,$(platform))
+objects += $b/win32.o # Also compile win32 resource file.
endif
-PROGRAM_$(d) := $(call add_exe_suffix,$(d)/yoink)
+ifeq (true,$(includeConfig))
+objects += $b/config.o # Also compile in the configuration.
+exec += $b/config.gz
+exec += $b/config.c # Make config.c a build target.
+$b/config.gz: config.mk
+ $(Q)$(gzip)
+$b/config.c: $b/config.gz
+ $(Q)$(xxd)
+endif
-BINARIES := $(BINARIES) $(PROGRAM_$(d))
-CLEAN := $(CLEAN) $(OBJECTS_$(d)) $(D_FILES_$(d)) $(PROGRAM_$(d))
+$(objects): TGT_CFLAGS := -I$b -I$d
+$(objects): config.h | $b
+# Make all objects depend on config.h; it's excessive, but config.h won't be
+# remade otherwise if dependencies are not being generated. The alternative
+# is to maintain an accurate list of objects with a dependency on config.h.
-$(OBJECTS_$(d)): CF_TGT := -I$(d)
-$(OBJECTS_$(d)): $(d)/rules.mk
+ifeq (true,$(pch))
+$(objects): $b/moof/precompile.hh.gch
+endif
-$(PROGRAM_$(d)): $(OBJECTS_$(d)) $(d)/moof/libmoof.a $(d)/stlplus/libstlplus.a
- $(DO_LDX)
+exec += $(objects) # Make the objects build targets.
+bindir_$b := $b/$(projectName)$(EXEEXT) # Install executable to bindir.
+$(bindir_$b): $(objects) $b/moof/libmoof.a $b/stlplus/libstlplus.a
+ $(Q)$(link_cc)
#
# Define the run and debug targets.
#
-YOINK_ENVIRONMENT = YOINK_DATADIR="./data"
-
-.PHONY: run
-run: $(PROGRAM_$(d))
- @$(YOINK_ENVIRONMENT) $< $(YOINK_OPTS)
-
-.PHONY: debug
-debug: $(PROGRAM_$(d))
- @$(YOINK_ENVIRONMENT) gdb $<
+run: $(bindir_$b)
+ $(Q)$< $(YOINKFLAGS)
+debug: $(bindir_$b)
+ $(Q)gdb $<
-########################
--include $(D_FILES_$(d))
-d := $(dirstack_$(sp))
-sp := $(basename $(sp))
-########################
+.PHONY: run debug