diff options
context:
space:
mode:
authorBryce Kwon <bryce@brycekwon.com>
committerBryce Kwon <bryce@brycekwon.com>
commit
parent
tree
download
Reorganize and simplify the Makefile
Diffstat (limited to 'source')
-rw-r--r--source/cgit.mk55
1 file changed, 30 insertions, 25 deletions
diff --git a/source/cgit.mk b/source/cgit.mk
index 661d351..f864ecb 100644
--- a/source/cgit.mk
+++ b/source/cgit.mk
@@ -4,14 +4,19 @@
#
# make -C libraries/git -f ../../source/cgit.mk ../../build/cgit
#
-# so every path back into the project is prefixed with "../../": sources come
-# from ../../source and all build output goes to ../../build.
+# so every path back into the project reaches through CGIT_ROOT ("../.."):
+# sources come from ../../source and all build output goes to ../../build.
include Makefile
-# Locations relative to libraries/git, where this file is run.
-CGIT_PREFIX = ../../
-CGIT_SRC = $(CGIT_PREFIX)source/
-CGIT_BUILD = $(CGIT_PREFIX)build/
+# Locations relative to libraries/git, where this file is run. SRCDIR and
+# BUILDDIR name the root-relative subdirs (matching the top-level Makefile and
+# used by the version recipe, which cds to the root); CGIT_SRC and CGIT_BUILD
+# are their full paths from here.
+CGIT_ROOT = ../..
+SRCDIR = source
+BUILDDIR = build
+CGIT_SRC = $(CGIT_ROOT)/$(SRCDIR)
+CGIT_BUILD = $(CGIT_ROOT)/$(BUILDDIR)
# Emit zero-initialised globals as plain definitions instead of common
# symbols, the default everywhere but Apple clang. ld64 otherwise derives
@@ -20,14 +25,14 @@ CGIT_BUILD = $(CGIT_PREFIX)build/
# CFLAGS (as tools/release-build.sh passes) still keeps the flag.
override CFLAGS += -fno-common
--include $(CGIT_PREFIX)cgit.conf
+-include $(CGIT_ROOT)/cgit.conf
# The CGIT_* variables are inherited from the top-level Makefile.
-$(CGIT_BUILD)VERSION: force-version
- @mkdir -p $(CGIT_BUILD)
- @cd $(CGIT_PREFIX) && '$(SHELL_PATH_SQ)' source/gen-version.sh "$(CGIT_VERSION)" build/VERSION
--include $(CGIT_BUILD)VERSION
+$(CGIT_BUILD)/VERSION: force-version
+ @mkdir -p $(CGIT_BUILD)/
+ @cd $(CGIT_ROOT) && '$(SHELL_PATH_SQ)' $(SRCDIR)/gen-version.sh "$(CGIT_VERSION)" $(BUILDDIR)/VERSION
+-include $(CGIT_BUILD)/VERSION
.PHONY: force-version
# CGIT_CFLAGS is tracked separately so that changing it does not force a
@@ -111,12 +116,12 @@ CGIT_OBJ_NAMES += ui-summary.o
CGIT_OBJ_NAMES += ui-tag.o
CGIT_OBJ_NAMES += ui-tree.o
-CGIT_OBJS := $(addprefix $(CGIT_BUILD),$(CGIT_OBJ_NAMES))
+CGIT_OBJS := $(addprefix $(CGIT_BUILD)/,$(CGIT_OBJ_NAMES))
# Only cgit.c references CGIT_VERSION, so only its objects rebuild when the
# version changes.
-CGIT_VERSION_OBJS := $(addprefix $(CGIT_BUILD),cgit.o cgit.sp)
-$(CGIT_VERSION_OBJS): $(CGIT_BUILD)VERSION
+CGIT_VERSION_OBJS := $(addprefix $(CGIT_BUILD)/,cgit.o cgit.sp)
+$(CGIT_VERSION_OBJS): $(CGIT_BUILD)/VERSION
$(CGIT_VERSION_OBJS): EXTRA_CPPFLAGS = \
-DCGIT_VERSION='"$(CGIT_VERSION)"'
@@ -128,31 +133,31 @@ ifneq ($(cgit_dep_files_present),)
include $(cgit_dep_files_present)
endif
-ifeq ($(wildcard $(CGIT_BUILD).depend),)
-missing_dep_dirs += $(CGIT_BUILD).depend
+ifeq ($(wildcard $(CGIT_BUILD)/.depend),)
+missing_dep_dirs += $(CGIT_BUILD)/.depend
endif
-$(CGIT_BUILD).depend:
+$(CGIT_BUILD)/.depend:
@mkdir -p $@
-$(CGIT_BUILD)CGIT-CFLAGS: FORCE
- @mkdir -p $(CGIT_BUILD)
+$(CGIT_BUILD)/CGIT-CFLAGS: FORCE
+ @mkdir -p $(CGIT_BUILD)/
@FLAGS='$(subst ','\'',$(CGIT_CFLAGS))'; \
- if test x"$$FLAGS" != x"`cat $(CGIT_BUILD)CGIT-CFLAGS 2>/dev/null`" ; then \
+ if test x"$$FLAGS" != x"`cat $(CGIT_BUILD)/CGIT-CFLAGS 2>/dev/null`" ; then \
echo 1>&2 " * new CGit build flags"; \
- echo "$$FLAGS" >$(CGIT_BUILD)CGIT-CFLAGS; \
+ echo "$$FLAGS" >$(CGIT_BUILD)/CGIT-CFLAGS; \
fi
-$(CGIT_OBJS): $(CGIT_BUILD)%.o: $(CGIT_SRC)%.c GIT-CFLAGS $(CGIT_BUILD)CGIT-CFLAGS $(missing_dep_dirs)
+$(CGIT_OBJS): $(CGIT_BUILD)/%.o: $(CGIT_SRC)/%.c GIT-CFLAGS $(CGIT_BUILD)/CGIT-CFLAGS $(missing_dep_dirs)
$(QUIET_CC)$(CC) -o $@ -c $(dep_args) $(ALL_CFLAGS) $(EXTRA_CPPFLAGS) $(CGIT_CFLAGS) $<
-$(CGIT_BUILD)cgit: $(CGIT_OBJS) GIT-LDFLAGS $(GITLIBS)
- @echo 1>&1 " * $(LUA_MESSAGE)"
+$(CGIT_BUILD)/cgit: $(CGIT_OBJS) GIT-LDFLAGS $(GITLIBS)
+ @echo 1>&2 " * $(LUA_MESSAGE)"
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS) $(CGIT_LIBS)
CGIT_SP_OBJS := $(patsubst %.o,%.sp,$(CGIT_OBJS))
-$(CGIT_SP_OBJS): $(CGIT_BUILD)%.sp: $(CGIT_SRC)%.c GIT-CFLAGS $(CGIT_BUILD)CGIT-CFLAGS FORCE
+$(CGIT_SP_OBJS): $(CGIT_BUILD)/%.sp: $(CGIT_SRC)/%.c GIT-CFLAGS $(CGIT_BUILD)/CGIT-CFLAGS FORCE
$(QUIET_SP)cgcc -no-compile $(ALL_CFLAGS) $(EXTRA_CPPFLAGS) $(CGIT_CFLAGS) $(SPARSE_FLAGS) $<
cgit-sparse: $(CGIT_SP_OBJS)