8 print "This is stowinstall,\n";
9 print " does `make install DESTDIR=...' for the GNU stow.\n";
11 print " Usage: stowinstall [-f] [stow-dir]\n";
12 print " (e.g. stowinstall /usr/local/stow/emacs)\n";
15 print " -f --force force install even if the Makefile\n";
16 print " doesn't have any \$(DESTDIR)\n";
17 print " --file=<file> specify the name of Makefile explicitly\n";
18 print " --prefix=<dir> specify the prefix instead of scanning Makefile\n";
19 print " --target=<targ> specify the target instead of `install'\n";
21 print "stowinstall can only install packages whose Makefile corresponds:\n";
22 print " * file name is exactly `Makefile'\n";
23 print " * the Makefile has target `install'\n";
24 print " * the Makefile has `prefix = ...' form\n";
25 print " * the Makefile has at least one `\$(DESTDIR)' form\n";
26 print "autotools is our friend; it generates such Makefile:s.\n";
32 my $opt_file = 'Makefile';
33 my $opt_target = 'install';
35 if (/^-f$/ or /^--force$/) {
38 elsif (/^--prefix=(.+)$/) {
41 elsif (/^--file=(.+)$/) {
44 elsif (/^--target=(.+)$/) {
53 print "stowinstall: $opt_file exists.\n";
56 die "stowinstall: $opt_file doesn't exist.\n";
61 open my $fh, '<', $opt_file;
65 my ($prefix, $destdir, $target_install);
66 $prefix = $opt_prefix;
68 foreach my $line (split /\r?\n/, $makefile) {
70 $line =~ /^prefix\s*=\s*(.+?)\s*$/) {
72 if ($prefix =~ /^(["'])(.+?)\1$/) {
76 elsif ($line =~ /\$\(DESTDIR\)/) {
79 elsif ($line =~ /^\Q$opt_target\E\s*:/) {
86 print "stowinstall: found prefix $prefix\n";
89 die "stowinstall: prefix not found...\n";
93 print "stowinstall: found \$(DESTDIR).\n";
97 print "stowinstall: \$(DESTDIR) not found; doing force install. THIS IS DANGEROUS.\n";
100 die "stowinstall: \$(DESTDIR) not found; this $opt_file seems not to support DESTDIR.\n";
104 if ($target_install) {
105 print "stowinstall: found target $opt_target.\n";
109 print "stowinstall: $opt_target target not found, but proceeding anyway...\n";
112 die "stowinstall: $opt_target target not found; this $opt_file seems not to support $opt_target!\n";
118 die "stowinstall: failed to mkdir $stowdir\n";
121 my @destdir = File::Spec->splitdir(
122 File::Spec->canonpath("/tmp/stowinstall-$$/".$prefix));
123 my $linkname = pop @destdir;
130 die "stowinstall: failed to mkdir $path\n";
134 my $linktarget = File::Spec->catdir(@destdir, $linkname);
135 symlink $stowdir => $linktarget or
136 die "stowinstall: failed to symlink $stowdir => $linktarget\n";
138 system("make $opt_target DESTDIR=/tmp/stowinstall-$$");
139 system("rm -rf /tmp/stowinstall-$$");