Add StringID structure accessor helper functions
[openttd/fttd.git] / projects / generate
blob080f53a9bdaab64074a5a92c7eb6ddcb8540b9d2
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_vs140.sln is for MSVC 2015
26 # openttd_vs140.vcxproj is for MSVC 2015
27 # openttd_vs140.vcxproj.filters is for MSVC 2015
28 # langs_vs140.vcxproj is for MSVC 2015
29 # strgen_vs140.vcxproj is for MSVC 2015
30 # strgen_vs140.vcxproj.filters is for MSVC 2015
31 # generate_vs140.vcxproj is for MSVC 2015
32 # version_vs140.vcxproj is for MSVC 2015
34 # openttd_vs100.sln is for MSVC 2010
35 # openttd_vs100.vcxproj is for MSVC 2010
36 # openttd_vs100.vcxproj.filters is for MSVC 2010
37 # langs_vs100.vcxproj is for MSVC 2010
38 # strgen_vs100.vcxproj is for MSVC 2010
39 # strgen_vs100.vcxproj.filters is for MSVC 2010
40 # generate_vs100.vcxproj is for MSVC 2010
41 # version_vs100.vcxproj is for MSVC 2010
43 # openttd_vs90.sln is for MSVC 2008
44 # openttd_vs90.vcproj is for MSVC 2008
45 # langs_vs90.vcproj is for MSVC 2008
46 # strgen_vs90.vcproj is for MSVC 2008
47 # generate_vs90.vcproj is for MSVC 2008
48 # version_vs90.vcproj is for MSVC 2008
50 # openttd_vs80.sln is for MSVC 2005
51 # openttd_vs80.vcproj is for MSVC 2005
52 # langs_vs80.vcproj is for MSVC 2005
53 # strgen_vs80.vcproj is for MSVC 2005
54 # generate_vs80.vcproj is for MSVC 2005
55 # version_vs80.vcproj is for MSVC 2005
58 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
59 find "$ROOT_DIR/src" -iname .svn -prune -o \( -iname '*.h' -o -iname '*.hpp' \) -print | sed "s~$ROOT_DIR/src/~~" | sort > tmp.headers.src
60 if ! diff tmp.headers.source.list tmp.headers.src >/dev/null; then
61 echo "The following headers are missing in source.list and not in /src/ or vice versa."
62 diff tmp.headers.source.list tmp.headers.src | grep '[<>]' | sort
63 echo ""
65 rm tmp.headers.*
68 generate() {
69 echo "Generating $2..."
70 if [ $# -eq 3 ]; then
71 # Everything above the !!FILTERS!! marker
72 sed < "$ROOT_DIR/projects/$2".in -n -e '
73 s/\r$//
74 /!!FILTERS!!/ q
76 ' > "$ROOT_DIR/projects/$2"
78 printf "%s" "$3" >> "$ROOT_DIR/projects/$2"
80 # Everything between the !!FILTERS!! marker and the !!FILES!! marker
81 sed < "$ROOT_DIR/projects/$2".in -n -e '
82 s/\r$//
83 1,/!!FILTERS!!/ d
84 /!!FILES!!/ q
86 ' >> "$ROOT_DIR/projects/$2"
87 else
88 # Everything above the !!FILES!! marker
89 sed < "$ROOT_DIR/projects/$2".in -n -e '
90 s/\r$//
91 /!!FILES!!/ q
93 ' > "$ROOT_DIR/projects/$2"
96 printf "%s" "$1" >> "$ROOT_DIR/projects/$2"
98 # Everything below the !!FILES!! marker
99 sed < "$ROOT_DIR/projects/$2".in -n -e '
100 s/\r$//
101 1,/!!FILES!!/ d
103 ' >> "$ROOT_DIR/projects/$2"
107 # First, collect the list of Windows files
108 file_prefix="..\\\\src\\\\"
110 # Read the source.list and process it
111 srclist="`cat "$ROOT_DIR/source.list" | tr '\r' '\n' | awk '
112 /^( *)#end/ { if (deep == skip) { skip -= 1; } deep -= 1; next; }
113 /^( *)#else/ { if (deep == skip) { skip -= 1; } else if (deep - 1 == skip) { skip += 1; } next; }
114 /^( *)#if/ {
115 gsub(" ", "", $0);
116 gsub("^#if", "", $0);
117 gsub("^ ", "", $0);
119 if (deep != skip) { deep += 1; next; }
121 deep += 1;
123 if ($0 == "SDL" ) { skip += 1; }
124 if ($0 == "PNG" ) { skip += 1; }
125 if ($0 == "WIN32" ) { skip += 1; }
126 if ($0 == "MSVC" ) { skip += 1; }
127 if ($0 == "DIRECTMUSIC") { skip += 1; }
128 if ($0 == "AI" ) { skip += 1; }
129 if ($0 == "SSE" ) { skip += 1; }
130 if ($0 == "HAVE_THREAD") { skip += 1; }
132 next;
134 /^$/ { next }
136 if (deep == skip) {
137 gsub(" ", "", $0);
138 print;
143 openttd="`echo "$srclist" | awk '
144 BEGIN {
145 configs[0] = "Release|Win32";
146 configs[1] = "Debug|Win32";
147 configs[2] = "Release|x64";
148 configs[3] = "Debug|x64";
150 /^#/ {
151 gsub("^#", "", $0);
152 gsub("^ ", "", $0);
154 if (first_time != 0) {
155 print " </Filter>";
156 } else {
157 first_time = 1;
160 print " <Filter";
161 print " Name=\\""$0"\\"";
162 print " >";
164 next;
167 gsub(" ", "", $0);
168 gsub("/", "\\\\", $0);
169 print " <File";
170 print " RelativePath=\\".\\\\'$file_prefix'"$0"\\"";
171 print " >";
172 ndirs = split($0, dirs, "\\\\");
173 if (ndirs > 1 && match($0, /\.cpp$/)) {
174 dir = "$(IntDir)\\\\";
175 for (i = 1; i < ndirs; i++) {
176 dir = sprintf("%s%s\\\\", dir, dirs[i]);
178 for (i = 0; i < 4; i++) {
179 print " <FileConfiguration";
180 print " Name=\\"" configs[i] "\\"";
181 print " >";
182 print " <Tool";
183 print " Name=\\"VCCLCompilerTool\\"";
184 print " AssemblerListingLocation=\\""dir"\\"";
185 print " ObjectFile=\\""dir"\\"";
186 print " XMLDocumentationFileName=\\""dir"\\"";
187 print " />";
188 print " </FileConfiguration>";
191 print " </File>";
193 END { print " </Filter>"; }
197 openttdvcxproj="`echo "$srclist" | awk '
198 /^#/ { next; }
200 gsub(" ", "", $0);
201 gsub("/", "\\\\", $0);
202 split($0, file, ".");
203 cltype = "ClInclude"
204 if (file[2] == "cpp") cltype = "ClCompile";
205 if (file[2] == "rc") cltype = "ResourceCompile";
207 ndirs = split($0, dirs, "\\\\");
208 if (ndirs > 1 && cltype == "ClCompile") {
209 dir = "$(IntDir)\\\\";
210 for (i = 1; i < ndirs; i++) {
211 dir = sprintf("%s%s\\\\", dir, dirs[i]);
213 print " <ClCompile Include=\\"'$file_prefix'"$0"\\">";
214 print " <AssemblerListingLocation>"dir"</AssemblerListingLocation>";
215 print " <ObjectFileName>"dir"</ObjectFileName>";
216 print " <XMLDocumentationFileName>"dir"</XMLDocumentationFileName>";
217 print " </ClCompile>";
218 } else {
219 print " <"cltype" Include=\\"'$file_prefix'"$0"\\" />";
225 openttdfiles="`echo "$srclist" | awk '
226 /^#/ {
227 gsub("^#", "", $0);
228 gsub("^ ", "", $0);
230 filter = $0;
232 next;
235 gsub(" ", "", $0);
236 gsub("/", "\\\\", $0);
237 split($0, file, ".");
238 cltype = "ClInclude"
239 if (file[2] == "cpp") cltype = "ClCompile";
240 if (file[2] == "rc") cltype = "ResourceCompile";
241 print " <"cltype" Include=\\"'$file_prefix'"$0"\\">";
242 print " <Filter>"filter"</Filter>";
243 print " </"cltype">";
248 openttdfilters="`echo "$srclist" | awk '
249 /^#/ {
250 gsub("^#", "", $0);
251 gsub("^ ", "", $0);
253 print " <Filter Include=\\""$0"\\">";
254 printf " <UniqueIdentifier>{c76ff9f1-1e62-46d8-8d55-%012d}</UniqueIdentifier>\n", i;
255 print " </Filter>";
256 i += 1;
261 generate "$openttd" "openttd_vs80.vcproj"
262 generate "$openttd" "openttd_vs90.vcproj"
263 generate "$openttdvcxproj" "openttd_vs100.vcxproj"
264 generate "$openttdfiles" "openttd_vs100.vcxproj.filters" "$openttdfilters"
265 generate "$openttdvcxproj" "openttd_vs140.vcxproj"
266 generate "$openttdfiles" "openttd_vs140.vcxproj.filters" "$openttdfilters"
269 txtfiles=`ls "$ROOT_DIR"/src/lang/*.txt | sed -e 's,^.*/,,' -e 's/\.txt$//' -e '/^english$/d'`
271 lang=""
272 langvcxproj=""
273 langfiles=""
275 for i in $txtfiles
277 lang="$lang\
278 <File
279 RelativePath=\"..\\src\\lang\\$i.txt\"
281 <FileConfiguration
282 Name=\"Debug|Win32\"
284 <Tool
285 Name=\"VCCustomBuildTool\"
286 Description=\"Generating $i language file\"
287 CommandLine=\"..\\objs\\strgen\\strgen.exe -s ..\\src\\lang -d ..\\bin\\lang &quot;\$(InputPath)&quot;&#x0D;&#x0A;exit 0&#x0D;&#x0A;\"
288 AdditionalDependencies=\"..\\src\\lang\\english.txt;..\\objs\\strgen\\strgen.exe\"
289 Outputs=\"..\\bin\\lang\\$i.lng\"
291 </FileConfiguration>
292 </File>
294 langvcxproj="$langvcxproj\
295 <CustomBuild Include=\"..\\src\\lang\\$i.txt\">
296 <Message Condition=\"'\$(Configuration)|\$(Platform)'=='Debug|Win32'\">Generating $i language file</Message>
297 <Command Condition=\"'\$(Configuration)|\$(Platform)'=='Debug|Win32'\">..\\objs\\strgen\\strgen.exe -s ..\\src\\lang -d ..\\bin\\lang \"%(FullPath)\"</Command>
298 <AdditionalInputs Condition=\"'\$(Configuration)|\$(Platform)'=='Debug|Win32'\">..\\src\\lang\\english.txt;..\\objs\\strgen\\strgen.exe;%(AdditionalInputs)</AdditionalInputs>
299 <Outputs Condition=\"'\$(Configuration)|\$(Platform)'=='Debug|Win32'\">..\\bin\\lang\\$i.lng;%(Outputs)</Outputs>
300 </CustomBuild>
302 langfiles="$langfiles\
303 <CustomBuild Include=\"..\\src\\lang\\$i.txt\">
304 <Filter>Translations</Filter>
305 </CustomBuild>
307 done
309 generate "$lang" "langs_vs80.vcproj"
310 generate "$lang" "langs_vs90.vcproj"
311 generate "$langvcxproj" "langs_vs100.vcxproj"
312 generate "$langfiles" "langs_vs100.vcxproj.filters"
313 generate "$langvcxproj" "langs_vs140.vcxproj"
314 generate "$langfiles" "langs_vs140.vcxproj.filters"
317 inifiles=`ls "$ROOT_DIR"/src/table/*.ini | sed -e 's,^.*/,,'`
319 settings=""
320 settingscommand="..\\objs\\settings\\settings_gen.exe -o ..\\objs\\settings\\table\\settings.h -b ..\\src\\table\\settings.h.preamble -a ..\\src\\table\\settings.h.postamble"
321 settingsvcxproj=""
322 settingsfiles=""
324 for i in $inifiles
326 settings="$settings\
327 <File
328 RelativePath=\"..\\src\\table\\$i\"
330 </File>
332 settingscommand="$settingscommand ..\\src\\table\\$i"
333 settingsvcxproj="$settingsvcxproj\
334 <None Include=\"..\\src\\table\\$i\" />
336 settingsfiles="$settingsfiles\
337 <None Include=\"..\\src\\table\\$i\">
338 <Filter>INI</Filter>
339 </None>
341 done
343 settingscommand="$settingscommand
346 generate "$settings" "settings_vs80.vcproj" "$settingscommand"
347 generate "$settings" "settings_vs90.vcproj" "$settingscommand"
348 generate "$settingsvcxproj" "settings_vs100.vcxproj" "$settingscommand"
349 generate "$settingsfiles" "settings_vs100.vcxproj.filters"
350 generate "$settingsvcxproj" "settings_vs140.vcxproj" "$settingscommand"
351 generate "$settingsfiles" "settings_vs140.vcxproj.filters"