3 # This file is part of OpenTTD.
4 # OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
5 # OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
6 # See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
9 ENDIAN_CHECK = !!ENDIAN_CHECK!!
11 LANG_DIR = !!LANG_DIR!!
13 LANGS_SRC = $(shell ls $(LANG_DIR)/*.txt)
14 LANGS = $(LANGS_SRC:$(LANG_DIR)/%.txt=%.lng)
15 CXX_BUILD = !!CXX_BUILD!!
16 CFLAGS_BUILD = !!CFLAGS_BUILD!!
17 CXXFLAGS_BUILD= !!CXXFLAGS_BUILD!!
18 LDFLAGS_BUILD = !!LDFLAGS_BUILD!!
19 STRGEN_FLAGS = !!STRGEN_FLAGS!!
21 LANG_SUPPRESS = !!LANG_SUPPRESS!!
22 LANG_OBJS_DIR = !!LANG_OBJS_DIR!!
24 ifeq ($(LANG_SUPPRESS), yes)
25 LANG_ERRORS = >/dev/null 2>&1
28 # Make sure endian_host.h is reachable as if it was in the src/ dir
29 CFLAGS_BUILD += -I $(LANG_OBJS_DIR)
31 ENDIAN_TARGETS := endian_host.h endian_target.h $(ENDIAN_CHECK)
33 # Check if we want to show what we are doing
42 RES := $(shell mkdir -p $(BIN_DIR)/lang )
44 all: table/strings.h $(LANGS)
46 strgen_base.o: $(SRC_DIR)/strgen/strgen_base.cpp $(SRC_DIR)/strgen/strgen.h endian_host.h $(SRC_DIR)/table/control_codes.h $(SRC_DIR)/table/strgen_tables.h
47 $(E) '$(STAGE) Compiling $(<:$(SRC_DIR)/%.cpp=%.cpp)'
48 $(Q)$(CXX_BUILD) $(CFLAGS_BUILD) $(CXXFLAGS_BUILD) -DSTRGEN -c -o $@ $<
50 strgen.o: $(SRC_DIR)/strgen/strgen.cpp $(SRC_DIR)/strgen/strgen.h endian_host.h $(SRC_DIR)/table/control_codes.h $(SRC_DIR)/table/strgen_tables.h
51 $(E) '$(STAGE) Compiling $(<:$(SRC_DIR)/%.cpp=%.cpp)'
52 $(Q)$(CXX_BUILD) $(CFLAGS_BUILD) $(CXXFLAGS_BUILD) -DSTRGEN -c -o $@ $<
54 string.o: $(SRC_DIR)/string.cpp endian_host.h
55 $(E) '$(STAGE) Compiling $(<:$(SRC_DIR)/%.cpp=%.cpp)'
56 $(Q)$(CXX_BUILD) $(CFLAGS_BUILD) $(CXXFLAGS_BUILD) -DSTRGEN -c -o $@ $<
58 alloc_func.o: $(SRC_DIR)/core/alloc_func.cpp endian_host.h
59 $(E) '$(STAGE) Compiling $(<:$(SRC_DIR)/%.cpp=%.cpp)'
60 $(Q)$(CXX_BUILD) $(CFLAGS_BUILD) $(CXXFLAGS_BUILD) -DSTRGEN -c -o $@ $<
62 getoptdata.o: $(SRC_DIR)/misc/getoptdata.cpp $(SRC_DIR)/misc/getoptdata.h
63 $(E) '$(STAGE) Compiling $(<:$(SRC_DIR)/misc/%.cpp=%.cpp)'
64 $(Q)$(CXX_BUILD) $(CFLAGS_BUILD) $(CXXFLAGS_BUILD) -DSTRGEN -c -o $@ $<
66 lang/english.txt: $(LANG_DIR)/english.txt
68 $(Q)cp $(LANG_DIR)/english.txt lang/english.txt
70 $(STRGEN): alloc_func.o string.o strgen_base.o strgen.o getoptdata.o
71 $(E) '$(STAGE) Compiling and Linking $@'
72 $(Q)$(CXX_BUILD) $(CFLAGS_BUILD) $(CXXFLAGS_BUILD) $(LDFLAGS_BUILD) $^ -o $@
74 table/strings.h: lang/english.txt $(STRGEN)
75 $(E) '$(STAGE) Generating $@'
77 $(Q)./$(STRGEN) -s $(LANG_DIR) -d table
79 $(LANGS): %.lng: $(LANG_DIR)/%.txt $(STRGEN) lang/english.txt
80 $(E) '$(STAGE) Compiling language $(*F)'
81 $(Q)./$(STRGEN) $(STRGEN_FLAGS) -s $(LANG_DIR) -d $(LANG_OBJS_DIR) $< $(LANG_ERRORS) && cp $@ $(BIN_DIR)/lang || true # Do not fail all languages when one fails
83 # The targets to compile the endian-code
85 endian_host.h: $(ENDIAN_CHECK)
86 $(E) '$(STAGE) Testing endianness for host'
87 $(Q)./$(ENDIAN_CHECK) > $@
89 $(ENDIAN_CHECK): $(SRC_DIR)/endian_check.cpp
90 $(E) '$(STAGE) Compiling and Linking $@'
91 $(Q)$(CXX_BUILD) $(CFLAGS_BUILD) $(CXXFLAGS_BUILD) $(LDFLAGS_BUILD) $< -o $@
96 $(E) '$(STAGE) Cleaning up language files'
97 $(Q)rm -f strgen.o string.o alloc_func.o getoptdata.o table/strings.h $(STRGEN) $(LANGS) $(LANGS:%=$(BIN_DIR)/lang/%) lang/english.* $(ENDIAN_TARGETS)
100 $(Q)rm -rf $(BIN_DIR)/lang
103 @echo '$(STAGE) No such language: $(@:%.lng=%)'
105 .PHONY: all mrproper depend clean