# The variable `CGIRLSDIR´ is used to point back to the directory containing the C·Girls code.
CGIRLSDIR := ..
cgirls : $(CGIRLSDIR)/cgirls
-PHONY : cgirls
+.PHONY : cgirls
include Makefile
# The `gen-version.sh´ script updates the `VERSION´ file when·ever the version changes.
$(CGIRLSDIR)/VERSION : VERSIONFORCE
@cd '$(CGIRLSDIR)' && $(SHELL_PATH_SQ) sh/gen-version.sh VERSION
VERSIONFORCE : ;
-PHONY : VERSIONFORCE
+.PHONY : VERSIONFORCE
-include $(CGIRLSBUILDDIR)/VERSION
# `CGIRLS_CFLAGS´ is a separate variable so that it can be tracked separately, to avoid rebuilding all of Git when these variables change.
CGIRLS_H_SOURCES = $(filter %.h,$(CGIRLS_SOURCE_FILES))
# `CGIRLS_OBJS´ lists the object files which this make·file is expected to create.
-# These are listed one per line to make merges easier.
-# `CGIRLSBUILDDIR´ is added as a prefix at the end.
-CGIRLS_OBJS :=
-CGIRLS_OBJS += cgirls.o
-CGIRLS_OBJS := $(addprefix $(CGIRLSDIR)/,$(CGIRLS_OBJS))
+# `CGIRLS_TESTOBJS´ lists the additional object files used for the testing programs.
+CGIRLS_OBJS := $(patsubst %.c,%.o,$(shell find '$(CGIRLSDIR)' '(' -path '$(CGIRLSDIR)' -o -prune ')' -a -type f -a -name '*.c' -a '!' -name 'cgirls-test-*.c'))
+CGIRLS_TESTOBJS := $(patsubst %.c,%.o,$(shell find '$(CGIRLSDIR)' '(' -path '$(CGIRLSDIR)' -o -prune ')' -a -type f -a -name 'cgirls-test-*.c'))
+CGIRLS_TESTS := $(patsubst %.o,%,$(CGIRLS_TESTOBJS))
+
+# `CGIRLS_ALLOBJS´ contains both `CGIRLS_OBJS´ and `CGIRLS_TESTOBJS´.
+CGIRLS_ALLOBJS = $(CGIRLS_OBJS) $(CGIRLS_TESTOBJS)
# Only `cgirls.c´ references CGIRLS_VERSION so we only rebuild its objects when the version changes.
CGIRLS_VERSION_OBJS := $(CGIRLSDIR)/cgirls.o
# Git handles dependencies using `:=´, so they have already been computed by this point.
# We have to manage the dependency files for `CGIRLS_OBJS´ ourselves.
-cgirls_dep_files := $(foreach f,$(CGIRLS_OBJS),$(dir $f).depend/$(notdir $f).d)
-cgirls_dep_dirs := $(addsuffix .depend,$(sort $(dir $(CGIRLS_OBJS))))
+cgirls_dep_files := $(foreach f,$(CGIRLS_ALLOBJS),$(dir $f).depend/$(notdir $f).d)
+cgirls_dep_dirs := $(addsuffix .depend,$(sort $(dir $(CGIRLS_ALLOBJS))))
ifeq ($(COMPUTE_HEADER_DEPENDENCIES),yes)
$(cgirls_dep_dirs) :
@mkdir -p $@
include $(cgirls_dep_files_present)
endif
else
-$(CGIRLS_OBJS) : $(CGIRLS_H_SOURCES) $(LIB_H) $(GENERATED_H)
+$(CGIRLS_ALLOBJS) : $(CGIRLS_H_SOURCES) $(LIB_H) $(GENERATED_H)
endif
+# At this point, all the variables have been defined.
+# Include custom modifications, if defined.
+-include $(CGIRLSDIR)/make/config.mak
+
# This saves the value of `CGIRLS_CFLAGS´ to force a rebuild of `CGIRLS_OBJS´ if the flags should change.
$(CGIRLSDIR)/CGIRLS-CFLAGS : FORCE
@FLAGS='$(subst ','"'"',$(CGIRLS_CFLAGS))'; \
fi
# Objects are built and linked the same as with Git, except depending on the additional `CGIRLS-CFLAGS´ file and using `ALL_CGIRLS_CFLAGS´ in place of `ALL_CFLAGS´.
-$(CGIRLS_OBJS) : $(CGIRLSDIR)/%.o : $(CGIRLSDIR)/%.c GIT-CFLAGS $(CGIRLSDIR)/CGIRLS-CFLAGS $(missing_dep_dirs)
+$(CGIRLS_ALLOBJS) : $(CGIRLSDIR)/%.o : $(CGIRLSDIR)/%.c GIT-CFLAGS $(CGIRLSDIR)/CGIRLS-CFLAGS $(missing_dep_dirs)
$(QUIET_CC)$(CC) -o $@ -c $(dep_args) $(ALL_CGIRLS_CFLAGS) $(EXTRA_CPPFLAGS) $<
$(CGIRLSDIR)/cgirls : $(CGIRLS_OBJS) GIT-LDFLAGS $(GITLIBS)
- $(QUIET_LINK)$(CC) $(ALL_CGIRLS_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(sort $(LIBS))
+ $(QUIET_LINK)$(CC) $(ALL_CGIRLS_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
+$(CGIRLS_TESTS) : $(CGIRLSDIR)/% : $(CGIRLSDIR)/%.o $(filter-out $(CGIRLSDIR)/cgirls.o,$(CGIRLS_OBJS)) GIT-LDFLAGS $(GITLIBS)
+ $(QUIET_LINK)$(CC) $(ALL_CGIRLS_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
+cgirls-tests : $(CGIRLS_TESTS) ;
+.PHONY : cgirls-tests