Fix e8d397e4ee: Avoid using RemapCoords2 during savegame conversion. (#7588)
[openttd-github.git] / projects / gen-kdev4.sh
blob4ea5dbc2a80b4dce34c52049caf7c245e42445b8
1 #!/bin/sh
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 # echo without interpretation of backslash escapes and without
11 # adding newline at the end - just the string as it is
12 rawprint()
14 printf '%s' "$@"
17 encode_dword()
19 printf '\x%02x' \
20 `expr $1 / 16777216 % 256` \
21 `expr $1 / 65536 % 256` \
22 `expr $1 / 256 % 256` \
23 `expr $1 % 256`
26 encode_string()
28 # turn string into UTF-16 and hexdump it
29 hex_utf16=`rawprint "$1" | iconv -t UTF-16BE | od -t x1 -A n | tr -d -c '[:xdigit:]'`;
31 encode_dword `rawprint "$hex_utf16" | wc -m | xargs -I {} expr {} / 2` # length = num hex digits / 2
32 rawprint "$hex_utf16" | sed 's/../\\x&/g' # put '\x' prefix before every pair of digits
35 encode_single_define()
37 encode_string `rawprint "$1" | grep -o '^[^=]*'` # everything before '='
38 rawprint '\x00\x00\x00\n\x00'
39 encode_string `rawprint "$1" | sed 's/^[^=]*=\?//'` # everything after '='
42 # $1 - newline-separated list of defines
43 encode_defines()
45 # add some fixed defines and discard empty lines from the tail
46 defines=`printf 'va_list\nva_args\n%s' "$1"`
48 # count lines (no newline at the end so add one)
49 encode_dword `printf '%s\n' "$defines" | wc -l`
51 while [ -n "$defines" ]; do
52 encode_single_define `rawprint "$defines" | head -n 1`
53 defines=`rawprint "$defines" | tail -n +2`
54 done
57 encode_includes()
59 encode_dword 3 # number of custom includes
60 encode_string "$1/src/stdafx.h"
61 encode_string "$1/objs/lang"
62 encode_string "$1/objs/setting"
65 # escape with a backslash (\) characters special to the sed replace string: \ &
66 # also escape our custom filed separator that we will be using in sed: @
67 escape_sed_special()
69 sed -e 's/[\&@]/\\&/g'
74 PROJECT_DIR=`pwd`
75 DIR_NAME=`pwd | xargs -0 basename`
77 USAGE_TEXT='Usage:
79 projects/gen-kdev4 [PROJECT_NAME|-h|--help]
81 PROJECT_NAME is the name of the project that will be displayed in KDevelop.
82 Before executing, cd into OpenTTD folder and run ./configure script.
84 -h, --help
85 print help and exit'
87 case "$# $1" in
88 '1 -h' | '1 --help') printf 'Generate OpenTTD project files for KDevelop 4+\n\n%s\n' "$USAGE_TEXT"; exit 0;;
89 1*) PROJECT_NAME="$1";;
90 0*) PROJECT_NAME="$DIR_NAME";;
91 *) printf 'Wrong arguments given. %s\n' "$USAGE_TEXT" >&2; exit 1;;
92 esac
94 CFLAGS=`grep '^using CFLAGS\.\.\.' config.log 2>/dev/null`
95 if [ -z "$CFLAGS" ]; then
96 echo "OpenTTD config.log not found" >&2
97 echo "cd into OpenTTD first and run 'configure'" >&2
98 exit 1
100 DEFINES=`eval "printf '%s\n' $CFLAGS" | grep '^\-D' | cut -c3-`
102 PROJECT_NAME_SED=s@!!PROJECT_NAME!!@`rawprint "$PROJECT_NAME" | escape_sed_special`@g
103 PROJECT_DIR_SED=s@!!PROJECT_DIR!!@`rawprint "$PROJECT_DIR" | escape_sed_special`@g
104 CUSTOM_DEFINES_SED=s@!!CUSTOM_DEFINES!!@`encode_defines "$DEFINES" | escape_sed_special`@g
105 CUSTOM_INCLUDES_SED=s@!!CUSTOM_INCLUDES!!@`encode_includes "$PROJECT_DIR" | escape_sed_special`@g
107 mkdir -p .kdev4
109 sed -e "$PROJECT_NAME_SED" \
110 >"$PROJECT_DIR/$DIR_NAME.kdev4" \
111 << "EOF"
112 [Project]
113 Manager=KDevCustomMakeManager
114 Name=!!PROJECT_NAME!!
117 sed -e "$PROJECT_DIR_SED" -e "$CUSTOM_DEFINES_SED" -e "$CUSTOM_INCLUDES_SED" \
118 >"$PROJECT_DIR/.kdev4/$DIR_NAME.kdev4" \
119 << "EOF"
120 [CustomDefinesAndIncludes][ProjectPath0]
121 Defines=!!CUSTOM_DEFINES!!
122 Includes=!!CUSTOM_INCLUDES!!
123 Path=.
125 [Defines And Includes][Compiler]
126 Name=GCC
127 Path=gcc
128 Type=GCC
130 [Filters]
131 size=10
133 [Filters][0]
134 inclusive=0
135 pattern=.*
136 targets=3
138 [Filters][1]
139 inclusive=0
140 pattern=.svn
141 targets=2
143 [Filters][2]
144 inclusive=0
145 pattern=.hg
146 targets=2
148 [Filters][3]
149 inclusive=0
150 pattern=.git
151 targets=2
153 [Filters][4]
154 inclusive=0
155 pattern=*.rej
156 targets=1
158 [Filters][5]
159 inclusive=0
160 pattern=*.orig
161 targets=1
163 [Filters][6]
164 inclusive=0
165 pattern=*~
166 targets=1
168 [Filters][7]
169 inclusive=0
170 pattern=.*.kate-swp
171 targets=1
173 [Filters][8]
174 inclusive=0
175 pattern=.*.swp
176 targets=1
178 [Filters][9]
179 inclusive=0
180 pattern=/objs
181 targets=2
183 [Launch]
184 Launch Configurations=Launch Configuration 0
186 [Launch][Launch Configuration 0]
187 Configured Launch Modes=execute
188 Configured Launchers=nativeAppLauncher
189 Name=Launch OpenTTD\s
190 Type=Native Application
192 [Launch][Launch Configuration 0][Data]
193 Arguments=-d 1
194 Dependencies=@Variant(\x00\x00\x00\t\x00\x00\x00\x00\x00)
195 Dependency Action=Nothing
196 EnvironmentGroup=
197 Executable=file://!!PROJECT_DIR!!/bin/openttd
198 External Terminal=konsole --noclose --workdir %workdir -e %exe
199 Project Target=
200 Use External Terminal=false
201 Working Directory=file://!!PROJECT_DIR!!/bin
202 isExecutable=true