This repository has been archived by the owner on Dec 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpackage-create.in
executable file
·320 lines (265 loc) · 8.78 KB
/
package-create.in
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
#!/usr/bin/perl -w
# -*- perl -*-
##########
# README #
##########
#
# This scripts allows automatic generation of packages.
# It is a perl script. To use it:
# $ chmod u+x package-create
# $ cd /tmp && /path/to/package-create -p foo
#
# It will create a package in /tmp/foo.
####################
# Import packages. #
####################
use strict;
use warnings;
use Getopt::Long;
use FindBin qw($Bin);
use Env qw(EMAIL FULLNAME);
#######################
# Parse command line. #
#######################
my ($pkg, $print_version, $print_help, @dep, @docdep);
my $usage = "package-create -p <packageName> -d dependency -dd docDependency";
my $version = "@PACKAGE_VERSION@";
my $kind = "autotools";
usage() if !GetOptions("version|v" => \$print_version,
"help|h" => \$print_help,
"package|p=s" => \$pkg,
"kind|k=s" => \$kind,
"dep|d:s" => \@dep,
"docdep|dd:s" => \@docdep);
if ($print_version) {
print "package-create version $version\n";
exit;
}
if ($print_help) {
print "$usage\n
Generate an Autotools package and provides basic support
for testing with Autotest and Doxygen documentation.
--dep|-d dependency
Define a compilation dependency from this package to another.
--docdep|-dd docDependency
Define a documentation dependency from this package to another.
Documentation dependencies are handled by Doxygen to track
class inheritance between packages.
--kind <kind>
Set the kind of package that will be generated.
It can be either autotools or cmake.
Default value is autotools.
--version|-v
print version information.
--help|-?
print help.\n";
exit;
}
sub usage {
print "Unknown option: @_\n" if ( @_ );
print "$usage\n";
print "Use --help for additional information.\n";
exit;
}
#####################
# Global variables. #
#####################
# Lower case.
my $package_lc = lc ($pkg);
# Upper case.
my $package_uc = uc ($pkg);
$package_uc =~ s/\W/_/g;
# Caml case.
my $package_cc = ucfirst ($package_lc);
###################
# Various checks. #
###################
if (!$pkg) { print $usage . "\n"; exit 1 }
if ($kind ne "autotools" && $kind ne "cmake") { print $usage . "\n"; exit 1 }
if (!$FULLNAME) {
print "Please specify your name in the FULLNAME environment variable.\n";
exit 1;
}
if (!$EMAIL) {
print "Please specify your e-mail in the EMAIL environment variable.\n";
exit 1;
}
if (-d $package_lc) {
print "The directory already exists, please remove it first if necessary.\n";
exit 1;
}
##############################################
# Search for the template-project directory. #
##############################################
my $tplProjectDir = "";
if (defined($ENV{PACKAGECREATE_SHAREDIR})) {
$tplProjectDir = $ENV{PACKAGECREATE_SHAREDIR};
} else {
$tplProjectDir = "@prefix@/share/@PACKAGE_TARNAME@";
}
$tplProjectDir = $tplProjectDir."/template-project/".$kind;
#####################
# Generate package. #
#####################
if (! -d "$tplProjectDir") {
print
"$tplProjectDir does not exist.\n".
"Please re-install the software or use the PACKAGECREATE_SHAREDIR\n".
"environment variable to set the location of this directory.\n".
"A directory called template-project must exist in ".
"PACKAGECREATE_SHAREDIR if used.\n";
exit 1;
}
# Copy template into specified location.
system("cp -Rf $tplProjectDir $package_lc");
# Fix permissions.
system("find $package_lc -type d -print0 | xargs -0 chmod 755");
system("find $package_lc -type f -print0 | xargs -0 chmod u+rw,g+rw,o+r");
# Generate dependency file.
my $dep_file = "deps.ac";
if ($kind ne "autotools") {
$dep_file = "deps.cmake"
}
open(OUTPUT, ">"."$package_lc/".$dep_file) or
die "Cannot open output file $package_lc/".$dep_file."\n";
print OUTPUT "# Automatically generated - DO NOT EDIT!\n";
my ($iDep, $D, $d);
for ($iDep = 0; $iDep< scalar(@dep); $iDep++) {
$D = uc ($dep[$iDep]);
$D =~ s/\W/_/g;
$d = lc ($dep[$iDep]);
$d =~ s/\W//g;
if ($kind eq "autotools") {
print OUTPUT "JRL_PKGCONFIGCHECK([$D], [$dep[$iDep] >= 0.1])\n"
} else {
print OUTPUT "ADD_REQUIRED_DEPENDENCY($dep[$iDep] >= 0.1)\n"
}
}
for ($iDep = 0; $iDep< scalar(@docdep); $iDep++) {
$D = uc ($docdep[$iDep]);
$D =~ s/\W/_/g;
$d = lc ($docdep[$iDep]);
$d =~ s/\W//g;
print OUTPUT "PKG_CHECK_MODULES([$D], [$docdep[$iDep]])\n";
print OUTPUT "$D\_PREFIX=\`\$PKG_CONFIG $docdep[$iDep] --variable=prefix\`\n";
print OUTPUT "$D\_DOCDIR=\`\$PKG_CONFIG $docdep[$iDep] --variable=docdir\`\n";
print OUTPUT "AC_SUBST([$D\_PREFIX])\n";
print OUTPUT "AC_SUBST([$D\_DOCDIR])\n";
print OUTPUT "\n";
}
close(OUTPUT);
# Generate sed arguments.
my ($sec,
$min,
$hour,
$mday,
$mon,
$year,
$wday,
$yday,
$isdst) = localtime(time);
$year += 1900;
$mon += 1;
my $DATE="$year-$mon-$mday";
my $PKG_DEPS = join(", ", @dep);
my $PKG_DOCDEPS = "";
my $PKG_DEPS_CFLAGS = "";
my $PKG_DEPS_LIBS = "";
# Generate PKG_DOCDEPS
for ($iDep=0; $iDep<scalar(@dep); $iDep++) {
my $dd = $dep[$iDep];
$D = uc ($dd);
$D =~ s/\W/_/g;
$d = lc ($dd);
$d =~ s/\W//g;
$PKG_DOCDEPS =
$PKG_DOCDEPS."\@$D\_DOXYGENDOCDIR\@/$dd.doxytag=\@$D\_DOXYGENDOCDIR\@ ";
}
for ($iDep=0; $iDep<scalar(@docdep); $iDep++) {
my $dd = $docdep[$iDep];
$D = uc ($dd);
$D =~ s/\W/_/g;
$d = lc ($dd);
$d =~ s/\W//g;
$PKG_DOCDEPS =
$PKG_DOCDEPS."\@$D\_DOXYGENDOCDIR\@/$dd.doxytag=\@$D\_DOXYGENDOCDIR\@ ";
}
# Generate PKG_DEPS_CFLAGS
for ($iDep=0; $iDep<scalar(@dep); $iDep++) {
my $dd = $dep[$iDep];
$D = uc ($dd);
$D =~ s/\W/_/g;
$PKG_DEPS_CFLAGS = $PKG_DEPS_CFLAGS."\$($D\_CFLAGS) ";
}
# Generate PKG_DEPS_LIBS
for ($iDep=0; $iDep<scalar(@dep); $iDep++) {
my $dd = $dep[$iDep];
$D = uc ($dd);
$D =~ s/\W/_/g;
$PKG_DEPS_LIBS = $PKG_DEPS_LIBS."\$($D\_LIBS) ";
}
my $sed_args = "-e 's,&PACKAGE_TARNAME&,$package_lc,g' \\
-e 's,&PACKAGE_TARNAME_LC&,$package_lc,g' \\
-e 's,&PACKAGE_TARNAME_UC&,$package_uc,g' \\
-e 's,&PACKAGE_TARNAME_CC&,$package_cc,g' \\
-e 's,&PACKAGE_NAME&,$pkg,g' \\
-e 's|&PKG_DEPS&|$PKG_DEPS|g' \\
-e 's|&PKG_DOCDEPS&|$PKG_DOCDEPS|g' \\
-e 's|&PKG_DEPS_CFLAGS&|$PKG_DEPS_CFLAGS|g' \\
-e 's|&PKG_DEPS_LIBS&|$PKG_DEPS_LIBS|g' \\
-e 's,&VERSION&,$version,g' \\
-e 's,&FULLNAME&,$FULLNAME,g' \\
-e 's,&EMAIL&,$EMAIL,g' \\
-e 's,&DATE&,$DATE,g'";
# Tune files.
system("find $package_lc -type f -print0 | xargs -0 sed -i $sed_args \n");
# Tune Makefile.am
my $package_lc_alphanum = $package_lc;
$package_lc_alphanum =~ s/\W/_/g;
$sed_args =
"-e 's,${package_lc}_la_SOURCES,${package_lc_alphanum}_la_SOURCES,g' \\
-e 's,${package_lc}_la_LIBADD,${package_lc_alphanum}_la_LIBADD,g' \\
-e 's,${package_lc}_la_CPPFLAGS,${package_lc_alphanum}_la_CPPFLAGS,g' \\
";
system("find $package_lc -type f -name Makefile.am -print0 ".
" | xargs -0 sed -i $sed_args \n");
# Move sample C++ source/header file.
system("mv $package_lc/src/package.cc $package_lc/src/$package_lc.cc");
system("mv $package_lc/include/package/package.hh $package_lc/include/package/$package_lc.hh");
system("mv $package_lc/include/package $package_lc/include/$package_lc");
############################
# Print user instructions. #
############################
print "To configure and test this package, do the following commands\n";
print "cd $pkg\n";
print "./bootstrap\n";
print "mkdir _build\n";
print "cd _build\n";
if ($kind eq "autotools") {
print "../configure --prefix=... CXXFLAGS=\"-g\"\n";
} else {
print "cmake -DCMAKE_INSTALL_PREFIX=... ..\n";
}
print "make\n";
print "\n";
print "If you want...\n";
if ($kind eq "autotools") {
print "* to get a tarball (to distribute the package): make distcheck\n";
print "* to generate the doc: make doc\n";
print "* to align the testsuite to current outputs: \n";
print " cd _build/tests && make generate-reference\n";
print "Please make sure to generate the stdout files with the previous\n";
print "command line *before* trying a make distcheck.\n";
print "\n";
print "See Autotools documentation for more information:\n";
print "* Autoconf: http://www.gnu.org/software/autoconf/manual/\n";
print "* Automake: http://www.gnu.org/software/automake/manual/\n";
print "* Libtool: http://www.gnu.org/software/libtool/manual/\n";
} else {
print "* to get a tarball (to distribute the package): make dist\n";
print "* to generate the doc: make doc\n";
print "\n";
print "See CMake documentation for more information:\n";
print "* CMake: http://www.cmake.org/cmake/help/documentation.html\n";
}
exit;