3 if test ! -f config.sh; then
5 ln ../../config.sh . || \
6 ln ../../../config.sh . || \
7 (echo "Can't find config.sh."; exit 1)
12 : This forces SH files to create target in same directory as SH file.
13 : This is so that make depend always knows where to find SH derivatives.
15 */*) cd `expr X$0 : 'X\(.*\)/'` ;;
17 echo "Extracting makelib (with variable substitutions)"
18 : This section of the file will have variable substitutions done on it.
19 : Move anything that needs config subs from !NO!SUBS! section to !GROK!THIS!.
20 : Protect any dollar signs and backticks that you do not want interpreted
21 : by putting a backslash in front. You may delete these comments.
22 $spitshell >makelib <<!GROK!THIS!
25 \$perlincl = '$privlib';
28 : In the following dollars and backticks do not need the extra backslash.
29 $spitshell >>makelib <<'!NO!SUBS!'
31 chdir '/usr/include' || die "Can't cd /usr/include";
33 %isatype = ('char',1,'short',1,'int',1,'long',1);
35 foreach $file (@ARGV) {
37 if ($file =~ m|^(.*)/|) {
39 if (!-d "$perlincl/$dir") {
40 mkdir("$perlincl/$dir",0777);
43 open(IN,"$file") || ((warn "Can't open $file: $!\n"),next);
44 open(OUT,">$perlincl/$file") || die "Can't create $file: $!\n";
54 s/\200[^\201]*\201//g; # delete single line comments
55 if (s/\200.*//) { # begin multi-line comment?
62 if (s/^define\s+(\w+)//) {
66 if (s/^\(([\w,\s]*)\)//) {
69 foreach $arg (split(/,\s*/,$args)) {
72 $args =~ s/\b(\w)/\$$1/g;
73 $args = "local($args) = \@_;\n$t ";
77 $new =~ s/(["\\])/\\$1/g;
79 $new =~ s/(['\\])/\\$1/g;
81 "eval 'sub $name {\n$t ${args}eval \"$new\";\n$t}';\n";
84 print OUT "sub $name {\n ${args}eval \"$new\";\n}\n";
91 $new = 1 if $new eq '';
93 $new =~ s/(['\\])/\\$1/g;
94 print OUT $t,"eval 'sub $name {",$new,";}';\n";
97 print OUT $t,"sub $name {",$new,";}\n";
101 elsif (/^include <(.*)>/) {
102 print OUT $t,"do '$1' || die \"Can't include $1: \$!\";\n";
104 elsif (/^ifdef\s+(\w+)/) {
105 print OUT $t,"if (defined &$1) {\n";
107 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
109 elsif (/^ifndef\s+(\w+)/) {
110 print OUT $t,"if (!defined &$1) {\n";
112 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
117 print OUT $t,"if ($new) {\n";
119 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
121 elsif (s/^elif\s+//) {
125 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
126 print OUT $t,"}\n${t}elsif ($new) {\n";
128 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
132 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
133 print OUT $t,"}\n${t}else {\n";
135 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
139 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
149 s/^(\s+)// && do {$new .= ' '; next;};
150 s/^(0x[0-9a-fA-F]+)// && do {$new .= $1; next;};
151 s/^(\d+)// && do {$new .= $1; next;};
152 s/^("(\\"|[^"])*")// && do {$new .= $1; next;};
153 s/^'((\\"|[^"])*)'// && do {
155 $new .= "ord('\$$1')";
162 s/^(struct\s+\w+)// && do {$new .= "'$1'"; next;};
163 s/^sizeof\s*\(([^)]+)\)/{$1}/ && do {
167 s/^([_a-zA-Z]\w*)// && do {
172 elsif ($id eq 'defined') {
176 s/^\((\w),/("$1",/ if $id =~ /^_IO[WR]*$/; # cheat
179 elsif ($isatype{$id}) {
187 s/^(.)// && do {$new .= $1; next;};