summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Thiago Macieira <thiago@macieira.org>2013-04-13 11:30:05 -0700
committerGravatar Thiago Macieira <thiago@macieira.org>2013-04-23 00:06:32 -0700
commitce3f073d422d03d473ff18e6793a9228fb02fa12 (patch)
treeb2720bab29e9d2716b3059b842d3b6c63897daa0
parenta0b523a5afc91c3816f6c44e61f8a05d5fe5e80a (diff)
downloadsubsurface-ce3f073d422d03d473ff18e6793a9228fb02fa12.tar.gz
Generate the C++ dependencies at configure-time
We use the -MG preprocessor option to the compiler to ask it to check all #includes and tell us what's missing. Then our own rules will generate the moc and uic files that the .cpp #include. Unfortunately, our rules make uic generate output in qt-ui/ for qt-ui/*.ui, while the compiler generates rules for no directory. We need to fake it by forcing the generation. Signed-off-by: Thiago Macieira <thiago@macieira.org>
-rw-r--r--Rules.mk26
1 files changed, 15 insertions, 11 deletions
diff --git a/Rules.mk b/Rules.mk
index bc135aab7..56ef8813a 100644
--- a/Rules.mk
+++ b/Rules.mk
@@ -35,7 +35,7 @@ all: $(NAME)
$(NAME): gen_version_file $(ALL_OBJS) $(MSGOBJS) $(INFOPLIST)
$(CXX) $(LDFLAGS) -o $(NAME) $(ALL_OBJS) $(LIBS)
-gen_version_file:
+gen_version_file $(VERSION_FILE):
ifneq ($(STORED_VERSION_STRING),$(VERSION_STRING))
$(info updating $(VERSION_FILE) to $(VERSION_STRING))
@echo \#define VERSION_STRING \"$(VERSION_STRING)\" >$(VERSION_FILE)
@@ -142,13 +142,6 @@ MOCFLAGS = $(filter -I%, $(CXXFLAGS) $(EXTRA_FLAGS)) $(filter -D%, $(CXXFLAGS) $
@mkdir -p .dep .dep/qt-ui
@$(CXX) $(CXXFLAGS) $(EXTRA_FLAGS) -MD -MF .dep/$@.dep -c -o $@ $<
-# Detect which files require the moc or uic tools to be run
-CPP_NEEDING_MOC = $(shell grep -l -s '^\#include \".*\.moc\"' $(OBJS:.o=.cpp))
-OBJS_NEEDING_MOC += $(CPP_NEEDING_MOC:.cpp=.o)
-
-CPP_NEEDING_UIC = $(shell grep -l -s '^\#include \"ui_.*\.h\"' $(OBJS:.o=.cpp))
-OBJS_NEEDING_UIC += $(CPP_NEEDING_UIC:.cpp=.o)
-
# This rule is for running the moc on QObject subclasses defined in the .h
# files.
%.moc.cpp: %.h
@@ -167,8 +160,12 @@ ui_%.h: %.ui
@echo ' UIC' $<
@$(UIC) $< -o $@
-$(OBJS_NEEDING_MOC): %.o: %.moc
-$(OBJS_NEEDING_UIC): qt-ui/%.o: qt-ui/ui_%.h
+# This forces the creation of ui headers with the wrong path
+# This is required because the -MG option to the compiler outputs
+# unknown files with no path prefix
+ui_%.h: qt-ui/%.ui
+ @echo ' UIC' $<
+ @$(UIC) $< -o qt-ui/$@
share/locale/%.UTF-8/LC_MESSAGES/subsurface.mo: po/%.po po/%.aliases
mkdir -p $(dir $@)
@@ -198,10 +195,17 @@ doc:
clean:
rm -f $(ALL_OBJS) *~ $(NAME) $(NAME).exe po/*~ po/subsurface-new.pot \
$(VERSION_FILE) qt-ui/*.moc qt-ui/ui_*.h
- rm -rf share .dep
+ rm -rf share
confclean: clean
rm -f $(CONFIGFILE)
+ rm -rf .dep
+
+ifneq ($(CONFIGURED)$(CONFIGURING),)
+.dep/%.o.dep: %.cpp
+ @mkdir -p .dep .dep/qt-ui
+ @$(CXX) $(CXXFLAGS) $(EXTRA_FLAGS) -MM -MG -MF $@ -MT $(<:.cpp=.o) -c $<
+endif
DEPS = $(addprefix .dep/,$(C_SOURCES:.c=.o.dep) $(CXX_SOURCES:.cpp=.o.dep))
-include $(DEPS)