[0b990d] | 1 | # Emacs should use -*- Perl -*- mode.
|
---|
| 2 |
|
---|
| 3 | while ($arg = shift) {
|
---|
| 4 | if ($arg eq "-x") {
|
---|
| 5 | $excluded[$#excluded+1] = shift;
|
---|
| 6 | }
|
---|
| 7 | else {
|
---|
| 8 | $srcdir = $arg;
|
---|
| 9 | }
|
---|
| 10 | }
|
---|
| 11 |
|
---|
| 12 | ($mydev,$myino,$mymode,$mynlink,$myuid,$mygid,$myrdev,$mysize,
|
---|
| 13 | $myatime,$mymtime,$myctime,$myblksize,$myblocks)
|
---|
| 14 | = stat(".");
|
---|
| 15 |
|
---|
| 16 | if (substr($srcdir,0,1) eq "/") {
|
---|
| 17 | $topdir = "";
|
---|
| 18 | }
|
---|
| 19 | else {
|
---|
| 20 | $topdir = ".";
|
---|
| 21 | }
|
---|
| 22 |
|
---|
| 23 | $stubhead = "# Generated by objectdir.pl -- edit at own risk.\n";
|
---|
| 24 |
|
---|
| 25 |
|
---|
| 26 | if (-d "$srcdir/lib") {
|
---|
| 27 | local($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
|
---|
| 28 | $atime,$mtime,$ctime,$blksize,$blocks)
|
---|
| 29 | = stat("$srcdir/lib");
|
---|
| 30 | mkdir ("lib", $mode);
|
---|
| 31 | }
|
---|
| 32 | else {
|
---|
| 33 | die "couldn't find source distribution";
|
---|
| 34 | }
|
---|
| 35 | if (-d "$srcdir/src") {
|
---|
| 36 | local($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
|
---|
| 37 | $atime,$mtime,$ctime,$blksize,$blocks)
|
---|
| 38 | = stat("$srcdir/src");
|
---|
| 39 | mkdir ("src", $mode);
|
---|
| 40 | }
|
---|
| 41 | else {
|
---|
| 42 | die "couldn't find source distribution";
|
---|
| 43 | }
|
---|
| 44 | if (-d "$srcdir/src/lib") {
|
---|
| 45 | local($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
|
---|
| 46 | $atime,$mtime,$ctime,$blksize,$blocks)
|
---|
| 47 | = stat("$srcdir/src/lib");
|
---|
| 48 | mkdir ("src/lib", $mode);
|
---|
| 49 | }
|
---|
| 50 | else {
|
---|
| 51 | die "couldn't find source distribution";
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | open(MAKEDIRLIST,">lib/Makedirlist");
|
---|
| 55 | open(INCDIRLIST,">src/lib/scdirlist.h");
|
---|
| 56 |
|
---|
| 57 | &dodir("$srcdir",".",$topdir);
|
---|
| 58 |
|
---|
| 59 | close(MAKEDIRLIST);
|
---|
| 60 | close(INCDIRLIST);
|
---|
| 61 |
|
---|
| 62 | exit;
|
---|
| 63 |
|
---|
| 64 | sub dodir {
|
---|
| 65 | local($dir,$objdir,$topdir) = @_;
|
---|
| 66 | local($file);
|
---|
| 67 | local(@files);
|
---|
| 68 |
|
---|
| 69 | #print "In directory $dir\n";
|
---|
| 70 |
|
---|
| 71 | opendir(DIR, $dir) || (warn "Can't open $dir: $!\n", return);
|
---|
| 72 | @files = readdir(DIR);
|
---|
| 73 | closedir(DIR);
|
---|
| 74 |
|
---|
| 75 | foreach $file (@files) {
|
---|
| 76 | if ($file eq "." || $file eq ".." || $file eq "CVS") {
|
---|
| 77 | next;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | local($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
|
---|
| 81 | $atime,$mtime,$ctime,$blksize,$blocks)
|
---|
| 82 | = stat("$dir/$file");
|
---|
| 83 |
|
---|
| 84 | if ($dev == $mydev && $ino == $myino) { next; }
|
---|
| 85 |
|
---|
| 86 | if (-d "$dir/$file") {
|
---|
| 87 | mkdir ("$objdir/$file", $mode);
|
---|
| 88 | local($nexttop);
|
---|
| 89 | if ($topdir eq ".") {
|
---|
| 90 | $nexttop = "../";
|
---|
| 91 | }
|
---|
| 92 | elsif ($topdir eq "" ) {
|
---|
| 93 | $nexttop = "";
|
---|
| 94 | }
|
---|
| 95 | else {
|
---|
| 96 | $nexttop = "$topdir../";
|
---|
| 97 | }
|
---|
| 98 | &dodir("$dir/$file", "$objdir/$file", $nexttop);
|
---|
| 99 | }
|
---|
| 100 | elsif ("$file" eq "Makefile" && isobjectdirmake("$dir/$file")) {
|
---|
| 101 | #print "Found $dir/Makefile\n";
|
---|
| 102 | local($nextdir);
|
---|
| 103 | &domake("$topdir$dir", "$objdir/$file");
|
---|
| 104 | &doconfigfiles("$objdir");
|
---|
| 105 | }
|
---|
| 106 | }
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | sub isobjectdirmake {
|
---|
| 110 | local($file) = shift;
|
---|
| 111 | open(MAKEFILE,"<$file");
|
---|
| 112 | while (<MAKEFILE>) {
|
---|
| 113 | if (/SRCDIR/) {
|
---|
| 114 | return 1;
|
---|
| 115 | }
|
---|
| 116 | }
|
---|
| 117 | return 0;
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | sub doconfigfiles {
|
---|
| 121 | local($dir) = @_;
|
---|
| 122 | $dir =~ s/\.//g;
|
---|
| 123 | $dir =~ s/\//_/g;
|
---|
| 124 | $dir = uc($dir);
|
---|
| 125 | $dir =~ s/^_//;
|
---|
| 126 | if ($dir ne "" && ! &excluded($dir)) {
|
---|
| 127 | printf MAKEDIRLIST "HAVE_SC_%s=yes\n", $dir;
|
---|
| 128 | printf INCDIRLIST "#define HAVE_SC_%s 1\n", $dir;
|
---|
| 129 | }
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | sub domake {
|
---|
| 133 | local($topdir, $stubmake) = @_;
|
---|
| 134 |
|
---|
| 135 | if (-f $stubmake) {
|
---|
| 136 | open(STUBMAKE,"<$stubmake");
|
---|
| 137 | local($line) = scalar(<STUBMAKE>);
|
---|
| 138 | close(STUBMAKE);
|
---|
| 139 | if ($line eq $stubhead) {
|
---|
| 140 | print "Overwriting "
|
---|
| 141 | }
|
---|
| 142 | else {
|
---|
| 143 | print "Skipping $stubmake\n";
|
---|
| 144 | return;
|
---|
| 145 | }
|
---|
| 146 | }
|
---|
| 147 | else {
|
---|
| 148 | print "Writing ";
|
---|
| 149 | }
|
---|
| 150 | print "$stubmake\n";
|
---|
| 151 |
|
---|
| 152 | open(STUBMAKE,">$stubmake");
|
---|
| 153 | print STUBMAKE "$stubhead";
|
---|
| 154 | print STUBMAKE "SRCDIR = $topdir\n";
|
---|
| 155 | print STUBMAKE "VPATH = \$(SRCDIR)\n";
|
---|
| 156 | print STUBMAKE "include \$(SRCDIR)/Makefile\n";
|
---|
| 157 | close(STUBMAKE);
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 | sub excluded {
|
---|
| 161 | my $dir = shift;
|
---|
| 162 | my $i;
|
---|
| 163 | foreach $i (0..($#excluded)) {
|
---|
| 164 | if ($dir eq $excluded[$i]) { return 1; }
|
---|
| 165 | }
|
---|
| 166 | return 0;
|
---|
| 167 | }
|
---|