Fix #7197: Invalidate depot buttons when necessary. (#7212)
[openttd-github.git] / projects / generate
blob595fa3acc6888d907d1d210d8be08463c0dd04f8
1 #!/bin/bash
3 # $Id$
5 # This file is part of OpenTTD.
6 # 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.
7 # 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.
8 # 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/>.
10 # This file generates all project files based on sources.list, so everyone who
11 # can start a bash process, can update the project files.
13 ROOT_DIR="`pwd`/.."
14 if ! [ -e "$ROOT_DIR/source.list" ]
15 then
16 ROOT_DIR="`pwd`"
18 if ! [ -e "$ROOT_DIR/source.list" ]
19 then
20 echo "Can't find source.list, needed in order to make this run. Please go to either"
21 echo " the project dir, or the root dir of a clean SVN checkout."
22 exit 1
25 # openttd_vs142.sln is for MSVC 2019
26 # openttd_vs142.vcxproj is for MSVC 2019
27 # openttd_vs142.vcxproj.filters is for MSVC 2019
28 # langs_vs142.vcxproj is for MSVC 2019
29 # strgen_vs142.vcxproj is for MSVC 2019
30 # strgen_vs142.vcxproj.filters is for MSVC 2019
31 # generate_vs142.vcxproj is for MSVC 2019
32 # version_vs142.vcxproj is for MSVC 2019
33 # basesets_vs142.vcxproj is for MSVC 2019
35 # openttd_vs141.sln is for MSVC 2017
36 # openttd_vs141.vcxproj is for MSVC 2017
37 # openttd_vs141.vcxproj.filters is for MSVC 2017
38 # langs_vs141.vcxproj is for MSVC 2017
39 # strgen_vs141.vcxproj is for MSVC 2017
40 # strgen_vs141.vcxproj.filters is for MSVC 2017
41 # generate_vs141.vcxproj is for MSVC 2017
42 # version_vs141.vcxproj is for MSVC 2017
43 # basesets_vs141.vcxproj is for MSVC 2017
45 # openttd_vs140.sln is for MSVC 2015
46 # openttd_vs140.vcxproj is for MSVC 2015
47 # openttd_vs140.vcxproj.filters is for MSVC 2015
48 # langs_vs140.vcxproj is for MSVC 2015
49 # strgen_vs140.vcxproj is for MSVC 2015
50 # strgen_vs140.vcxproj.filters is for MSVC 2015
51 # generate_vs140.vcxproj is for MSVC 2015
52 # version_vs140.vcxproj is for MSVC 2015
53 # basesets_vs140.vcxproj is for MSVC 2015
58 # First, collect the list of Windows files
59 allegro_config=""
60 sdl_config="1"
61 png_config="1"
62 os="MSVC"
63 enable_dedicated="0"
64 enable_ai="1"
65 with_cocoa="0"
66 enable_directmusic="1"
67 enable_fluidsynth="0"
68 with_threads="1"
69 file_prefix="..\\\\src\\\\"
71 safety_check() {
72 li=""
73 for i in `cat $1 | grep -v "#\|ottdres.rc\|win32.cpp\|win32_v.cpp" | xargs -n 1 basename | sort`; do
74 if [ "$li" = "$i" ]; then
75 echo " !! ERROR !!"
76 echo ""
77 echo "The filename '$i' is already used in this project."
78 echo "Because MSVC uses one single directory for all object files, it"
79 echo "cannot handle filenames with the same name inside the same project."
80 echo "Please rename either one of the file and try generating again."
81 echo ""
82 echo " !! ERROR !!"
83 exit 1
85 li="$i"
86 done
89 grep '\.h' "$ROOT_DIR/source.list" | grep -v '../objs/langs/table/strings.h\|../objs/settings/table/settings.h' | sed 's/ //g' | sort > tmp.headers.source.list
90 find "$ROOT_DIR/src" \( -iname "*.h" -or -iname "*.hpp" \) -and -not -ipath "*/.svn/*" | sed "s~$ROOT_DIR/src/~~" | sort > tmp.headers.src
91 if [ -n "`diff tmp.headers.source.list tmp.headers.src`" ]; then
92 echo "The following headers are missing in source.list and not in /src/ or vice versa."
93 diff tmp.headers.source.list tmp.headers.src | grep '[<>]' | sort
94 echo ""
96 rm tmp.headers.*
98 load_main_data() {
99 # Read the source.list and process it
100 RES="`cat $1 | tr '\r' '\n' | awk '
101 /^( *)#end/ { if (deep == skip) { skip -= 1; } deep -= 1; next; }
102 /^( *)#else/ { if (deep == skip) { skip -= 1; } else if (deep - 1 == skip) { skip += 1; } next; }
103 /^( *)#if/ {
104 gsub(" ", "", $0);
105 gsub("^#if", "", $0);
106 gsub("^ ", "", $0);
108 if (deep != skip) { deep += 1; next; }
110 deep += 1;
112 if ($0 == "ALLEGRO" && "'$allegro_config'" == "") { next; }
113 if ($0 == "SDL" && "'$sdl_config'" == "") { next; }
114 if ($0 == "PNG" && "'$png_config'" == "") { next; }
115 if ($0 == "OSX" && "'$os'" != "OSX") { next; }
116 if ($0 == "OS2" && "'$os'" != "OS2") { next; }
117 if ($0 == "DOS" && "'$os'" != "DOS") { next; }
118 if ($0 == "DEDICATED" && "'$enable_dedicated'" != "1") { next; }
119 if ($0 == "AI" && "'$enable_ai'" == "0") { next; }
120 if ($0 == "COCOA" && "'$with_cocoa'" == "0") { next; }
121 if ($0 == "BEOS" && "'$os'" != "BEOS") { next; }
122 if ($0 == "WIN32" && "'$os'" != "MINGW" &&
123 "'$os'" != "CYGWIN" && "'$os'" != "MSVC" ) { next; }
124 if ($0 == "MSVC" && "'$os'" != "MSVC") { next; }
125 if ($0 == "DIRECTMUSIC" && "'$enable_directmusic'" != "1") { next; }
126 if ($0 == "FLUIDSYNTH" && "'$enable_fluidsynth'" != "1") { next; }
127 if ($0 == "LIBTIMIDITY" && "'$libtimidity'" == "" ) { next; }
128 if ($0 == "HAVE_THREAD" && "'$with_threads'" == "0") { next; }
130 skip += 1;
132 next;
134 /^( *)#/ {
135 if (deep == skip) {
136 gsub(" ", "", $0);
137 gsub("^#", "", $0);
138 gsub("^ ", "", $0);
139 filter = $0;
140 print "#3 <Filter Include=\\""filter"\\">";
141 printf "#3 <UniqueIdentifier>{c76ff9f1-1e62-46d8-8d55-%012d}</UniqueIdentifier>\n", i;
142 print "#3 </Filter>";
143 i += 1;
146 next;
148 /^$/ { next }
150 if (deep == skip) {
151 gsub(" ", "", $0);
152 gsub("/", "\\\\", $0);
153 split($0, file, ".");
154 cltype = "ClInclude"
155 if (file[2] == "cpp") cltype = "ClCompile";
156 if (file[2] == "rc") cltype = "ResourceCompile";
157 print "#2 <"cltype" Include=\\"'$file_prefix'"$0"\\" />";
158 print "#4 <"cltype" Include=\\"'$file_prefix'"$0"\\">";
159 print "#4 <Filter>"filter"</Filter>";
160 print "#4 </"cltype">";
165 eval "$2=\"\$RES\""
168 load_lang_data() {
169 RES=""
170 # Windows Folder sort and Linux Folder sort are slightly different.
171 # By removing the extension and sorting it on Linux, they are the same.
172 for i in `ls $1 | sed s~.txt$~~g | sort`
174 i=`basename $i`
175 if [ "$i" == "english" ]
176 then
177 continue
179 RES="$RES
180 #2 <CustomBuild Include=\"..\\src\\lang\\"$i".txt\">
181 #2 <Message Condition=\"'\$(Configuration)|\$(Platform)'=='Debug|Win32'\">Generating "$i" language file</Message>
182 #2 <Command Condition=\"'\$(Configuration)|\$(Platform)'=='Debug|Win32'\">..\\objs\\strgen\\strgen.exe -s ..\\src\\lang -d ..\\bin\\lang \"%(FullPath)\"</Command>
183 #2 <AdditionalInputs Condition=\"'\$(Configuration)|\$(Platform)'=='Debug|Win32'\">..\\src\\lang\\english.txt;..\\objs\\strgen\\strgen.exe;%(AdditionalInputs)</AdditionalInputs>
184 #2 <Outputs Condition=\"'\$(Configuration)|\$(Platform)'=='Debug|Win32'\">..\\bin\\lang\\"$i".lng;%(Outputs)</Outputs>
185 #2 </CustomBuild>
186 #3 <CustomBuild Include=\"..\\src\\lang\\"$i".txt\">
187 #3 <Filter>Translations</Filter>
188 #3 </CustomBuild>"
189 done
191 eval "$2=\"\$RES\""
194 load_settings_data() {
195 RES=""
196 RES2="
197 #3..\\objs\\settings\\settings_gen.exe -o ..\\objs\\settings\\table\\settings.h -b ..\\src\\table\\settings.h.preamble -a ..\\src\\table\\settings.h.postamble"
198 for i in `ls $1`
200 i=`basename $i`
201 RES="$RES
202 #2 <None Include=\"..\\src\\table\\"$i"\" />
203 #4 <None Include=\"..\\src\\table\\"$i"\">
204 #4 <Filter>INI</Filter>
205 #4 </None>"
206 RES2="$RES2 ..\\src\\table\\"$i
207 done
209 eval "$2=\"\$RES\$RES2\""
212 load_baseset_data() {
213 FIRST=""
214 RES=""
215 RES2="
216 #4 <Langs>"
217 # Windows Folder sort and Linux Folder sort are slightly different.
218 # By removing the extension and sorting it on Linux, they are the same.
219 for i in `ls $2 | sed s~.txt$~~g | sort`
221 if [ "$FIRST" != "" ]; then
222 RES2="$RES2;"
223 else
224 FIRST=1
226 i=`basename $i`
227 RES2="$RES2..\\src\\lang\\$i.txt"
228 done
229 RES2="$RES2</Langs>"
230 # Windows Folder sort and Linux Folder sort are slightly different.
231 # By fiddling with the extension and sorting it on Linux, they are the same.
232 for i in `ls $1 | sed s~\\\.~000~g | sort | sed s~000~.~g`
234 i=`basename $i`
235 RES="$RES
236 #2 <CustomBuild Include=\"..\\media\\baseset\\"$i"\">
237 #2 <Message Condition=\"'\$(Configuration)|\$(Platform)'=='Debug|Win32'\">Generating "$i" baseset metadata file</Message>
238 #2 <Command Condition=\"'\$(Configuration)|\$(Platform)'=='Debug|Win32'\">cscript //nologo ..\\media\\baseset\\translations.vbs \"%(FullPath)\" \"\$(OutputPath)$i\" ..\\src\\lang ..\\bin\\baseset\\orig_extra.grf</Command>
239 #2 <AdditionalInputs Condition=\"'\$(Configuration)|\$(Platform)'=='Debug|Win32'\">\$(Langs);..\\bin\\baseset\\orig_extra.grf;%(AdditionalInputs)</AdditionalInputs>
240 #2 <Outputs Condition=\"'\$(Configuration)|\$(Platform)'=='Debug|Win32'\">..\\bin\\baseset\\"$i";%(Outputs)</Outputs>
241 #2 </CustomBuild>
242 #3 <CustomBuild Include=\"..\\media\\baseset\\"$i"\">
243 #3 <Filter>Baseset Metadata</Filter>
244 #3 </CustomBuild>"
245 done
247 eval "$3=\"\$RES\$RES2\""
250 generate() {
251 echo "Generating $2..."
252 if [ $# -eq 3 ]; then
253 # Everything above the !!FILTERS!! marker
254 cat "$ROOT_DIR/projects/$2".in | tr '\r' '\n' | awk '
255 /^$/ { next }
256 /!!FILTERS!!/ { stop = 1; }
258 if (stop == 0) { print $0 }
260 ' > "$ROOT_DIR/projects/$2"
262 echo "$3" >> "$ROOT_DIR/projects/$2"
264 # Everything below the !!FILTERS!! marker and above the !!FILES!! marker
265 cat "$ROOT_DIR/projects/$2".in | tr '\r' '\n' | awk '
266 BEGIN { stop = 1; }
267 /^$/ { next }
268 /!!FILTERS!!/ { stop = 2; }
269 /!!FILES!!/ { stop = 1; }
271 if (stop == 0) { print $0 }
272 if (stop == 2) { stop = 0 }
274 ' >> "$ROOT_DIR/projects/$2"
275 else
276 # Everything above the !!FILES!! marker
277 cat "$ROOT_DIR/projects/$2".in | tr '\r' '\n' | awk '
278 /^$/ { next }
279 /!!FILES!!/ { stop = 1; }
281 if (stop == 0) { print $0 }
283 ' > "$ROOT_DIR/projects/$2"
286 echo "$1" >> "$ROOT_DIR/projects/$2"
288 # Everything below the !!FILES!! marker
289 cat "$ROOT_DIR/projects/$2".in | tr '\r' '\n' | awk '
290 BEGIN { stop = 1; }
291 /^$/ { next }
292 /!!FILES!!/ { stop = 2; }
294 if (stop == 0) { print $0 }
295 if (stop == 2) { stop = 0 }
297 ' >> "$ROOT_DIR/projects/$2"
300 safety_check "$ROOT_DIR/source.list"
302 load_main_data "$ROOT_DIR/source.list" openttd
303 openttdfiles=`echo "$openttd" | grep "^#4" | sed "s~#4~~g"`
304 openttdfilters=`echo "$openttd" | grep "^#3" | sed "s~#3~~g"`
305 openttdvcxproj=`echo "$openttd" | grep "^#2" | sed "s~#2~~g"`
307 load_lang_data "$ROOT_DIR/src/lang/*.txt" lang
308 langfiles=`echo "$lang" | grep "^#3" | sed "s~#3~~g"`
309 langvcxproj=`echo "$lang" | grep "^#2" | sed "s~#2~~g"`
311 load_settings_data "$ROOT_DIR/src/table/*.ini" settings
312 settingsfiles=`echo "$settings" | grep "^#4" | sed "s~#4~~g"`
313 settingscommand=`echo "$settings" | grep "^#3" | sed "s~#3~~g"`
314 settingsvcxproj=`echo "$settings" | grep "^#2" | sed "s~#2~~g"`
316 load_baseset_data "$ROOT_DIR/media/baseset/*.ob?" "$ROOT_DIR/src/lang/*.txt" baseset
317 basesetfiles=`echo "$baseset" | grep "^#3" | sed "s-#3--g"`
318 basesetvcxproj=`echo "$baseset" | grep "^#2" | sed "s~#2~~g"`
319 basesetlangs=`echo "$baseset" | grep "^#4" | sed "s~#4~~g"`
321 generate "$openttdvcxproj" "openttd_vs140.vcxproj"
322 generate "$openttdfiles" "openttd_vs140.vcxproj.filters" "$openttdfilters"
323 generate "$openttdvcxproj" "openttd_vs141.vcxproj"
324 generate "$openttdfiles" "openttd_vs141.vcxproj.filters" "$openttdfilters"
325 generate "$openttdvcxproj" "openttd_vs142.vcxproj"
326 generate "$openttdfiles" "openttd_vs142.vcxproj.filters" "$openttdfilters"
327 generate "$langvcxproj" "langs_vs140.vcxproj"
328 generate "$langfiles" "langs_vs140.vcxproj.filters"
329 generate "$langvcxproj" "langs_vs141.vcxproj"
330 generate "$langfiles" "langs_vs141.vcxproj.filters"
331 generate "$langvcxproj" "langs_vs142.vcxproj"
332 generate "$langfiles" "langs_vs142.vcxproj.filters"
333 generate "$settingsvcxproj" "settings_vs140.vcxproj" "$settingscommand"
334 generate "$settingsfiles" "settings_vs140.vcxproj.filters"
335 generate "$settingsvcxproj" "settings_vs141.vcxproj" "$settingscommand"
336 generate "$settingsfiles" "settings_vs141.vcxproj.filters"
337 generate "$settingsvcxproj" "settings_vs142.vcxproj" "$settingscommand"
338 generate "$settingsfiles" "settings_vs142.vcxproj.filters"
339 generate "$basesetvcxproj" "basesets_vs140.vcxproj" "$basesetlangs"
340 generate "$basesetfiles" "basesets_vs140.vcxproj.filters"
341 generate "$basesetvcxproj" "basesets_vs141.vcxproj" "$basesetlangs"
342 generate "$basesetfiles" "basesets_vs141.vcxproj.filters"
343 generate "$basesetvcxproj" "basesets_vs142.vcxproj" "$basesetlangs"
344 generate "$basesetfiles" "basesets_vs142.vcxproj.filters"