home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / gnurecod.zip / configdos < prev    next >
Text File  |  1994-04-14  |  7KB  |  328 lines

  1. #!/usr/bin/perl -s
  2. eval "exec /usr/bin/perl -s -S $0 $*"
  3.     if $running_under_some_shell;
  4.  
  5. # Convert `Makefile.in' into a Makefile for MSDOS.
  6. # Copyright (C) 1991, 1993, 1994 Free Software Foundation, Inc.
  7. # Francois Pinard <pinard@iro.umontreal.ca>, 1991
  8.  
  9. # Usage: $0 [-tcc]
  10.  
  11. $output_name = $tcc ? "makefile.tcc" : "makefile.xxx";
  12. $output_name = "-";
  13.  
  14. open (INPUT, "Makefile.in") || die "Cannot read Makefile.in\n";
  15. open (OUTPUT, ">$output_name") || die "Cannot create $output_name\n";
  16.  
  17. # Default @VARIABLE@ substitutions for MSDOS.  Changed or activated by
  18. # MSDOS_<variable>=<new-default> lines in Makefile.in.
  19.  
  20. $configure{"ALLOCA"} = "";
  21. $configure{"LIBOBJS"} = "";
  22. $configure{"VPATH"} = ".";
  23. $configure{"srcdir"} = ".";
  24.  
  25. # Default VARIABLE= overrides and @VARIABLE@ substitutions for MSDOS.
  26. # VARIABLE= overrides are deactivated for variables in %configure.
  27.  
  28. $override{"AR"} = $tcc ? "tlib" : "ar";
  29. $override{"AWK"} = "@echo :";
  30. $override{"CC"} = $tcc ? "tcc -v -N" : "gcc";
  31. $override{"CFLAGS"} = "";
  32. $override{"DEFS"} = "-DHAVE_CONFIG_H";
  33. $override{"INSTALL"} = "@echo :";
  34. $override{"INSTALL_DATA"} = $tcc ? "copy" : "cp";
  35. $override{"INSTALL_PROGRAM"} = $tcc ? "copy" : "cp";
  36. $override{"LDFLAGS"} = "";
  37. $override{"LEX"} = $tcc ? "@echo :" : "flex";
  38. $override{"LIBS"} = "";
  39. $override{"MAKEINFO"} = "@echo :";
  40. $override{"RANLIB"} = $tcc ? "@echo :" : "ranlib";
  41. $override{"TEXI2DVI"} = "@echo :";
  42. $override{"U"} = "";
  43. $override{"YACC"} = $tcc ? "@echo :" : "bison -y";
  44.  
  45. # Default file renames for MSDOS.  Macros DISTFILES, *HDRS, *HEADERS,
  46. # *SRCS, *SOURCES, *OBJS, *OBJECTS also introduce file lists.
  47.  
  48. $renaming{"GNUmakefile"} = "makefile.gnu";
  49. $renaming{"tags"} = "tags";
  50. $renaming{"TAGS"} = "tagse";
  51.  
  52. # Transform `Makefile.in' into `$output_name'.
  53.  
  54. print OUTPUT "# Generated automatically from Makefile.in by `$0'.\n";
  55. while (<INPUT>)
  56. {
  57.     chop;
  58.  
  59.     # Process Makefile.in comments.  A few are special purpose.
  60.  
  61.     if (/^\#=MSDOS=(.*)/)
  62.     {
  63.     # An =MSDOS= comment outputs the remainder of the line, verbatim.
  64.  
  65.     print OUTPUT $1, "\n";
  66.     next;
  67.     }
  68.     elsif (/^\#-MSDOS/)
  69.     {
  70.     # An -MSDOS comment remove all lines until an +MSDOS comment.
  71.  
  72.     while (<INPUT>)
  73.     {
  74.         last if /^\#\+MSDOS/;
  75.     }
  76.     last if !$_;
  77.     next;
  78.     }
  79.     elsif (/^\#/)
  80.     {
  81.     # Copy other comments right now.
  82.  
  83.     print OUTPUT $_, "\n";
  84.     next;
  85.     }
  86.  
  87.     # Remove $U prefixes, useless, so file name renaming works better.
  88.  
  89.     s/\$U//g;
  90.  
  91.     # Execute @...@ substitutions.
  92.  
  93.     while (/(.*)\@(\w[\w0-9]*)\@(.*)/)
  94.     {
  95.     if (defined $configure{$2})
  96.     {
  97.         $_ = $1 . $configure{$2} . $3;
  98.     }
  99.     elsif (defined $override{$2})
  100.     {
  101.         $_ = $1 . $override{$2} . $3;
  102.     }
  103.     else
  104.     {
  105.         warn "*** @$2@ not substituted ***";
  106.         last;
  107.     }
  108.     }
  109.  
  110.     # Save MSDOS_* definitions for later substitution.  MSDOS_PROGS
  111.     # announce file names which should have .exe appended.
  112.  
  113.     if (/^MSDOS_PROGS\s*=\s*(.*)/)
  114.     {
  115.     foreach $prog (split (' ', $1))
  116.     {
  117.         $renaming{$prog} = &dosfn ("$prog.exe");
  118.         $program{$prog} = 1;
  119.     }
  120.     next;
  121.     }
  122.  
  123.     if (/^MSDOS_([^\s]+)\s*=\s*(.*)/)
  124.     {
  125.     $configure{$1} = $2;
  126.     next;
  127.     }
  128.  
  129.     # Some macros annonce list of files.  Study these lines to get a
  130.     # better %renaming cache.
  131.  
  132.     if (/^(DISTFILES|\w*HDRS|\w*HEADERS)\s*=\s*(.*)/)
  133.     {
  134.     &studylist ($2);
  135.     $studylist = 1;
  136.     }
  137.     elsif (/^(\w*SRCS|\w*SOURCES|\w*OBJS|\w*OBJECTS)\s*=\s*(.*)/)
  138.     {
  139.     &studylist ($2);
  140.     $studylist = 1;
  141.     }
  142.     elsif ($studylist)
  143.     {
  144.     &studylist ($_);
  145.     }
  146.  
  147.     if ($studylist && ! /\\$/)
  148.     {
  149.     $studylist = 0;
  150.     }
  151.  
  152.     # Extract each word of the line and process it.
  153.  
  154.     ($_, $line) = /^(\w[\w0-9]*\s*=\s*)?(.*)/;
  155.     while ($line =~ /[-.\w\/]+/)
  156.     {
  157.     $_ .= $`;
  158.     $line = $';
  159.  
  160.     if (defined $renaming{$&})
  161.     {
  162.         # Execute any previously saved substitution.
  163.  
  164.         $value = $renaming{$&};
  165.     }
  166.     else
  167.     {
  168.         $value = $&;
  169.         if ($value =~ /^[^.]+\.[^.]+$/)
  170.         {
  171.         # Normalize anything resembling a file name.
  172.  
  173.         $value = &dosfn ($value);
  174.         }
  175.     }
  176.     $_ .= $value;
  177.     }
  178.     $_ .= $line;
  179.  
  180.     # Check for other special modifications.
  181.  
  182.     if (/^SHELL\s*=/)
  183.     {
  184.     s/^/#/;
  185.     }
  186.     elsif (/^    \$\(CC\).*-o\s+(\w+)/)
  187.     {
  188.     if ($tcc)
  189.     {
  190.         s/-o\s+/-e/;
  191.         s/\$\(OBJECTS\)/@objects.lst/;
  192.     }
  193.     else
  194.     {
  195.         $aout = $1;
  196.         s/\.exe//;
  197.     }
  198.     }
  199.     elsif (/^    \$\(AR\)\scru\s/ && $tcc)
  200.     {
  201.     s/\scru//;
  202.     s/\$\(LIBOBJS\)/@libobjs.lst/;
  203.     }
  204.     elsif (/^\w+\s*=\s*:\b/ || /^    :\b/)
  205.     {
  206.     s/:/@echo :/;
  207.     }
  208.     elsif ((/^\w+\s*=\s*cp\b/ || /^    cp\b/) && $tcc)
  209.     {
  210.     s/cp(\s+-\w+)*/copy/;
  211.     }
  212.     elsif ((/^\w+\s*=\s*rm\b/ || /^    rm\b/) && $tcc)
  213.     {
  214.     s/rm(\s+-\w+)*/erase/;
  215.     }
  216.     elsif (/^\.c\.o:$/ && $tcc)
  217.     {
  218.     print OUTPUT ".SUFFIXES: .obj\n";
  219.     s/\.o/\.obj/;
  220.     }
  221.     elsif (/^(\w+)\s*=/)
  222.     {
  223.     if (!defined $configure{$1} && defined $override{$1})
  224.     {
  225.         $_ = $1 . " = " . $override{$1};
  226.     }
  227.     }
  228.     elsif (/^$/ && $aout)
  229.     {
  230.     print OUTPUT "\taout2exe $aout\n";
  231.     print OUTPUT "\trm $aout\n";
  232.     $aout = "";
  233.     }
  234.  
  235.     print OUTPUT $_, "\n";
  236. }
  237. close INPUT;
  238. close OUTPUT;
  239. exit 0;
  240.  
  241. # Prepare substitutions for the given list of files.
  242.  
  243. sub studylist
  244. {
  245.     $list = $_[0];
  246.     $list =~ s/\$\(\w+\)//g;
  247.     $list =~ s/\\$//;
  248.     while ($list =~ /([-.\w\/]+)/)
  249.     {
  250.     $list = $';
  251.     $value = $&;
  252.     $renaming{$value} = &dosfn ($&);
  253.     }
  254. }
  255.  
  256. # Turn the argument into an MSDOS file name.
  257. # Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
  258. # Francois Pinard <pinard@iro.umontreal.ca>, 1992.
  259.  
  260. # Predefine $tcc if necessary.
  261.  
  262. sub dosfn
  263. {
  264.     local ($whole, $prefix, $name, $ext);
  265.  
  266.     $whole = $_[0];
  267.     $whole =~ y/A-Z/a-z/;
  268.  
  269.     # Change any beginning period with an underline.
  270.  
  271.     $whole =~ s/^\./_/;
  272.  
  273.     # Change all periods except the last with underlines.
  274.  
  275.     while ($whole =~ /(.*)\.(.*)\.(.*)/)
  276.     {
  277.     $whole = "$1_$2.$3";
  278.     }
  279.  
  280.     # If no period at all, let flow characters after the 8th into the
  281.     # the extension.
  282.  
  283.     if ($whole =~ /^(.*\/)?([^.\/]+)$/)
  284.     {
  285.     ($prefix, $name, $ext) = ($1, $2, "");
  286.     if (length ($name) > 8)
  287.     {
  288.         $ext = substr ($name, 8);
  289.         $name = substr ($name, 0, 8);
  290.         $ext = substr ($ext, 0, 3) if length ($ext) > 3;
  291.         return "$prefix$name.$ext";
  292.     }
  293.     return "$prefix$name";
  294.     }
  295.  
  296.     # There is only one period, truncate to 8 characters before it and
  297.     # to 3 characters after it.
  298.  
  299.     if ($whole =~ /^(.*\/)?([^.\/]+)\.([^.\/]+)$/)
  300.     {
  301.     ($prefix, $name, $ext) = ($1, $2, $3);
  302.     $name = substr ($name, 0, 8) if length ($name) > 8;
  303.     if ($ext eq "a" && $tcc)
  304.     {
  305.         $ext = "lib";
  306.     }
  307.     elsif ($ext eq "o" && $tcc)
  308.     {
  309.         $ext = "obj";
  310.     }
  311.     elsif ($ext eq "texi" || $ext eq "texinfo")
  312.     {
  313.         $ext = "ti";
  314.     }
  315.     elsif (length ($ext) > 3)
  316.     {
  317.         $ext = substr ($ext, 0, 3);
  318.     }
  319.     return "$prefix$name.$ext";
  320.     }
  321.  
  322.     # This should not happen.
  323.  
  324.     warn "Error in dosfn.pl for \`$_[0]'\n";
  325.     return $_[0];
  326. }
  327.  
  328.