1 #!/scratchbox/tools/bin/perl
3 # dh_make - Script to Debianize a source archive
8 #Getopt::Long::Configure ("bundling");
9 #Getopt::Long::Configure ("bundling_override");
11 # Some important parameters
12 $DHLIB="/scratchbox/devkits/debian/share/debhelper/dh_make";
13 $POLICY_VERSION="3.6.0";
14 $DH_MAKE_VERSION="0.36";
15 %PACKAGE_TYPES = ( 's' => 'Single', 'l' => 'Library', 'm' => 'Multi-Binary',
16 'k' => 'Kernel Module');
35 $forced_package_name="";
41 my ($infile, $outfile) = @_;
44 if ( $main::overlay eq "" )
46 if ( $main::add_missing && -f $outfile) {
47 print "File $outfile exists, skipping.\n";
52 open IN, "<$infile" or die "Unable to open template file $infile for reading: $! \n";
53 open OUT, ">$outfile" or die "Unable to open file $outfile for writing: $! \n";
54 while (defined($line = <IN>))
56 $line =~ s/#PACKAGE#/$main::package_name/g;
57 $line =~ s/#UCPACKAGE#/$main::uc_package_name/g;
58 $line =~ s/#VERSION#/$main::version/g;
59 $line =~ s/#EMAIL#/$main::email/g;
60 $line =~ s/#DATE#/$main::date/g;
61 $line =~ s/#SHORTDATE#/$main::shortdate/g;
62 $line =~ s/#CHANGELOGS#/$main::CHANGELOG/g;
63 $line =~ s/#PRESERVE#/$main::PRESERVE/g;
64 $line =~ s/#CONFIG_STATUS#/$main::CONFIG_STATUS/g;
65 $line =~ s/#CONFIGURE#/$main::CONFIGURE/g;
66 $line =~ s/#CONFIGURE_STAMP#/$main::CONFIGURE_STAMP/g;
67 $line =~ s/#DPKG_ARCH#/$main::DPKG_ARCH/g;
68 $line =~ s/#INSTALL#/$main::INSTALL/g;
69 $line =~ s/#CLEAN#/$main::CLEAN/g;
70 $line =~ s/#USERNAME#/$main::username/g;
71 $line =~ s/#POLICY#/$main::POLICY_VERSION/g;
72 $line =~ s/#DASHLINE#/$main::DASHLINE/g;
73 $line =~ s/#PHONY_CONFIGURE#/$main::PHONY_CONFIGURE/g;
83 print "dh_make - Script to Debianize a regular source archive, version $main::DH_MAKE_VERSION\n\n";
84 print "Copyright (C) 1998-2004 Craig Small <csmall\@debian.org>\n";
85 print "This is free software; see the source for copying conditions. There is NO\n";
86 print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n";
92 Usage: dh_make [options]
93 -c, --copyright <type> use <type> of license in copyright file
94 (gpl|lgpl|artistic|bsd)
95 -e, --email <address> use <address> as the maintainer e-mail address
96 -n, --native the program is Debian native, don\'t generate .orig
97 -f, --file <file> specify file to use as the original source archive
98 -s, --single set package class to single
99 -m, --multi set package class to multiple binary
100 -l, --library set package class to library
101 -k, --kmod set package class to kernel module
102 -a, --addmissing reprocess package and add missing files
103 -t, --templates <dir> apply customizing templates in <dir>
104 -d --defaultless skip the default debian and package class templates
105 -o, --overlay <dir> reprocess package using template in <dir>
106 -p, --packagename <name> force package name to be <name>
107 -h, --help display this help screen and exit
108 -v, --version show the version and exit
110 By Craig Small <csmall\@debian.org>
111 Based on deb-make by Christoph Lameter <clameter\@debian.org>.
112 Custom template support by Bruce Sass <bsass\@edmc.net>.
118 my ($dohelp,$doversion, $single,$multi,$library );
119 %options = ('copyright' => \$main::license,
120 'email' => \$main::email,
121 'file' => \$main::source_file,
123 'version' => \$doversion,
124 'native' => \$main::debian_native,
125 'single' => \$single,
127 'library' => \$library,
129 'addmissing' => \$main::add_missing,
130 'templates' => \$main::custom,
131 'defaultless' => \$main::no_defaults,
132 'overlay' => \$main::overlay,
133 'packagename' => \$main::forced_package_name,
135 if (GetOptions(\%options, "copyright=s", "email=s", "file=s", "templates=s", "overlay=s", "packagename=s", "help", "version", "native", "single", "multi", "library", "kmod", "addmissing", "defaultless") == 0)
152 $main::package_type = 's';
156 $main::package_type = 'm';
160 $main::package_type = 'l';
164 $main::package_type = 'k';
168 $main::add_missing = 1;
172 $main::no_defaults = 1;
174 $main::license = lc $main::license;
175 if ($main::lincense ne "" && grep(!/gpl|lgpl|artistic|bsd/, $main::license)) {
176 print "Copyright type \"$main::license\" is not gpl, lgpl, artistic or bsd\n";
186 $tmpusername = $ENV{'DEBFULLNAME'};
187 return $tmpusername if ($tmpusername ne "");
189 if (-x '/usr/bin/getent')
191 $tmpusername = `/usr/bin/getent passwd $ENV{LOGNAME}|awk -F: '\{ print \$5; \}' | cut -f1 -d,`;
194 return $tmpusername if ($tmpusername ne "");
196 $tmpusername =`awk -F: -vUSER=$ENV{LOGNAME} '\$1 == USER \{ print \$5; \}' /etc/passwd | cut -f1 -d,`;
198 return $tmpusername if ($tmpusername ne "");
200 if (-x '/usr/bin/ypmatch')
202 $tmpusername=`ypmatch $ENV{LOGNAME} passwd.byname|awk -F: '\{ print \$5; \}' | cut -f1 -d,`;
205 return $tmpusername if ($tmpusername ne "");
207 if (-x '/usr/bin/ldapsearch')
209 $tmpusername = [map {/^(?:gecos|cn): (.*)/} `ldapsearch -Q -LLL uid=$ENV{LOGNAME} gecos cn`]->[0];
212 return $tmpusername if ($tmpusername ne "");
221 return $ENV{DEBEMAIL};
227 if (-x '/usr/bin/ldapsearch')
230 $mail = [map {/^mail: (.*)/ && $1} `ldapsearch -Q -LLL uid=$ENV{LOGNAME} mail`]->[0];
231 return $mail if $mail;
236 if ( -e '/etc/mailname'){
237 chomp($mailhost = `cat /etc/mailname`);
241 return ($ENV{LOGNAME} . '@' . $mailhost);
249 if (( ($main::forced_package_name) &&
250 ($pwd =~ /.*\/($main::forced_package_name)-([0-9][0-9a-zA-Z+\.\-]*)$/)
252 ($pwd =~ /.*\/(.*)-([0-9][0-9a-zA-Z+\.\-]*)$/)
255 if ($main::forced_package_name) {
256 $main::package_name = $main::forced_package_name;
258 $main::package_name = $1;
260 $main::uc_package_name = uc $main::package_name;
262 # Fullname stays as the original dir
263 $main::fullname = $1 . "-" . $2;
267 The directory name must be <package>-<version> for dh_make to work!
268 I cannot understand the directory name or you have an invalid directory name!
270 Your current directory is $pwd, perhaps you could try going to
271 directory where the sources are?
275 if (! ($main::package_name =~ /^[a-z0-9+.-]+$/)) {
277 Package name "$main::package_name" is not in a valid format.
278 Debian policy manual states:
279 "Package names must only consist of lower case letters, digits (0-9),
280 plus (+) or minus (-) signs, and periods (.)"
289 if (-x "/scratchbox/devkits/debian/bin/822-date")
291 $tmpdate = `/scratchbox/devkits/debian/bin/822-date`;
295 die "Unable to find 822-date program in /scratchbox/devkits/debian/bin!\n";
299 $username = get_username();
300 $email = get_email();
302 $shortdate = `date '+%B %e, %Y'`;
305 if ( ! $overlay eq "" )
307 #setup for overlay mode
310 $customer = $overlay;
314 # Generate a line of dashes, which is as long as '#PACKAGE# for Debian'.
315 for ($i=0; $i<length("$main::package_name for Debian"); $i++)
317 $DASHLINE = $DASHLINE . '-';
320 if ( ! $no_defaults )
322 while ($package_type eq "")
324 print "\nType of package: single binary, multiple binary, library, or kernel module?\n [s/m/l/k] ";
329 $main::package_type = 's' if $type eq 's';
330 $main::package_type = 'm' if $type eq 'm';
331 $main::package_type = 'l' if $type eq 'l';
332 $main::package_type = 'k' if $type eq 'k';
336 # Print what we have found
337 print "Maintainer name : $username\n";
338 print "Email-Address : $email \n";
339 print "Date : $date\n";
340 print "Package Name : $package_name\n";
341 print "Version : $version\n";
342 print "Type of Package : ";
343 if (exists $PACKAGE_TYPES{$package_type})
345 print $PACKAGE_TYPES{$package_type};
349 if ( $customer ne "" )
351 print "\nCustomer template : $custom";
353 if ( $overlay ne "" )
359 print "\nDefault debian and package class templates will not be applied.";
361 print "\nHit <enter> to confirm: hacked by STRanger, 2006 - you do not have to hit <enter> \n";
364 if (! $debian_native)
370 system('cp', '-a', "$source_file", "../$package_name\_$version.orig.tar.gz");
372 print "Source archive you specified was not found!\n";
376 if (-d "..$fullname.orig")
378 print "Skipping copying to $fullname.orig since $fullname.orig exists.\n";
380 if ( -f "../$fullnane.orig.tar.gz")
382 print "Skipping copying to $fullname.orig since $fullname.org.tar.gz exists.\n";
384 system('cp', '-a', "../$fullname", "../$fullname.orig");
389 # Figure out where documentation is
390 @DOCS= split / |\n/, `ls -1 N[Ee][Ww][Ss] *[Ff][Aa][Qq]* *.[Tt][Xx][Tt] README* *.README [rR]eadme* *.[rR]eadme [Bb][Uu][Gg][Ss] *[tT][oO][dD][oO]* 2>/dev/null`;
391 # What are our info files
392 @INFOS= split / |\n/, `find . -regex '.*\\.info\\(-[0-9]+\\)?'`;
393 # Figure out where is the first changelog, assign other similar files to docs
394 @changelogs= split / |\n/, `ls *[cC][hH][aA][nN][gG][eE][lL][oO][gG]* [cC][hH][aA][nN][gG][eE][sS]* 2>/dev/null`;
395 $CHANGELOG = $changelogs[0] if ($#changelogs != -1);
397 @DOCS = (@DOCS,@changelogs);
398 # Are there any .orig files in the upstream sources
399 @ORIG= split /[ \n]/, `find . -name '\*.orig'`;
401 foreach $orig (@ORIG)
403 $PRESERVE="$PRESERVE --exclude $orig";
408 if (-x "./configure" )
410 $CONFIG_STATUS="config.status";
413 $CONFIGURE="config.status: configure\n".
415 "\t# Add here commands to configure the package.\n".
416 "\t".'CFLAGS="$(CFLAGS)" ./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info'."\n";
417 $DPKG_ARCH="# These are used for cross-compiling and for saving the configure script\n".
418 "# from having to guess our platform (since we know it already)\n".
419 'DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)'."\n".
420 'DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)'."\n";
423 # If it is automaked, use DESTDIR insteadof prefix
424 if ( -f 'Makefile.am' ) {
425 # If it is a library then install into tmp
426 if ( $package_type eq "l") {
427 $INSTALL="\$(MAKE) install DESTDIR=\$(CURDIR)/debian/tmp";
429 $INSTALL="\$(MAKE) install DESTDIR=\$(CURDIR)/debian/$package_name";
432 if ( $package_type eq "l") {
433 $INSTALL="\$(MAKE) install prefix=\$(CURDIR)/debian/tmp/usr";
435 $INSTALL="\$(MAKE) install prefix=\$(CURDIR)/debian/$package_name/usr";
438 $CLEAN="\$(MAKE) distclean\n".
439 "ifneq \"\$(wildcard /usr/share/misc/config.sub)\" \"\"\n".
440 "\tcp -f /usr/share/misc/config.sub config.sub\n".
442 "ifneq \"\$(wildcard /usr/share/misc/config.guess)\" \"\"\n".
443 "\tcp -f /usr/share/misc/config.guess config.guess\n".
446 if (! -f 'Makefile' && ! -f 'makefile' && ! -f 'GNUmakefile')
448 print "Currently there is no top level Makefile. This may require additional tuning.\n";
450 $CONFIGURE_STAMP='configure-stamp';
452 $CONFIGURE="configure: configure-stamp\n".
453 "configure-stamp:\n".
455 "\t# Add here commands to configure the package.\n\n".
456 "\ttouch configure-stamp\n";
457 $PHONY_CONFIGURE='configure';
459 if ($package_type eq "l") {
460 $INSTALL="\$(MAKE) install DESTDIR=\$(CURDIR)/debian/tmp";
462 $INSTALL="\$(MAKE) install DESTDIR=\$(CURDIR)/debian/$package_name";
464 $CLEAN='$(MAKE) clean';
472 die "--addmissing or --overlay flag used but cannot find debian subdirectory\n";
477 mkdir 'debian', 0755 or die "Unable to make debian subdirectory: $! \n";
479 print "You already have a debian/ subdirectory in the source tree.\n";
480 print "dh_make will not try to overwrite anything.\n";
484 chdir 'debian' or die "Unable to chdir to debian subdirectory: $! \n";
488 die "Unable to find dh_make's template directory: $! \n";
491 if ( ! $no_defaults )
494 @filenames= split / |\n/, `(cd $DHLIB/debian && ls)`;
495 foreach $filename (@filenames)
497 process_file("$DHLIB/debian/$filename", $filename);
503 process_file("$DHLIB/licenses/blank", copyright);
505 if ( -r "$DHLIB/licenses/$license" )
507 process_file("$DHLIB/licenses/$license", copyright);
509 die "Unable to find copyright template file $DHLIB/licenses/$license";
514 @filenames = split / |\n/, `(cd $DHLIB/debian$package_type && ls)`;
515 foreach $filename (@filenames)
517 process_file("$DHLIB/debian$package_type/$filename", $filename);
526 @filenames = split /[\n]/, `(cd $custom && ls)`;
527 foreach $filename (@filenames)
529 process_file("$custom/$filename", $filename);
532 print "Unable to find the customization directory, $custom\n";
539 print "File docs already exists, skipping.\n";
541 open (DOCSFILE,">docs");
544 print DOCSFILE "$doc\n";
551 print "File info already exists, skipping.\n";
555 open (INFOFILE,">info");
556 foreach $info (@INFOS)
559 print INFOFILE "$info\n";
565 if ( ! $no_defaults )
569 @filenames= split / |\n/, `(cd $DHLIB/native;ls)`;
570 foreach $filename (@filenames)
572 process_file("$DHLIB/native/$filename", $filename);
577 @filenames = split / |\n/, `ls package* 2>/dev/null`;
578 if ($#filenames != -1)
580 foreach $filename (@filenames)
582 my $oldname = $filename;
583 $filename =~ s/^package/$package_name/;
586 print "File $filename already exists, skipping.\n";
588 system('mv', $oldname, $filename);
594 if ($CONFIG_STATUS ne "")
596 print "Done. Please edit the files in the debian/ subdirectory now. $package_name\n";
597 print "uses a configure script, so you probably don't have to edit the Makefiles.\n";
599 print "Done. Please edit the files in the debian/ subdirectory now. You should also\n";
600 print "check that the $package_name Makefiles install into \$DESTDIR and not in / .\n";
602 if ($package_type eq 'l')
604 print "Make sure you change the package name from $package_name"."BROKEN to something\n".
605 "else, such as $package_name"."1 in the debian/control file.\n";