-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap
More file actions
executable file
·172 lines (148 loc) · 4.53 KB
/
Copy pathbootstrap
File metadata and controls
executable file
·172 lines (148 loc) · 4.53 KB
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
#!/bin/sh
printSynopsis() {
if test -n "$1"
then
echo "ERROR: $1"
fi
echo "SYNOPSIS"
echo "\tBootstrap generates a autotools shared library project for you."
echo "USAGE"
echo "\t`basename $0` libraryName projectName sourcePrefix copyRightHolder copyRightContact"
echo "\t"
echo "\t libraryName library name of the project (without the lib)"
echo "\t projectName a very short description/name of the project"
echo "\t sourcePrefix prefix for source files and headers"
echo "\t copyRightHolder name of the copyright holder, say John L. Smith"
echo "\t copyRightContact Contact information for the copyright holder, could"
echo "\t be E-mail or site"
}
validRegExp() {
if test -z "$2"
then
echo "Empty is no match" >&2
fi
if echo "$1" | grep -Ei "$2" >/dev/null
then
echo "$1"
else
echo "Input '$1' does not match regexp '$2'" >&2
exit 1
fi
}
if echo "$1" | grep -Ei "(-{1,2}h\$|-{1,2}help\$|help\$)" >/dev/null
then
printSynopsis
exit 0
fi
if ! test -n "$5"
then
printSynopsis "Missing argument(s)" >&2
exit 1
fi
allowedCommentCharacters="[-+_a-z0-9.%,\"\?@<>/]"
libraryNameRegExp="^[a-z][-_0-9a-z]+[a-z0-9]\$"
nameOrUrlRegExp="^${allowedCommentCharacters}+((\t| )+${allowedCommentCharacters}+){0,4}\$"
sourcePrefixRegExp="^([a-z][a-z0-9]*[-_]{1})+\$"
if ! libraryName=`validRegExp "$1" "${libraryNameRegExp}"`
then
printSynopsis "Invalid library name: '$1'" >&2
exit 1
fi
shift
if ! projectName=`validRegExp "$1" "${nameOrUrlRegExp}"`
then
printSynopsis "Invalid project name: '$1'" >&2
exit 1
fi
shift
if ! sourcePrefix=`validRegExp "$1" "${sourcePrefixRegExp}"`
then
printSynopsis "Invalid source prefix: '$1'" >&2
exit 1
fi
shift
if ! copyrightHolder=`validRegExp "$1" "${nameOrUrlRegExp}"`
then
printSynopsis "Invalid copyright holder: '$1'" >&2
exit 1
fi
shift
if ! copyrightContact=`validRegExp "$1" "${nameOrUrlRegExp}"`
then
printSynopsis "Invalid copyright contact: '$1'" >&2
exit 1
fi
shift
echo "Removing source management system directories"
rm -rf ".git"
rm -rf ".hg"
rm *~
currentYear=`date +"%Y"`
currentDir=`dirname "$0"`
#projectName=`echo "${projectName}" | sed -r s/"\""/'\\\\"'/g | sed -r s/"'"/""/g`
#copyrightHolder=`echo "${copyrightHolder}" | sed -r s/'"'/'\"'/g | sed -r s/"'"/"\'"/g | sed -r s/'\\'/'\\\\'/g `
#copyrightContact=`echo "${copyrightContact}" | sed -r s/'"'/'\"'/g | sed -r s/"'"/"\'"/g | sed -r s/'\\'/'\\\\'/g `
echo "Project name ${projectName}"
echo "Copyright ${currentYear} ${copyrightHolder}"
echo "Contact ${copyrightContact}"
echo "Library lib${libraryName}"
echo "Source Prefix ${sourcePrefix}"
substituteVariables() {
echo "Substituting templates for '$1'"
if ! cat "$1" |\
sed -r s/'TemplateLibraryName'/"${libraryName}"/g |\
sed -r s/'GenerateProjectInitialCopyrightYear'/"${currentYear}"/g |\
sed -r s/'GenerateProjectPrefix'/"${sourcePrefix}"/g |\
sed s/'GenerateProjectDescription'/"${projectName}"/ |\
sed s/'GenerateProjectCopyrightHolder'/"${copyrightHolder}"/ |\
sed s/'GenerateprojectCopyRightContact'/"${copyrightContact}"/ \
> "$2"
then
echo "Error while substituting '$1' to '$2'" >&2
exit 1
fi
}
sourceGeneratorTemplate="${currentDir}/sourcetemplates/generate-from-template.sh"
sourceGenerator="${currentDir}/generatesource"
if ! test -f "${sourceGeneratorTemplate}"
then
echo "ERROR: cannot find template for source-code-generator: ${sourceGeneratorTemplate}" >&2
exit 1
fi
if ! substituteVariables "${sourceGeneratorTemplate}" "${sourceGenerator}"
then
echo "Failed to create source file creator" >&2
exit 1
fi
chmod u+x ${sourceGenerator}
chmod u+x "init-autotools"
mkdir include
echo "Replacing library template name in autotools files with '${projectName}'"
autoToolsFiles=`find "${currentDir}" -name "Makefile.am"`
autoToolsFiles="configure.ac AUTHORS COPYING NOTICE README README.md ${autoToolsFiles}"
for autoToolsFile in ${autoToolsFiles}
do
echo "Substitue in ${autoToolsFile}..."
if ! substituteVariables "${autoToolsFile}" "${autoToolsFile}~~"
then
exit 1
fi
if ! cp "${autoToolsFile}" "${autoToolsFile}~"
then
echo "Couldn't create backup!"
exit 1
elif ! mv "${autoToolsFile}~~" "${autoToolsFile}"
then
echo "Could not copy substituted file back"
exit 1
fi
done
echo "DONE!"
echo "Now would be the time to add your project to source control."
echo "."
echo "You can create source and files using the ./generatesource script"
echo "."
echo "After that, use ./init-autotools to create a working autotools project"
echo "And start building!"
echo "Regards,"
echo "Michel Fleur."