Copyright adjusted to 2009.
[FireMan.git] / scripts / generate.sh
blobf4b04dfff73b4b0a7ca8bcd88edba6014d1c20bb
1 #/bin/sh
3 # Copyright (c) 2008,2009 Tobias Sarnowski <sarnowski@new-thoughts.org>
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 # get configfile to use
18 if [ -z "$1" ] || [ ! -r "$1" ]; then
19 echo "Usage: $0 <configfile>" >&2
20 exit 1
23 # get absolute path of project
24 cd $(dirname $1)
25 PROJECTDIR=$(pwd)
27 # set paths
28 configfile=$PROJECTDIR/$(basename $1)
30 SED=sed
31 # find the right "sed"
32 # use GNU sed if available, nessecary on OpenBSD
33 # cause sed don't supports -i (infile)
34 [ ! -z "$(which gsed)" ] && SED=gsed
37 # include config file for direct usage of variables
38 . $configfile
40 # reset paths to absolute
41 BUILDDIR=$PROJECTDIR/$BUILDDIR
42 SRCDIR=$PROJECTDIR/$SRCDIR
44 # create temporary directory
45 mkdir -p $BUILDDIR
47 # make the source dir the working dir so that
48 # find prints relative paths
49 cd $SRCDIR
51 # find out the actual version
52 VERSION=$(../scripts/generate_version.sh)
53 VERSION_FULL=$(../scripts/generate_version.sh --full)
54 echo " VSN $VERSION_FULL"
56 # process every listed file
57 find $FILES_TO_PROCESS | while read file; do
58 if [ -d $file ] && [ ! -d $BUILDDIR/$file ]; then
59 # create the directory
60 echo " DIR $file"
61 mkdir -p $BUILDDIR/$file
63 elif [ -f $file ]; then
65 # already processed?
66 if [ $file -ot $BUILDDIR/$file ]; then
67 continue
70 # what type of file do we have?
71 filetype=$(file $file | cut -d' ' -f2)
72 if [ "$filetype" = "ASCII" ] \
73 || [ "$filetype" = "XML" ] \
74 || [ "$filetype" = "HTML" ]
75 then
76 # copy over file
77 echo " GEN $file"
78 cp $file $BUILDDIR/$file
80 # insert version
81 $SED "s/%%VERSION%%/$VERSION/g" -i $BUILDDIR/$file
82 $SED "s/%%VERSION_FULL%%/$VERSION_FULL/g" -i $BUILDDIR/$file
84 # parse the config file
85 cat $configfile | while read line; do
87 # strip comments
88 line=$(echo $line | sed 's/#.*//')
90 # sort out invalid lines
91 if [ -z "$(echo $line | grep '=')" ]; then
92 continue;
95 # split line
96 key=$(echo $line | cut -d'=' -f1)
97 value=$(echo $line | cut -d'=' -f2-)
99 # do not process special keywords
100 case "$key" in
101 "FILES_TO_PROCESS") continue;;
102 "BUILDDIR") continue;;
103 esac
105 # strip " from strings
106 value=$(echo $value | sed 's/^"//' | sed 's/"$//')
108 # escape / to \/
109 value=$(echo $value | sed 's/\//\\\//')
111 # replace %%<key>%% with <value>
112 $SED "s/%%$key%%/$value/g" -i $BUILDDIR/$file
113 done
114 else
115 # no ASCII file
116 # copy over file
117 echo " CPY $file"
118 cp $file $BUILDDIR/$file
121 done