Fix old map array tunnel head conversion
[openttd/fttd.git] / projects / generate
blob6fe6c276e806737262517533ed6f2d1d07ff529e
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_vs141.sln is for MSVC 2017
26 # openttd_vs141.vcxproj is for MSVC 2017
27 # openttd_vs141.vcxproj.filters is for MSVC 2017
28 # langs_vs141.vcxproj is for MSVC 2017
29 # strgen_vs141.vcxproj is for MSVC 2017
30 # strgen_vs141.vcxproj.filters is for MSVC 2017
31 # generate_vs141.vcxproj is for MSVC 2017
32 # version_vs141.vcxproj is for MSVC 2017
34 # openttd_vs140.sln is for MSVC 2015
35 # openttd_vs140.vcxproj is for MSVC 2015
36 # openttd_vs140.vcxproj.filters is for MSVC 2015
37 # langs_vs140.vcxproj is for MSVC 2015
38 # strgen_vs140.vcxproj is for MSVC 2015
39 # strgen_vs140.vcxproj.filters is for MSVC 2015
40 # generate_vs140.vcxproj is for MSVC 2015
41 # version_vs140.vcxproj is for MSVC 2015
43 # openttd_vs100.sln is for MSVC 2010
44 # openttd_vs100.vcxproj is for MSVC 2010
45 # openttd_vs100.vcxproj.filters is for MSVC 2010
46 # langs_vs100.vcxproj is for MSVC 2010
47 # strgen_vs100.vcxproj is for MSVC 2010
48 # strgen_vs100.vcxproj.filters is for MSVC 2010
49 # generate_vs100.vcxproj is for MSVC 2010
50 # version_vs100.vcxproj is for MSVC 2010
52 # openttd_vs90.sln is for MSVC 2008
53 # openttd_vs90.vcproj is for MSVC 2008
54 # langs_vs90.vcproj is for MSVC 2008
55 # strgen_vs90.vcproj is for MSVC 2008
56 # generate_vs90.vcproj is for MSVC 2008
57 # version_vs90.vcproj is for MSVC 2008
59 # openttd_vs80.sln is for MSVC 2005
60 # openttd_vs80.vcproj is for MSVC 2005
61 # langs_vs80.vcproj is for MSVC 2005
62 # strgen_vs80.vcproj is for MSVC 2005
63 # generate_vs80.vcproj is for MSVC 2005
64 # version_vs80.vcproj is for MSVC 2005
67 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
68 find "$ROOT_DIR/src" -iname .svn -prune -o \( -iname '*.h' -o -iname '*.hpp' \) -print | sed "s~$ROOT_DIR/src/~~" | sort > tmp.headers.src
69 if ! diff tmp.headers.source.list tmp.headers.src >/dev/null; then
70 echo "The following headers are missing in source.list and not in /src/ or vice versa."
71 diff tmp.headers.source.list tmp.headers.src | grep '[<>]' | sort
72 echo ""
74 rm tmp.headers.*
77 generate() {
78 echo "Generating $2..."
79 if [ $# -eq 3 ]; then
80 # Everything above the !!FILTERS!! marker
81 sed < "$ROOT_DIR/projects/$2".in -n -e '
82 s/\r$//
83 /!!FILTERS!!/ q
85 ' > "$ROOT_DIR/projects/$2"
87 printf "%s" "$3" >> "$ROOT_DIR/projects/$2"
89 # Everything between the !!FILTERS!! marker and the !!FILES!! marker
90 sed < "$ROOT_DIR/projects/$2".in -n -e '
91 s/\r$//
92 1,/!!FILTERS!!/ d
93 /!!FILES!!/ q
95 ' >> "$ROOT_DIR/projects/$2"
96 else
97 # Everything above the !!FILES!! marker
98 sed < "$ROOT_DIR/projects/$2".in -n -e '
99 s/\r$//
100 /!!FILES!!/ q
102 ' > "$ROOT_DIR/projects/$2"
105 printf "%s" "$1" >> "$ROOT_DIR/projects/$2"
107 # Everything below the !!FILES!! marker
108 sed < "$ROOT_DIR/projects/$2".in -n -e '
109 s/\r$//
110 1,/!!FILES!!/ d
112 ' >> "$ROOT_DIR/projects/$2"
116 # First, collect the list of Windows files
117 file_prefix="..\\\\src\\\\"
119 # Read the source.list and process it
120 srclist="`cat "$ROOT_DIR/source.list" | tr '\r' '\n' | awk '
121 /^( *)#end/ { if (deep == skip) { skip -= 1; } deep -= 1; next; }
122 /^( *)#else/ { if (deep == skip) { skip -= 1; } else if (deep - 1 == skip) { skip += 1; } next; }
123 /^( *)#if/ {
124 gsub(" ", "", $0);
125 gsub("^#if", "", $0);
126 gsub("^ ", "", $0);
128 if (deep != skip) { deep += 1; next; }
130 deep += 1;
132 if ($0 == "SDL" ) { skip += 1; }
133 if ($0 == "PNG" ) { skip += 1; }
134 if ($0 == "WIN32" ) { skip += 1; }
135 if ($0 == "MSVC" ) { skip += 1; }
136 if ($0 == "DIRECTMUSIC") { skip += 1; }
137 if ($0 == "AI" ) { skip += 1; }
138 if ($0 == "SSE" ) { skip += 1; }
139 if ($0 == "HAVE_THREAD") { skip += 1; }
141 next;
143 /^$/ { next }
145 if (deep == skip) {
146 gsub(" ", "", $0);
147 print;
152 openttd="`echo "$srclist" | awk '
153 BEGIN {
154 configs[0] = "Release|Win32";
155 configs[1] = "Debug|Win32";
156 configs[2] = "Release|x64";
157 configs[3] = "Debug|x64";
159 /^#/ {
160 gsub("^#", "", $0);
161 gsub("^ ", "", $0);
163 if (first_time != 0) {
164 print " </Filter>";
165 } else {
166 first_time = 1;
169 print " <Filter";
170 print " Name=\\""$0"\\"";
171 print " >";
173 next;
176 gsub(" ", "", $0);
177 gsub("/", "\\\\", $0);
178 print " <File";
179 print " RelativePath=\\".\\\\'$file_prefix'"$0"\\"";
180 print " >";
181 ndirs = split($0, dirs, "\\\\");
182 if (ndirs > 1 && match($0, /\.cpp$/)) {
183 dir = "$(IntDir)\\\\";
184 for (i = 1; i < ndirs; i++) {
185 dir = sprintf("%s%s\\\\", dir, dirs[i]);
187 for (i = 0; i < 4; i++) {
188 print " <FileConfiguration";
189 print " Name=\\"" configs[i] "\\"";
190 print " >";
191 print " <Tool";
192 print " Name=\\"VCCLCompilerTool\\"";
193 print " AssemblerListingLocation=\\""dir"\\"";
194 print " ObjectFile=\\""dir"\\"";
195 print " XMLDocumentationFileName=\\""dir"\\"";
196 print " />";
197 print " </FileConfiguration>";
200 print " </File>";
202 END { print " </Filter>"; }
206 openttdvcxproj="`echo "$srclist" | awk '
207 /^#/ { next; }
209 gsub(" ", "", $0);
210 gsub("/", "\\\\", $0);
211 split($0, file, ".");
212 cltype = "ClInclude"
213 if (file[2] == "cpp") cltype = "ClCompile";
214 if (file[2] == "rc") cltype = "ResourceCompile";
216 ndirs = split($0, dirs, "\\\\");
217 if (ndirs > 1 && cltype == "ClCompile") {
218 dir = "$(IntDir)\\\\";
219 for (i = 1; i < ndirs; i++) {
220 dir = sprintf("%s%s\\\\", dir, dirs[i]);
222 print " <ClCompile Include=\\"'$file_prefix'"$0"\\">";
223 print " <AssemblerListingLocation>"dir"</AssemblerListingLocation>";
224 print " <ObjectFileName>"dir"</ObjectFileName>";
225 print " <XMLDocumentationFileName>"dir"</XMLDocumentationFileName>";
226 print " </ClCompile>";
227 } else {
228 print " <"cltype" Include=\\"'$file_prefix'"$0"\\" />";
234 openttdfiles="`echo "$srclist" | awk '
235 /^#/ {
236 gsub("^#", "", $0);
237 gsub("^ ", "", $0);
239 filter = $0;
241 next;
244 gsub(" ", "", $0);
245 gsub("/", "\\\\", $0);
246 split($0, file, ".");
247 cltype = "ClInclude"
248 if (file[2] == "cpp") cltype = "ClCompile";
249 if (file[2] == "rc") cltype = "ResourceCompile";
250 print " <"cltype" Include=\\"'$file_prefix'"$0"\\">";
251 print " <Filter>"filter"</Filter>";
252 print " </"cltype">";
257 openttdfilters="`echo "$srclist" | awk '
258 /^#/ {
259 gsub("^#", "", $0);
260 gsub("^ ", "", $0);
262 print " <Filter Include=\\""$0"\\">";
263 printf " <UniqueIdentifier>{c76ff9f1-1e62-46d8-8d55-%012d}</UniqueIdentifier>\n", i;
264 print " </Filter>";
265 i += 1;
270 generate "$openttd" "openttd_vs80.vcproj"
271 generate "$openttd" "openttd_vs90.vcproj"
272 generate "$openttdvcxproj" "openttd_vs100.vcxproj"
273 generate "$openttdfiles" "openttd_vs100.vcxproj.filters" "$openttdfilters"
274 generate "$openttdvcxproj" "openttd_vs140.vcxproj"
275 generate "$openttdfiles" "openttd_vs140.vcxproj.filters" "$openttdfilters"
276 generate "$openttdvcxproj" "openttd_vs141.vcxproj"
277 generate "$openttdfiles" "openttd_vs141.vcxproj.filters" "$openttdfilters"
280 txtfiles=`ls "$ROOT_DIR"/src/lang/*.txt | sed -e 's,^.*/,,' -e 's/\.txt$//' -e '/^english$/d'`
282 lang=""
283 langvcxproj=""
284 langfiles=""
286 for i in $txtfiles
288 lang="$lang\
289 <File
290 RelativePath=\"..\\src\\lang\\$i.txt\"
292 <FileConfiguration
293 Name=\"Debug|Win32\"
295 <Tool
296 Name=\"VCCustomBuildTool\"
297 Description=\"Generating $i language file\"
298 CommandLine=\"..\\objs\\strgen\\strgen.exe -s ..\\src\\lang -d ..\\bin\\lang &quot;\$(InputPath)&quot;&#x0D;&#x0A;exit 0&#x0D;&#x0A;\"
299 AdditionalDependencies=\"..\\src\\lang\\english.txt;..\\objs\\strgen\\strgen.exe\"
300 Outputs=\"..\\bin\\lang\\$i.lng\"
302 </FileConfiguration>
303 </File>
305 langvcxproj="$langvcxproj\
306 <CustomBuild Include=\"..\\src\\lang\\$i.txt\">
307 <Message Condition=\"'\$(Configuration)|\$(Platform)'=='Debug|Win32'\">Generating $i language file</Message>
308 <Command Condition=\"'\$(Configuration)|\$(Platform)'=='Debug|Win32'\">..\\objs\\strgen\\strgen.exe -s ..\\src\\lang -d ..\\bin\\lang \"%(FullPath)\"</Command>
309 <AdditionalInputs Condition=\"'\$(Configuration)|\$(Platform)'=='Debug|Win32'\">..\\src\\lang\\english.txt;..\\objs\\strgen\\strgen.exe;%(AdditionalInputs)</AdditionalInputs>
310 <Outputs Condition=\"'\$(Configuration)|\$(Platform)'=='Debug|Win32'\">..\\bin\\lang\\$i.lng;%(Outputs)</Outputs>
311 </CustomBuild>
313 langfiles="$langfiles\
314 <CustomBuild Include=\"..\\src\\lang\\$i.txt\">
315 <Filter>Translations</Filter>
316 </CustomBuild>
318 done
320 generate "$lang" "langs_vs80.vcproj"
321 generate "$lang" "langs_vs90.vcproj"
322 generate "$langvcxproj" "langs_vs100.vcxproj"
323 generate "$langfiles" "langs_vs100.vcxproj.filters"
324 generate "$langvcxproj" "langs_vs140.vcxproj"
325 generate "$langfiles" "langs_vs140.vcxproj.filters"
326 generate "$langvcxproj" "langs_vs141.vcxproj"
327 generate "$langfiles" "langs_vs141.vcxproj.filters"
330 inifiles=`ls "$ROOT_DIR"/src/table/*.ini | sed -e 's,^.*/,,'`
332 settings=""
333 settingscommand="..\\objs\\settings\\settings_gen.exe -o ..\\objs\\settings\\table\\settings.h -b ..\\src\\table\\settings.h.preamble -a ..\\src\\table\\settings.h.postamble"
334 settingsvcxproj=""
335 settingsfiles=""
337 for i in $inifiles
339 settings="$settings\
340 <File
341 RelativePath=\"..\\src\\table\\$i\"
343 </File>
345 settingscommand="$settingscommand ..\\src\\table\\$i"
346 settingsvcxproj="$settingsvcxproj\
347 <None Include=\"..\\src\\table\\$i\" />
349 settingsfiles="$settingsfiles\
350 <None Include=\"..\\src\\table\\$i\">
351 <Filter>INI</Filter>
352 </None>
354 done
356 settingscommand="$settingscommand
359 generate "$settings" "settings_vs80.vcproj" "$settingscommand"
360 generate "$settings" "settings_vs90.vcproj" "$settingscommand"
361 generate "$settingsvcxproj" "settings_vs100.vcxproj" "$settingscommand"
362 generate "$settingsfiles" "settings_vs100.vcxproj.filters"
363 generate "$settingsvcxproj" "settings_vs140.vcxproj" "$settingscommand"
364 generate "$settingsfiles" "settings_vs140.vcxproj.filters"
365 generate "$settingsvcxproj" "settings_vs141.vcxproj" "$settingscommand"
366 generate "$settingsfiles" "settings_vs141.vcxproj.filters"