(svn r28004) -Update from Eints:
[openttd.git] / projects / generate
blobe82559a911ffe2d548fc37462d41076d88483afd
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
68 # First, collect the list of Windows files
69 allegro_config=""
70 sdl_config="1"
71 png_config="1"
72 os="MSVC"
73 enable_dedicated="0"
74 enable_ai="1"
75 with_cocoa="0"
76 enable_directmusic="1"
77 with_threads="1"
78 file_prefix="..\\\\src\\\\"
80 safety_check() {
81 li=""
82 for i in `cat $1 | grep -v "#\|ottdres.rc\|win32.cpp\|win32_v.cpp" | xargs -n 1 basename | sort`; do
83 if [ "$li" = "$i" ]; then
84 echo " !! ERROR !!"
85 echo ""
86 echo "The filename '$i' is already used in this project."
87 echo "Because MSVC uses one single directory for all object files, it"
88 echo "cannot handle filenames with the same name inside the same project."
89 echo "Please rename either one of the file and try generating again."
90 echo ""
91 echo " !! ERROR !!"
92 exit 1
94 li="$i"
95 done
98 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
99 find "$ROOT_DIR/src" \( -iname "*.h" -or -iname "*.hpp" \) -and -not -ipath "*/.svn/*" | sed "s~$ROOT_DIR/src/~~" | sort > tmp.headers.src
100 if [ -n "`diff tmp.headers.source.list tmp.headers.src`" ]; then
101 echo "The following headers are missing in source.list and not in /src/ or vice versa."
102 diff tmp.headers.source.list tmp.headers.src | grep '[<>]' | sort
103 echo ""
105 rm tmp.headers.*
107 load_main_data() {
108 # Read the source.list and process it
109 RES="`cat $1 | tr '\r' '\n' | awk '
110 /^( *)#end/ { if (deep == skip) { skip -= 1; } deep -= 1; next; }
111 /^( *)#else/ { if (deep == skip) { skip -= 1; } else if (deep - 1 == skip) { skip += 1; } next; }
112 /^( *)#if/ {
113 gsub(" ", "", $0);
114 gsub("^#if", "", $0);
115 gsub("^ ", "", $0);
117 if (deep != skip) { deep += 1; next; }
119 deep += 1;
121 if ($0 == "ALLEGRO" && "'$allegro_config'" == "") { next; }
122 if ($0 == "SDL" && "'$sdl_config'" == "") { next; }
123 if ($0 == "PNG" && "'$png_config'" == "") { next; }
124 if ($0 == "OSX" && "'$os'" != "OSX") { next; }
125 if ($0 == "OS2" && "'$os'" != "OS2") { next; }
126 if ($0 == "PSP" && "'$os'" != "PSP") { next; }
127 if ($0 == "DOS" && "'$os'" != "DOS") { next; }
128 if ($0 == "DEDICATED" && "'$enable_dedicated'" != "1") { next; }
129 if ($0 == "AI" && "'$enable_ai'" == "0") { next; }
130 if ($0 == "COCOA" && "'$with_cocoa'" == "0") { next; }
131 if ($0 == "BEOS" && "'$os'" != "BEOS") { next; }
132 if ($0 == "WIN32" && "'$os'" != "MINGW" &&
133 "'$os'" != "CYGWIN" && "'$os'" != "MSVC" ) { next; }
134 if ($0 == "WINCE" && "'$os'" != "WINCE") { next; }
135 if ($0 == "MSVC" && "'$os'" != "MSVC") { next; }
136 if ($0 == "DIRECTMUSIC" && "'$enable_directmusic'" != "1") { next; }
137 if ($0 == "LIBTIMIDITY" && "'$libtimidity'" == "" ) { next; }
138 if ($0 == "HAVE_THREAD" && "'$with_threads'" == "0") { next; }
140 skip += 1;
142 next;
144 /^( *)#/ {
145 if (deep == skip) {
146 gsub(" ", "", $0);
147 gsub("^#", "", $0);
148 gsub("^ ", "", $0);
150 if (first_time != 0) {
151 print "#1 </Filter>";
152 } else {
153 first_time = 1;
156 filter = $0;
157 print "#1 <Filter";
158 print "#1 Name=\\""filter"\\"";
159 print "#1 >";
160 print "#3 <Filter Include=\\""filter"\\">";
161 printf "#3 <UniqueIdentifier>{c76ff9f1-1e62-46d8-8d55-%012d}</UniqueIdentifier>\n", i;
162 print "#3 </Filter>";
163 i += 1;
166 next;
168 /^$/ { next }
170 if (deep == skip) {
171 gsub(" ", "", $0);
172 gsub("/", "\\\\", $0);
173 print "#1 <File";
174 print "#1 RelativePath=\\".\\\\'$file_prefix'"$0"\\"";
175 print "#1 >";
176 print "#1 </File>";
177 split($0, file, ".");
178 cltype = "ClInclude"
179 if (file[2] == "cpp") cltype = "ClCompile";
180 if (file[2] == "rc") cltype = "ResourceCompile";
181 print "#2 <"cltype" Include=\\"'$file_prefix'"$0"\\" />";
182 print "#4 <"cltype" Include=\\"'$file_prefix'"$0"\\">";
183 print "#4 <Filter>"filter"</Filter>";
184 print "#4 </"cltype">";
187 END { print "#1 </Filter>"; }
190 eval "$2=\"\$RES\""
193 load_lang_data() {
194 RES=""
195 for i in `ls $1`
197 i=`basename $i | sed s~.txt$~~g`
198 if [ "$i" == "english" ]
199 then
200 continue
202 RES="$RES
203 #1 <File
204 #1 RelativePath=\"..\\src\\lang\\"$i".txt\"
205 #1 >
206 #1 <FileConfiguration
207 #1 Name=\"Debug|Win32\"
208 #1 >
209 #1 <Tool
210 #1 Name=\"VCCustomBuildTool\"
211 #1 Description=\"Generating "$i" language file\"
212 #1 CommandLine=\"..\\objs\\strgen\\strgen.exe -s ..\\src\\lang -d ..\\bin\\lang &quot;\$(InputPath)&quot;&#x0D;&#x0A;exit 0&#x0D;&#x0A;\"
213 #1 AdditionalDependencies=\"..\\src\\lang\\english.txt;..\\objs\\strgen\\strgen.exe\"
214 #1 Outputs=\"..\\bin\\lang\\"$i".lng\"
215 #1 />
216 #1 </FileConfiguration>
217 #1 </File>
218 #2 <CustomBuild Include=\"..\\src\\lang\\"$i".txt\">
219 #2 <Message Condition=\"'\$(Configuration)|\$(Platform)'=='Debug|Win32'\">Generating "$i" language file</Message>
220 #2 <Command Condition=\"'\$(Configuration)|\$(Platform)'=='Debug|Win32'\">..\\objs\\strgen\\strgen.exe -s ..\\src\\lang -d ..\\bin\\lang \"%(FullPath)\"</Command>
221 #2 <AdditionalInputs Condition=\"'\$(Configuration)|\$(Platform)'=='Debug|Win32'\">..\\src\\lang\\english.txt;..\\objs\\strgen\\strgen.exe;%(AdditionalInputs)</AdditionalInputs>
222 #2 <Outputs Condition=\"'\$(Configuration)|\$(Platform)'=='Debug|Win32'\">..\\bin\\lang\\"$i".lng;%(Outputs)</Outputs>
223 #2 </CustomBuild>
224 #3 <CustomBuild Include=\"..\\src\\lang\\"$i".txt\">
225 #3 <Filter>Translations</Filter>
226 #3 </CustomBuild>"
227 done
229 eval "$2=\"\$RES\""
232 load_settings_data() {
233 RES=""
234 RES2="
235 #3..\\objs\\settings\\settings_gen.exe -o ..\\objs\\settings\\table\\settings.h -b ..\\src\\table\\settings.h.preamble -a ..\\src\\table\\settings.h.postamble"
236 for i in `ls $1`
238 i=`basename $i`
239 RES="$RES
240 #1 <File
241 #1 RelativePath=\"..\\src\\table\\"$i"\"
242 #1 >
243 #1 </File>
244 #2 <None Include=\"..\\src\\table\\"$i"\" />
245 #4 <None Include=\"..\\src\\table\\"$i"\">
246 #4 <Filter>INI</Filter>
247 #4 </None>"
248 RES2="$RES2 ..\\src\\table\\"$i
249 done
251 eval "$2=\"\$RES\$RES2\""
254 generate() {
255 echo "Generating $2..."
256 if [ $# -eq 3 ]; then
257 # Everything above the !!FILTERS!! marker
258 cat "$ROOT_DIR/projects/$2".in | tr '\r' '\n' | awk '
259 /^$/ { next }
260 /!!FILTERS!!/ { stop = 1; }
262 if (stop == 0) { print $0 }
264 ' > "$ROOT_DIR/projects/$2"
266 echo "$3" >> "$ROOT_DIR/projects/$2"
268 # Everything below the !!FILTERS!! marker and above the !!FILES!! marker
269 cat "$ROOT_DIR/projects/$2".in | tr '\r' '\n' | awk '
270 BEGIN { stop = 1; }
271 /^$/ { next }
272 /!!FILTERS!!/ { stop = 2; }
273 /!!FILES!!/ { stop = 1; }
275 if (stop == 0) { print $0 }
276 if (stop == 2) { stop = 0 }
278 ' >> "$ROOT_DIR/projects/$2"
279 else
280 # Everything above the !!FILES!! marker
281 cat "$ROOT_DIR/projects/$2".in | tr '\r' '\n' | awk '
282 /^$/ { next }
283 /!!FILES!!/ { stop = 1; }
285 if (stop == 0) { print $0 }
287 ' > "$ROOT_DIR/projects/$2"
290 echo "$1" >> "$ROOT_DIR/projects/$2"
292 # Everything below the !!FILES!! marker
293 cat "$ROOT_DIR/projects/$2".in | tr '\r' '\n' | awk '
294 BEGIN { stop = 1; }
295 /^$/ { next }
296 /!!FILES!!/ { stop = 2; }
298 if (stop == 0) { print $0 }
299 if (stop == 2) { stop = 0 }
301 ' >> "$ROOT_DIR/projects/$2"
304 safety_check "$ROOT_DIR/source.list"
306 load_main_data "$ROOT_DIR/source.list" openttd
307 openttdfiles=`echo "$openttd" | grep "^#4" | sed "s~#4~~g"`
308 openttdfilters=`echo "$openttd" | grep "^#3" | sed "s~#3~~g"`
309 openttdvcxproj=`echo "$openttd" | grep "^#2" | sed "s~#2~~g"`
310 openttd=`echo "$openttd" | grep "^#1" | sed "s~#1~~g"`
312 load_lang_data "$ROOT_DIR/src/lang/*.txt" lang
313 langfiles=`echo "$lang" | grep "^#3" | sed "s~#3~~g"`
314 langvcxproj=`echo "$lang" | grep "^#2" | sed "s~#2~~g"`
315 lang=`echo "$lang" | grep "^#1" | sed "s~#1~~g"`
317 load_settings_data "$ROOT_DIR/src/table/*.ini" settings
318 settingsfiles=`echo "$settings" | grep "^#4" | sed "s~#4~~g"`
319 settingscommand=`echo "$settings" | grep "^#3" | sed "s~#3~~g"`
320 settingsvcxproj=`echo "$settings" | grep "^#2" | sed "s~#2~~g"`
321 settings=`echo "$settings" | grep "^#1" | sed "s~#1~~g"`
323 generate "$openttd" "openttd_vs80.vcproj"
324 generate "$openttd" "openttd_vs90.vcproj"
325 generate "$openttdvcxproj" "openttd_vs100.vcxproj"
326 generate "$openttdfiles" "openttd_vs100.vcxproj.filters" "$openttdfilters"
327 generate "$openttdvcxproj" "openttd_vs140.vcxproj"
328 generate "$openttdfiles" "openttd_vs140.vcxproj.filters" "$openttdfilters"
329 generate "$openttdvcxproj" "openttd_vs141.vcxproj"
330 generate "$openttdfiles" "openttd_vs141.vcxproj.filters" "$openttdfilters"
331 generate "$lang" "langs_vs80.vcproj"
332 generate "$lang" "langs_vs90.vcproj"
333 generate "$langvcxproj" "langs_vs100.vcxproj"
334 generate "$langfiles" "langs_vs100.vcxproj.filters"
335 generate "$langvcxproj" "langs_vs140.vcxproj"
336 generate "$langfiles" "langs_vs140.vcxproj.filters"
337 generate "$langvcxproj" "langs_vs141.vcxproj"
338 generate "$langfiles" "langs_vs141.vcxproj.filters"
339 generate "$settings" "settings_vs80.vcproj" "$settingscommand"
340 generate "$settings" "settings_vs90.vcproj" "$settingscommand"
341 generate "$settingsvcxproj" "settings_vs100.vcxproj" "$settingscommand"
342 generate "$settingsfiles" "settings_vs100.vcxproj.filters"
343 generate "$settingsvcxproj" "settings_vs140.vcxproj" "$settingscommand"
344 generate "$settingsfiles" "settings_vs140.vcxproj.filters"
345 generate "$settingsvcxproj" "settings_vs141.vcxproj" "$settingscommand"
346 generate "$settingsfiles" "settings_vs141.vcxproj.filters"