2007-01-02 19:19:48 +00:00
#!/bin/bash
2009-08-21 20:21:05 +00:00
# $Id$
# This file is part of OpenTTD.
# 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.
# 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.
# 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/>.
2007-01-02 19:19:48 +00:00
# This file generates all project files based on sources.list, so everyone who
# can start a bash process, can update the project files.
ROOT_DIR="`pwd`/.."
if ! [ -e "$ROOT_DIR/source.list" ]
then
ROOT_DIR="`pwd`"
fi
if ! [ -e "$ROOT_DIR/source.list" ]
then
echo "Can't find source.list, needed in order to make this run. Please go to either"
echo " the project dir, or the root dir of a clean SVN checkout."
exit 1
fi
2010-06-28 19:07:33 +00:00
# openttd_vs100.sln is for MSVC 2010
# openttd_vs100.vcxproj is for MSVC 2010
# openttd_vs100.vcxproj.filters is for MSVC 2010
# langs_vs100.vcxproj is for MSVC 2010
# strgen_vs100.vcxproj is for MSVC 2010
# strgen_vs100.vcxproj.filters is for MSVC 2010
# generate_vs100.vcxproj is for MSVC 2010
# version_vs100.vcxproj is for MSVC 2010
2007-11-17 02:22:56 +00:00
2010-06-28 19:07:33 +00:00
# openttd_vs90.sln is for MSVC 2008
# openttd_vs90.vcproj is for MSVC 2008
# langs_vs90.vcproj is for MSVC 2008
# strgen_vs90.vcproj is for MSVC 2008
# generate_vs90.vcproj is for MSVC 2008
# version_vs90.vcproj is for MSVC 2008
# openttd_vs80.sln is for MSVC 2005
# openttd_vs80.vcproj is for MSVC 2005
# langs_vs80.vcproj is for MSVC 2005
# strgen_vs80.vcproj is for MSVC 2005
# generate_vs80.vcproj is for MSVC 2005
# version_vs80.vcproj is for MSVC 2005
2007-01-02 19:19:48 +00:00
# First, collect the list of Windows files
2008-11-25 19:32:12 +00:00
allegro_config=""
2007-01-02 19:19:48 +00:00
sdl_config="1"
2007-06-13 18:52:06 +00:00
png_config="1"
2007-01-02 19:19:48 +00:00
os="MSVC"
enable_dedicated="0"
2010-02-10 16:24:05 +00:00
enable_ai="1"
2007-01-02 19:19:48 +00:00
with_cocoa="0"
enable_directmusic="1"
2007-07-20 18:34:21 +00:00
with_threads="1"
2007-01-02 19:19:48 +00:00
file_prefix="..\\\\src\\\\"
2007-06-17 20:14:38 +00:00
safety_check() {
li=""
2007-06-17 20:30:28 +00:00
for i in `cat $1 | grep -v "#\|ottdres.rc\|win32.cpp\|win32_v.cpp" | xargs -n 1 basename | sort`; do
2007-06-17 20:14:38 +00:00
if [ "$li" = "$i" ]; then
echo " !! ERROR !!"
echo ""
echo "The filename '$i' is already used in this project."
echo "Because MSVC uses one single directory for all object files, it"
echo "cannot handle filenames with the same name inside the same project."
echo "Please rename either one of the file and try generating again."
echo ""
echo " !! ERROR !!"
exit 1
fi
li="$i"
done
}
2008-11-25 19:26:31 +00:00
grep '\.h' "$ROOT_DIR/source.list" | grep -v '../objs/langs/table/strings.h' | sed 's/ //' | sort > tmp.headers.source.list
2008-10-14 19:47:28 +00:00
find "$ROOT_DIR/src" \( -iname "*.h" -or -iname "*.hpp" \) -and -not -ipath "*/.svn/*" | sed "s~$ROOT_DIR/src/~~" | sort > tmp.headers.src
2008-04-18 09:49:23 +00:00
if [ -n "`diff tmp.headers.source.list tmp.headers.src`" ]; then
echo "The following headers are missing in source.list and not in /src/ or vice versa."
diff tmp.headers.source.list tmp.headers.src | grep '[<>]' | sort
echo ""
fi
rm tmp.headers.*
2007-01-02 19:19:48 +00:00
load_main_data() {
# Read the source.list and process it
2007-01-03 22:24:36 +00:00
RES="`cat $1 | tr '\r' '\n' | awk '
2007-01-02 19:19:48 +00:00
/^( *)#end/ { if (deep == skip) { skip -= 1; } deep -= 1; next; }
/^( *)#else/ { if (deep == skip) { skip -= 1; } else if (deep - 1 == skip) { skip += 1; } next; }
/^( *)#if/ {
gsub(" ", "", $0);
gsub("^#if", "", $0);
gsub("^ ", "", $0);
if (deep != skip) { deep += 1; next; }
deep += 1;
2008-11-25 19:32:12 +00:00
if ($0 == "ALLEGRO" && "'$allegro_config'" == "") { next; }
2007-01-02 19:19:48 +00:00
if ($0 == "SDL" && "'$sdl_config'" == "") { next; }
2007-06-13 18:52:06 +00:00
if ($0 == "PNG" && "'$png_config'" == "") { next; }
2007-01-02 19:19:48 +00:00
if ($0 == "OSX" && "'$os'" != "OSX") { next; }
2007-02-17 12:50:19 +00:00
if ($0 == "OS2" && "'$os'" != "OS2") { next; }
if ($0 == "PSP" && "'$os'" != "PSP") { next; }
2008-12-03 00:19:06 +00:00
if ($0 == "DOS" && "'$os'" != "DOS") { next; }
2007-01-02 19:19:48 +00:00
if ($0 == "DEDICATED" && "'$enable_dedicated'" != "1") { next; }
2010-02-10 16:24:05 +00:00
if ($0 == "AI" && "'$enable_ai'" == "0") { next; }
2007-01-02 19:19:48 +00:00
if ($0 == "COCOA" && "'$with_cocoa'" == "0") { next; }
if ($0 == "BEOS" && "'$os'" != "BEOS") { next; }
if ($0 == "WIN32" && "'$os'" != "MINGW" &&
"'$os'" != "CYGWIN" && "'$os'" != "MSVC" ) { next; }
2007-01-21 19:40:38 +00:00
if ($0 == "WINCE" && "'$os'" != "WINCE") { next; }
2007-01-02 19:19:48 +00:00
if ($0 == "MSVC" && "'$os'" != "MSVC") { next; }
if ($0 == "DIRECTMUSIC" && "'$enable_directmusic'" != "1") { next; }
2007-02-17 12:50:19 +00:00
if ($0 == "LIBTIMIDITY" && "'$libtimidity'" == "" ) { next; }
2008-04-14 19:54:33 +00:00
if ($0 == "HAVE_THREAD" && "'$with_threads'" == "0") { next; }
2007-01-02 19:19:48 +00:00
skip += 1;
next;
}
/^( *)#/ {
if (deep == skip) {
gsub(" ", "", $0);
gsub("^#", "", $0);
gsub("^ ", "", $0);
if (first_time != 0) {
2010-06-28 19:07:33 +00:00
print "#1 </Filter>";
2007-01-02 19:19:48 +00:00
} else {
first_time = 1;
}
2010-06-28 19:07:33 +00:00
filter = $0;
print "#1 <Filter";
print "#1 Name=\\""filter"\\"";
print "#1 >";
print "#3 <Filter Include=\\""filter"\\">";
printf "#3 <UniqueIdentifier>{c76ff9f1-1e62-46d8-8d55-%012d}</UniqueIdentifier>\n", i;
print "#3 </Filter>";
i += 1;
2007-01-02 19:19:48 +00:00
}
next;
}
/^$/ { next }
{
if (deep == skip) {
gsub(" ", "", $0);
gsub("/", "\\\\", $0);
2010-06-28 19:07:33 +00:00
print "#1 <File";
print "#1 RelativePath=\\".\\\\'$file_prefix'"$0"\\"";
print "#1 >";
print "#1 </File>";
split($0, file, ".");
cltype = "ClInclude"
if (file[2] == "cpp") cltype = "ClCompile";
if (file[2] == "rc") cltype = "ResourceCompile";
print "#2 <"cltype" Include=\\"'$file_prefix'"$0"\\" />";
print "#4 <"cltype" Include=\\"'$file_prefix'"$0"\\">";
print "#4 <Filter>"filter"</Filter>";
print "#4 </"cltype">";
2007-01-02 19:19:48 +00:00
}
}
2010-06-28 19:07:33 +00:00
END { print "#1 </Filter>"; }
2007-01-03 22:24:36 +00:00
'`"
2007-01-02 19:19:48 +00:00
eval "$2=\"\$RES\""
}
load_lang_data() {
RES=""
for i in `ls $1`
do
2008-10-14 19:47:28 +00:00
i=`basename $i | sed s~.txt$~~g`
2007-01-02 19:19:48 +00:00
RES="$RES
2010-06-28 19:07:33 +00:00
#1 <File
#1 RelativePath=\"..\\src\\lang\\"$i".txt\"
#1 >
#1 <FileConfiguration
#1 Name=\"Debug|Win32\"
#1 >
#1 <Tool
#1 Name=\"VCCustomBuildTool\"
#1 Description=\"Generating "$i" language file\"
#1 CommandLine=\"..\\objs\\strgen\\strgen.exe -s ..\\src\\lang -d ..\\bin\\lang "\$(InputPath)"
exit 0
\"
#1 AdditionalDependencies=\"..\\src\\lang\\english.txt;..\\objs\\strgen\\strgen.exe\"
#1 Outputs=\"..\\bin\\lang\\"$i".lng\"
#1 />
#1 </FileConfiguration>
#1 </File>
#2 <CustomBuild Include=\"..\\src\\lang\\"$i".txt\">
#2 <Message Condition=\"'\$(Configuration)|\$(Platform)'=='Debug|Win32'\">Generating "$i" language file</Message>
#2 <Command Condition=\"'\$(Configuration)|\$(Platform)'=='Debug|Win32'\">..\\objs\\strgen\\strgen.exe -s ..\\src\\lang -d ..\\bin\\lang \"%(FullPath)\"</Command>
#2 <AdditionalInputs Condition=\"'\$(Configuration)|\$(Platform)'=='Debug|Win32'\">..\\src\\lang\\english.txt;..\\objs\\strgen\\strgen.exe;%(AdditionalInputs)</AdditionalInputs>
#2 <Outputs Condition=\"'\$(Configuration)|\$(Platform)'=='Debug|Win32'\">..\\bin\\lang\\"$i".lng;%(Outputs)</Outputs>
#2 </CustomBuild>"
2007-01-02 19:19:48 +00:00
done
eval "$2=\"\$RES\""
}
generate() {
echo "Generating $2..."
2010-06-28 19:07:33 +00:00
if [ $# -eq 3 ]; then
# Everything above the !!FILTERS!! marker
cat "$ROOT_DIR/projects/$2".in | tr '\r' '\n' | awk '
/^$/ { next }
/!!FILTERS!!/ { stop = 1; }
{
if (stop == 0) { print $0 }
}
' > "$ROOT_DIR/projects/$2"
echo "$3" >> "$ROOT_DIR/projects/$2"
# Everything below the !!FILTERS!! marker and above the !!FILES!! marker
cat "$ROOT_DIR/projects/$2".in | tr '\r' '\n' | awk '
BEGIN { stop = 1; }
/^$/ { next }
/!!FILTERS!!/ { stop = 2; }
/!!FILES!!/ { stop = 1; }
{
if (stop == 0) { print $0 }
if (stop == 2) { stop = 0 }
}
' >> "$ROOT_DIR/projects/$2"
else
# Everything above the !!FILES!! marker
cat "$ROOT_DIR/projects/$2".in | tr '\r' '\n' | awk '
/^$/ { next }
/!!FILES!!/ { stop = 1; }
{
if (stop == 0) { print $0 }
}
' > "$ROOT_DIR/projects/$2"
fi
2007-01-02 19:19:48 +00:00
2008-01-24 18:47:05 +00:00
echo "$1" >> "$ROOT_DIR/projects/$2"
2007-01-02 19:19:48 +00:00
# Everything below the !!FILES!! marker
2007-02-28 23:52:04 +00:00
cat "$ROOT_DIR/projects/$2".in | tr '\r' '\n' | awk '
2007-01-02 19:19:48 +00:00
BEGIN { stop = 1; }
2007-01-03 22:24:36 +00:00
/^$/ { next }
2007-01-02 19:19:48 +00:00
/!!FILES!!/ { stop = 2; }
{
if (stop == 0) { print $0 }
if (stop == 2) { stop = 0 }
}
2007-02-28 23:52:04 +00:00
' >> "$ROOT_DIR/projects/$2"
2007-01-02 19:19:48 +00:00
}
2007-06-17 20:14:38 +00:00
safety_check "$ROOT_DIR/source.list"
2007-01-02 19:19:48 +00:00
load_main_data "$ROOT_DIR/source.list" openttd
2010-06-28 19:07:33 +00:00
openttdfiles=`echo "$openttd" | grep "^#4" | sed "s~#4~~g"`
openttdfilters=`echo "$openttd" | grep "^#3" | sed "s~#3~~g"`
openttdvcxproj=`echo "$openttd" | grep "^#2" | sed "s~#2~~g"`
openttd=`echo "$openttd" | grep "^#1" | sed "s~#1~~g"`
2007-01-02 19:19:48 +00:00
load_lang_data "$ROOT_DIR/src/lang/*.txt" lang
2010-06-28 19:07:33 +00:00
langvcxproj=`echo "$lang" | grep "^#2" | sed "s~#2~~g"`
lang=`echo "$lang" | grep "^#1" | sed "s~#1~~g"`
2007-01-02 19:19:48 +00:00
2008-01-24 18:47:05 +00:00
generate "$openttd" "openttd_vs80.vcproj"
generate "$openttd" "openttd_vs90.vcproj"
2010-06-28 19:07:33 +00:00
generate "$openttdvcxproj" "openttd_vs100.vcxproj"
generate "$openttdfiles" "openttd_vs100.vcxproj.filters" "$openttdfilters"
2008-01-24 18:47:05 +00:00
generate "$lang" "langs_vs80.vcproj"
generate "$lang" "langs_vs90.vcproj"
2010-06-28 19:07:33 +00:00
generate "$langvcxproj" "langs_vs100.vcxproj"