-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdevelopers.sh
executable file
·203 lines (183 loc) · 5.63 KB
/
developers.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#!/bin/bash
#
# File: developers.sh
#
# LibSylph Class Library (build script)
# Copyright (C) 2013 Frank "SeySayux" Erens <seysayux@gmail.com>
#
# This software is provided 'as-is', without any express or implied
# warranty. In no event will the authors be held liable for any damages
# arising from the use of this software.
#
# Permission is granted to anyone to use this software for any purpose,
# including commercial applications, and to alter it and redistribute it
# freely, subject to the following restrictions:
#
# 1. The origin of this software must not be misrepresented; you must not
# claim that you wrote the original software. If you use this software
# in a product, an acknowledgment in the product documentation would be
# appreciated but is not required.
#
# 2. Altered source versions must be plainly marked as such, and must not be
# misrepresented as being the original software.
#
# 3. This notice may not be removed or altered from any source
# distribution.
#
#########################################################################
PROJECT="LibSylph"
PROJECT_LC=$(echo $PROJECT | tr [A-Z] [a-z])
ROOTDIR="sylph"
SRCDIRS=( 'src' 'test' )
log() {
echo $@ >&2
}
do-git() {
#prepare for GIT
cat > README-GIT << EOT
You have checked out the current master branch from Git. Code from Git does
not always compile or can be incomplete.
EOT
if [ "$1" == "compile" ]; then
cat >> README-GIT << EOT
However, current code seems to compile. Be warned that it may still have many
bugs, or can be simply incomplete. If you want to have working code, please
check out the latest relase from the 'unstable' branch.
EOT
else
cat >> README-GIT << EOT
GIT is currently known to be broken. Please check out the latest release from
the 'unstable' branch.
EOT
fi
cat >> README-GIT << EOT
For instructions on building and installing, please see the README file in this
directory. You might need to recreate the src/SourcesList.txt files. In order to
do so, please run:
./developers.sh cmake
This will create the required files for the build.
EOT
}
do-cmake() {
log Creating/updating SourcesList.txt...
for subdir in "${SRCDIRS[@]}"; do
pushd $subdir
if [ '!' -f .devctl ]; then
log "No .devctl file found in ${subdir}!"
exit 1
fi
source .devctl
echo '# This file is automatically generated by developers.sh in' \
> SourcesList.txt
echo '# the main source directory. DO NOT EDIT MANUALLY!' \
>> SourcesList.txt
echo >> SourcesList.txt
echo "SET ( ${SRCNAME}_ALL_SRC " >> SourcesList.txt
for x in `find * | grep '\.cpp$'`; do
echo -n "$x " >> SourcesList.txt
done
echo ' )' >> SourcesList.txt
popd
done
log 'Done!'
}
do-release() {
if [ -z "$1" ]; then error; fi
log Preparing for release "$1" of $PROJECT...
log Cleaning Git stuff...
rm -f README-GIT
find . -name '.git' -exec rm -rf '{}' \;
log Creating CMake stuff
do-cmake
log Cleaning build...
make clean
log Removing old builds
for x in `ls | grep "^${PROJECT_UC}-.*-src.tar.bz2$"`; do
rm -v $x;
done;
log Creating tarball in parent directory...
pushd ..
cp $ROOTDIR "$PROJECT_LC"-"$1"-src
tar cjf "$PROJECT_LC"-"$1"-src "$PROJECT_LC"-"$1"-src.tar.bz2
rm -rf "$PROJECT_LC"-"$1"-src
popd
log Removing this script '('don\'t worry, it\'s up in Git')'...
rm -f developers.sh
log 'Done!'
}
do-update-copyright() {
name="$1";
if [ -z "$name" ]; then
name=$(git config user.name)
fi
year=$(date +%Y)
for file in $(find . '!' -type d | grep -v '^\./\.'); do
if grep -q "Copyright (C) 20[0-9][0-9] $name" $file; then
echo "Updating $file..."
if [ $(uname -s) = "Darwin" ]; then
sed -i '' "s/Copyright (C) 20[0-9][0-9] $name/Copyright (C) $year $name/" $file
else
sed -i "s/Copyright (C) 20[0-9][0-9] $name/Copyright (C) $year $name/" $file
fi
fi
done
}
do-fix-modelines() {
pushd src > /dev/null
for x in $(find . | egrep '\.(cpp|h)$'); do
if grep -v '// vim: ' $x > /dev/null; then
:
else
echo -e '\n// vim: ts=4:sts=4:sw=4:sta:et:tw=80:nobk' >> $x
fi
perl -0777 -i -pe 's@\n(\n\n// vim:.*)@$1@' $x
perl -0777 -i -pe \
's@// vim:.*@// vim: ts=4:sts=4:sw=4:sta:et:tw=80:nobk@' $x
done
popd > /dev/null
pushd test > /dev/null
for x in $(find . | egrep '\.(cpp|h)$'); do
n=$(echo -n $x | sed 's/[^\/]//g' | wc -c | perl -pe 's/^\s+//')
p=$(for (( ; n>0; --n )); do echo -n ../; done)
if grep -v '// vim: ' $x > /dev/null; then
:
else
echo -e '\n// vim: ts=4:sts=4:sw=4:sta:et:tw=80:nobk:path='$p'src' >> $x
fi
perl -0777 -i -pe 's@\n(\n\n// vim:.*)@$1@' $x
perl -0777 -i -pe \
's@// vim:.*@// vim: ts=4:sts=4:sw=4:sta:et:tw=80:nobk:path='$p'src@' $x
done
popd > /dev/null
}
error() {
echo "Syntax error."
exit 1
}
case "$1" in
git)
case "$2" in
compile|nocompile)
do-git "$2"
;;
*)
error
;;
esac
;;
cmake)
do-cmake
;;
release)
do-release "$2"
;;
update-copyright)
do-update-copyright "$2"
;;
fix-modelines)
do-fix-modelines
;;
*)
echo "This script contains several useful functions for the $PROJECT devs."
;;
esac