(svn r1917) - Makefile: Revamped VERBOSE support, build mechanics changed.

- VERBOSE has now greater effect, many previously hidden commands
    are now shown on the terminal as they are executed. (Use $(Q)
    instead of @ where the command should be shown if VERBOSE.)
  - Compilation commands redundancy was eliminated.
  - Compilation commands calling generalized so that the VERBOSE
    support does not further entangle the code. The commands are now
    all at a single place, before the targets in a "Build commands"
    section.

Note that this changeset has a character of proposal. If you do not
like the direction it takes at all, feel free to revert it (probably
together with the previous VERBOSE patch). However, I believe it
improves the code by bringing the compilation commands to a single
place and it greatly improves the VERBOSE support, too (and makes it
much less intrusive).
This commit is contained in:
pasky 2005-03-01 01:14:27 +00:00
parent 319a41ed84
commit 7f78acebef

227
Makefile
View File

@ -681,6 +681,46 @@ LANG_TXT = $(filter-out %.unfinished.txt,$(wildcard lang/*.txt))
LANGS = $(LANG_TXT:%.txt=%.lng) LANGS = $(LANG_TXT:%.txt=%.lng)
##############################################################################
#
# Build commands
#
# If we are verbose, we will show commands prefixed by $(Q) (which acts as
# @ in the non-verbose mode), and we will show the "real" cmds instead of
# their quiet versions (which are used in the non-verbose mode).
# Inspired by the Linux kernel build system.
ifdef VERBOSE
Q =
quiet =
else
Q = @
quiet = quiet_
endif
# Show the command (quiet or non-quiet version based on the assignment
# just above) and then execute it.
cmd = @$(if $($(quiet)cmd_$(1)),echo $($(quiet)cmd_$(1)) &&) $(cmd_$(1))
# The build commands themselves. Note that if you omit the quiet version,
# nothing will be shown in the non-verbose mode.
quiet_cmd_compile_link = '===> Compiling and Linking $@'
cmd_compile_link = $(CC) $(BASECFLAGS) $(CDEFS) $< -o $@
quiet_cmd_ttd_link = '===> Linking $@'
cmd_ttd_link = $(CC) $(LDFLAGS) $(TTDLDFLAGS) $(OBJS) $(LIBS) -o $@
COMPILE_PARAMS=$(CFLAGS) $(CDEFS) -MD -c $< -o $@
quiet_cmd_c_compile = '===> Compiling $<'
cmd_c_compile = $(CC) $(COMPILE_PARAMS)
quiet_cmd_cxx_compile = '===> Compiling $<'
cmd_cxx_compile = $(CXX) $(COMPILE_PARAMS)
############################################################################## ##############################################################################
# #
# Targets # Targets
@ -699,37 +739,31 @@ all: endian.h $(UPDATECONFIG) $(LANGS) $(TTD) $(OSX) $(endwarnings)
endian.h: $(ENDIAN_CHECK) endian.h: $(ENDIAN_CHECK)
@echo '===> Testing endianness' @echo '===> Testing endianness'
@./$(ENDIAN_CHECK) > $@ $(Q)./$(ENDIAN_CHECK) > $@
$(ENDIAN_CHECK): endian_check.c $(ENDIAN_CHECK): endian_check.c
@echo '===> Compiling and Linking $@' $(call cmd,compile_link)
@$(CC) $(BASECFLAGS) $(CDEFS) endian_check.c -o $@
$(TTD): table/strings.h $(OBJS) $(MAKE_CONFIG) $(TTD): table/strings.h $(OBJS) $(MAKE_CONFIG)
@if [ ! "$(VERBOSE)" ]; then \ $(call cmd,ttd_link)
echo '===> Linking $@'; \
else \
echo $(CC) $(LDFLAGS) $(TTDLDFLAGS) $(OBJS) $(LIBS) -o $@; \
fi
@$(CC) $(LDFLAGS) $(TTDLDFLAGS) $(OBJS) $(LIBS) -o $@
$(OSX): $(TTD) $(OSX): $(TTD)
@rm -fr "$(OSXAPP)" $(Q)rm -fr "$(OSXAPP)"
@mkdir -p "$(OSXAPP)"/Contents/MacOS $(Q)mkdir -p "$(OSXAPP)"/Contents/MacOS
@mkdir -p "$(OSXAPP)"/Contents/Resources $(Q)mkdir -p "$(OSXAPP)"/Contents/Resources
@mkdir -p "$(OSXAPP)"/Contents/Data $(Q)mkdir -p "$(OSXAPP)"/Contents/Data
@mkdir -p "$(OSXAPP)"/Contents/Lang $(Q)mkdir -p "$(OSXAPP)"/Contents/Lang
@echo "APPL????" > "$(OSXAPP)"/Contents/PkgInfo $(Q)echo "APPL????" > "$(OSXAPP)"/Contents/PkgInfo
@cp os/macos/openttd.icns "$(OSXAPP)"/Contents/Resources/openttd.icns $(Q)cp os/macos/openttd.icns "$(OSXAPP)"/Contents/Resources/openttd.icns
@os/macos/plistgen.sh "$(OSXAPP)" "$(REV)" $(Q)os/macos/plistgen.sh "$(OSXAPP)" "$(REV)"
@cp os/macos/track_starter "$(OSXAPP)"/contents/macos $(Q)cp os/macos/track_starter "$(OSXAPP)"/contents/macos
@ls os/macos | grep -q "\.class" || \ $(Q)ls os/macos | grep -q "\.class" || \
javac os/macos/OpenTTDMidi.java $(Q) javac os/macos/OpenTTDMidi.java
@cp os/macos/OpenTTDMidi.class "$(OSXAPP)"/contents/macos $(Q)cp os/macos/OpenTTDMidi.class "$(OSXAPP)"/contents/macos
@cp data/* "$(OSXAPP)"/Contents/data/ $(Q)cp data/* "$(OSXAPP)"/Contents/data/
@cp lang/*.lng "$(OSXAPP)"/Contents/lang/ $(Q)cp lang/*.lng "$(OSXAPP)"/Contents/lang/
@cp $(TTD) "$(OSXAPP)"/Contents/MacOS/$(TTD) $(Q)cp $(TTD) "$(OSXAPP)"/Contents/MacOS/$(TTD)
$(endwarnings): $(64_bit_warnings) $(endwarnings): $(64_bit_warnings)
@ -738,51 +772,50 @@ $(64_bit_warnings):
$(warning If you see any bugs, include in your bug report that you use a 64 bit CPU) $(warning If you see any bugs, include in your bug report that you use a 64 bit CPU)
$(STRGEN): strgen/strgen.c endian.h $(STRGEN): strgen/strgen.c endian.h
@echo '===> Compiling and Linking $@' $(call cmd,compile_link)
@$(CC) $(BASECFLAGS) $(CDEFS) -o $@ $<
table/strings.h: lang/english.txt $(STRGEN) table/strings.h: lang/english.txt $(STRGEN)
@echo '===> Generating $@' @echo '===> Generating $@'
@$(STRGEN) $(Q)$(STRGEN)
lang/%.lng: lang/%.txt $(STRGEN) lang/english.txt lang/%.lng: lang/%.txt $(STRGEN) lang/english.txt
@echo '===> Compiling language $(*F)' @echo '===> Compiling language $(*F)'
@$(STRGEN) $(STRGEN_FLAGS) $< $(LANG_ERRORS) $(Q)$(STRGEN) $(STRGEN_FLAGS) $< $(LANG_ERRORS)
winres.o: ttd.rc winres.o: ttd.rc
@echo '===> Compiling resource $<' @echo '===> Compiling resource $<'
@windres -o $@ $< $(Q)windres -o $@ $<
ifdef MORPHOS ifdef MORPHOS
release: all release: all
@rm -fr "/t/openttd-$(RELEASE)-morphos.lha" $(Q)rm -fr "/t/openttd-$(RELEASE)-morphos.lha"
@mkdir -p "/t/" $(Q)mkdir -p "/t/"
@mkdir -p "/t/openttd-$(RELEASE)-morphos" $(Q)mkdir -p "/t/openttd-$(RELEASE)-morphos"
@mkdir -p "/t/openttd-$(RELEASE)-morphos/docs" $(Q)mkdir -p "/t/openttd-$(RELEASE)-morphos/docs"
@mkdir -p "/t/openttd-$(RELEASE)-morphos/data" $(Q)mkdir -p "/t/openttd-$(RELEASE)-morphos/data"
@mkdir -p "/t/openttd-$(RELEASE)-morphos/lang" $(Q)mkdir -p "/t/openttd-$(RELEASE)-morphos/lang"
@mkdir -p "/t/openttd-$(RELEASE)-morphos/scenario" $(Q)mkdir -p "/t/openttd-$(RELEASE)-morphos/scenario"
@cp -R $(TTD) "/t/openttd-$(RELEASE)-morphos/" $(Q)cp -R $(TTD) "/t/openttd-$(RELEASE)-morphos/"
@cp data/* "/t/openttd-$(RELEASE)-morphos/data/" $(Q)cp data/* "/t/openttd-$(RELEASE)-morphos/data/"
@cp lang/*.lng "/t/openttd-$(RELEASE)-morphos/lang/" $(Q)cp lang/*.lng "/t/openttd-$(RELEASE)-morphos/lang/"
@cp scenario/* "/t/openttd-$(RELEASE)-morphos/scenario/" $(Q)cp scenario/* "/t/openttd-$(RELEASE)-morphos/scenario/"
@cp readme.txt "/t/openttd-$(RELEASE)-morphos/docs/ReadMe" $(Q)cp readme.txt "/t/openttd-$(RELEASE)-morphos/docs/ReadMe"
@cp docs/console.txt "/t/openttd-$(RELEASE)-morphos/docs/Console" $(Q)cp docs/console.txt "/t/openttd-$(RELEASE)-morphos/docs/Console"
@cp COPYING "/t/openttd-$(RELEASE)-morphos/docs/" $(Q)cp COPYING "/t/openttd-$(RELEASE)-morphos/docs/"
@cp changelog.txt "/t/openttd-$(RELEASE)-morphos/docs/ChangeLog" $(Q)cp changelog.txt "/t/openttd-$(RELEASE)-morphos/docs/ChangeLog"
@cp known-bugs.txt "/t/openttd-$(RELEASE)-morphos/docs/known-bugs.txt" $(Q)cp known-bugs.txt "/t/openttd-$(RELEASE)-morphos/docs/known-bugs.txt"
@cp os/morphos/icons/openttd.info "/t/openttd-$(RELEASE)-morphos/$(TTD).info" $(Q)cp os/morphos/icons/openttd.info "/t/openttd-$(RELEASE)-morphos/$(TTD).info"
@cp os/morphos/icons/docs.info "/t/openttd-$(RELEASE)-morphos/docs.info" $(Q)cp os/morphos/icons/docs.info "/t/openttd-$(RELEASE)-morphos/docs.info"
@cp os/morphos/icons/drawer.info "/t/openttd-$(RELEASE)-morphos.info" $(Q)cp os/morphos/icons/drawer.info "/t/openttd-$(RELEASE)-morphos.info"
@cp os/morphos/icons/document.info "/t/openttd-$(RELEASE)-morphos/docs/ReadMe.info" $(Q)cp os/morphos/icons/document.info "/t/openttd-$(RELEASE)-morphos/docs/ReadMe.info"
@cp os/morphos/icons/document.info "/t/openttd-$(RELEASE)-morphos/docs/Console.info" $(Q)cp os/morphos/icons/document.info "/t/openttd-$(RELEASE)-morphos/docs/Console.info"
@cp os/morphos/icons/document.info "/t/openttd-$(RELEASE)-morphos/docs/COPYING.info" $(Q)cp os/morphos/icons/document.info "/t/openttd-$(RELEASE)-morphos/docs/COPYING.info"
@cp os/morphos/icons/document.info "/t/openttd-$(RELEASE)-morphos/docs/ChangeLog.info" $(Q)cp os/morphos/icons/document.info "/t/openttd-$(RELEASE)-morphos/docs/ChangeLog.info"
@strip --strip-all --strip-unneeded --remove-section .comment "/t/openttd-$(RELEASE)-morphos/$(TTD)" $(Q)strip --strip-all --strip-unneeded --remove-section .comment "/t/openttd-$(RELEASE)-morphos/$(TTD)"
@lha a -r "t:openttd-$(RELEASE)-morphos.lha" "t:openttd-$(RELEASE)-morphos" $(Q)lha a -r "t:openttd-$(RELEASE)-morphos.lha" "t:openttd-$(RELEASE)-morphos"
@lha a "t:openttd-$(RELEASE)-morphos.lha" "t:openttd-$(RELEASE)-morphos.info" $(Q)lha a "t:openttd-$(RELEASE)-morphos.lha" "t:openttd-$(RELEASE)-morphos.info"
@rm -fr "/t/openttd-$(RELEASE)-morphos" $(Q)rm -fr "/t/openttd-$(RELEASE)-morphos"
@rm -fr "/t/openttd-$(RELEASE)-morphos.info" $(Q)rm -fr "/t/openttd-$(RELEASE)-morphos.info"
@echo "Release archive can be found in RAM:t/ now." @echo "Release archive can be found in RAM:t/ now."
.PHONY: release .PHONY: release
@ -790,37 +823,37 @@ endif
ifdef OSX ifdef OSX
release: all release: all
@mkdir -p "OpenTTD $(RELEASE)" $(Q)mkdir -p "OpenTTD $(RELEASE)"
@mkdir -p "OpenTTD $(RELEASE)"/docs $(Q)mkdir -p "OpenTTD $(RELEASE)"/docs
@mkdir -p "OpenTTD $(RELEASE)"/scenario $(Q)mkdir -p "OpenTTD $(RELEASE)"/scenario
@cp -R $(OSXAPP) "OpenTTD $(RELEASE)"/ $(Q)cp -R $(OSXAPP) "OpenTTD $(RELEASE)"/
@cp docs/OSX_where_did_the_package_go.txt "OpenTTD $(RELEASE)"/Where\ did\ the\ package\ go.txt $(Q)cp docs/OSX_where_did_the_package_go.txt "OpenTTD $(RELEASE)"/Where\ did\ the\ package\ go.txt
@cp readme.txt "OpenTTD $(RELEASE)"/docs/ $(Q)cp readme.txt "OpenTTD $(RELEASE)"/docs/
@cp docs/README_if_game_crashed_on_OSX.txt "OpenTTD $(RELEASE)"/docs/readme\ if\ crashed\ on\ OSX.txt $(Q)cp docs/README_if_game_crashed_on_OSX.txt "OpenTTD $(RELEASE)"/docs/readme\ if\ crashed\ on\ OSX.txt
@cp docs/console.txt "OpenTTD $(RELEASE)"/docs/ $(Q)cp docs/console.txt "OpenTTD $(RELEASE)"/docs/
@cp COPYING "OpenTTD $(RELEASE)"/docs/ $(Q)cp COPYING "OpenTTD $(RELEASE)"/docs/
@cp changelog.txt "OpenTTD $(RELEASE)"/docs/ $(Q)cp changelog.txt "OpenTTD $(RELEASE)"/docs/
@cp docs/README_if_game_crashed_on_OSX.txt "OpenTTD $(RELEASE)"/docs/ $(Q)cp docs/README_if_game_crashed_on_OSX.txt "OpenTTD $(RELEASE)"/docs/
@cp os/macos/*.webloc "OpenTTD $(RELEASE)" $(Q)cp os/macos/*.webloc "OpenTTD $(RELEASE)"
@cp known-bugs.txt "OpenTTD $(RELEASE)"/known-bugs.txt $(Q)cp known-bugs.txt "OpenTTD $(RELEASE)"/known-bugs.txt
@cp scenario/* "OpenTTD $(RELEASE)"/scenario/ $(Q)cp scenario/* "OpenTTD $(RELEASE)"/scenario/
@/usr/bin/hdiutil create -ov -format UDZO -srcfolder "OpenTTD $(RELEASE)" openttd-"$(RELEASE)"-osx.dmg $(Q)/usr/bin/hdiutil create -ov -format UDZO -srcfolder "OpenTTD $(RELEASE)" openttd-"$(RELEASE)"-osx.dmg
@rm -fr "OpenTTD $(RELEASE)" $(Q)rm -fr "OpenTTD $(RELEASE)"
nightly_build: all nightly_build: all
@mkdir -p "OpenTTD_nightly_$(DATE)" $(Q)mkdir -p "OpenTTD_nightly_$(DATE)"
@mkdir -p "OpenTTD_nightly_$(DATE)"/docs $(Q)mkdir -p "OpenTTD_nightly_$(DATE)"/docs
@cp -R $(OSXAPP) "OpenTTD_nightly_$(DATE)"/ $(Q)cp -R $(OSXAPP) "OpenTTD_nightly_$(DATE)"/
@cp docs/OSX_where_did_the_package_go.txt "OpenTTD_nightly_$(DATE)"/Where\ did\ the\ package\ go.txt $(Q)cp docs/OSX_where_did_the_package_go.txt "OpenTTD_nightly_$(DATE)"/Where\ did\ the\ package\ go.txt
@cp readme.txt "OpenTTD_nightly_$(DATE)"/docs/ $(Q)cp readme.txt "OpenTTD_nightly_$(DATE)"/docs/
@cp docs/README_if_game_crashed_on_OSX.txt "OpenTTD_nightly_$(DATE)"/docs/readme\ if\ crashed\ on\ OSX.txt $(Q)cp docs/README_if_game_crashed_on_OSX.txt "OpenTTD_nightly_$(DATE)"/docs/readme\ if\ crashed\ on\ OSX.txt
@cp docs/console.txt "OpenTTD_nightly_$(DATE)"/docs/ $(Q)cp docs/console.txt "OpenTTD_nightly_$(DATE)"/docs/
@cp COPYING "OpenTTD_nightly_$(DATE)"/docs/ $(Q)cp COPYING "OpenTTD_nightly_$(DATE)"/docs/
@cp revisionlog.txt "OpenTTD_nightly_$(DATE)"/revisionlog.txt $(Q)cp revisionlog.txt "OpenTTD_nightly_$(DATE)"/revisionlog.txt
@cp docs/README_if_game_crashed_on_OSX.txt "OpenTTD_nightly_$(DATE)"/docs/ $(Q)cp docs/README_if_game_crashed_on_OSX.txt "OpenTTD_nightly_$(DATE)"/docs/
@cp os/macos/*.webloc "OpenTTD_nightly_$(DATE)"/ $(Q)cp os/macos/*.webloc "OpenTTD_nightly_$(DATE)"/
@/usr/bin/hdiutil create -ov -format UDZO -srcfolder "OpenTTD_nightly_$(DATE)" openttd-nightly-"$(DATE)".dmg $(Q)/usr/bin/hdiutil create -ov -format UDZO -srcfolder "OpenTTD_nightly_$(DATE)" openttd-nightly-"$(DATE)".dmg
@rm -fr "OpenTTD_nightly_$(DATE)" $(Q)rm -fr "OpenTTD_nightly_$(DATE)"
.PHONY: release nightly_build .PHONY: release nightly_build
endif endif
@ -843,10 +876,10 @@ FORCE:
clean: clean:
@echo '===> Cleaning up' @echo '===> Cleaning up'
@rm -rf .deps *~ $(TTD) $(STRGEN) core table/strings.h $(LANGS) $(OBJS) endian.h $(ENDIAN_CHECK) $(Q)rm -rf .deps *~ $(TTD) $(STRGEN) core table/strings.h $(LANGS) $(OBJS) endian.h $(ENDIAN_CHECK)
mrproper: clean mrproper: clean
@rm -rf $(MAKE_CONFIG) $(Q)rm -rf $(MAKE_CONFIG)
ifndef OSX ifndef OSX
ifndef MORPHOS ifndef MORPHOS
@ -904,8 +937,8 @@ love:
# Export all variables set to subprocesses (a bit dirty) # Export all variables set to subprocesses (a bit dirty)
.EXPORT_ALL_VARIABLES: .EXPORT_ALL_VARIABLES:
upgradeconf: $(MAKE_CONFIG) upgradeconf: $(MAKE_CONFIG)
@rm $(MAKE_CONFIG) $(Q)rm $(MAKE_CONFIG)
@$(MAKE) $(MAKE_CONFIG) $(Q)$(MAKE) $(MAKE_CONFIG)
.PHONY: upgradeconf .PHONY: upgradeconf
@ -924,21 +957,11 @@ DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :)
# therefore we do not need to watch deps. # therefore we do not need to watch deps.
%.o: %.c $(MAKE_CONFIG) endian.h table/strings.h %.o: %.c $(MAKE_CONFIG) endian.h table/strings.h
@if [ ! "$(VERBOSE)" ]; then \ $(call cmd,c_compile)
echo '===> Compiling $<'; \
else \
echo $(CC) $(CFLAGS) $(CDEFS) -c $< -o $@; \
fi
@$(CC) $(CFLAGS) $(CDEFS) -MD -c $< -o $@
@mv $(<:%.c=%.d) $(<:%.c=.deps/%.d) @mv $(<:%.c=%.d) $(<:%.c=.deps/%.d)
%.o: %.cpp $(MAKE_CONFIG) endian.h table/strings.h %.o: %.cpp $(MAKE_CONFIG) endian.h table/strings.h
@if [ ! "$(VERBOSE)" ]; then \ $(call cmd,cxx_compile)
echo '===> Compiling $<'; \
else \
echo $(CXX) $(CFLAGS) $(CDEFS) -c $< -o $@; \
fi
@$(CXX) $(CFLAGS) $(CDEFS) -MD -c $< -o $@
@mv $(<:%.c=%.d) $(<:%.c=.deps/%.d) @mv $(<:%.c=%.d) $(<:%.c=.deps/%.d)
# Silence stale header dependencies # Silence stale header dependencies