#!/usr/bin/perl -w # # Name: # patchMake.pl. # # Purpose: # Patch makefiles & other things for various packages. # # Notes: # Package Procedure # ------------------------- # vim tar xvzf vim-5_1.tar.gz # cd vim-5.1/src # setenv SOURCE_DIR `pwd` # patchMake.pl -package vim -subPackage Makefile # make # patchMake.pl -package vim -subPackage osdef # make # make install # # Perl 5.005.02 makePerl500502.bat # Perl 5.005.03 makePerl500503.bat # # Author: # Ron Savage # http://savage.net.au/index.html # # Licence: # Australian Copyright (c) 1999-2002 Ron Savage. # # All Programs of mine are 'OSI Certified Open Source Software'; # you can redistribute them and/or modify them under the terms of # The Artistic License, a copy of which is available at: # http://www.opensource.org/licenses/index.html use strict; no strict 'refs'; use File::Find; use Getopt::Simple qw($switch); require 'projectLib.pl'; my($VERSION) = '1.00'; # ----------------------------------------------------------------------------- my(%package) = ( 'GD' => ['GD'], 'gnuplot' => ['gnuplot'], 'Perl500502' => ['Makefile'], 'Perl500503' => ['Makefile'], 'pgplot' => ['MakefilePL', 'makehtml', 'sys_irix', 'xsubppargs'], 'tk' => ['tk'], 'vim' => ['Makefile', 'osdef'], 'Win32' => ['any', 'MakefilePL'], 'xforms' => ['mkconfigh'], 'Xforms4Perl' => ['MakefilePL', 'Makefile', 'hashbang'], ); # ----------------------------------------------------------------------------- sub GD_GD { find(\&gnuplot_find, $ENV{'SOURCE_DIR'}); # As good as using GD_find. } # End of gnuplot_gnuplot. # ----------------------------------------------------------------------------- sub gnuplot_gnuplot { find(\&gnuplot_find, $ENV{'SOURCE_DIR'}); } # End of gnuplot_gnuplot. # ----------------------------------------------------------------------------- sub gnuplot_find { return if (! /^Makefile$/i); my($fileName) = $File::Find::name; print "Patching: $fileName\n"; my($line) = &readFile($_); for (@$line) { s/-Olimit 3000/-OPT:Olimit=3000/; } &writeFile($_, $line); } # End of gnuplot_find. # ----------------------------------------------------------------------------- sub init { my($default) = { 'help' => { 'type' => '', 'env' => '-', 'default' => '', 'order' => 1, }, 'home' => { 'type' => '=s', 'env', => '$HOME etc', 'default' => &getHome(), 'order' => 2, }, 'package' => { 'type' => '=s', 'env', => '-', 'default' => '', 'order' => 3, }, 'subPackage' => { 'type' => '=s', 'env', => '-', 'default' => '', 'order' => 4, }, 'verbose' => { 'type' => '', 'env', => '-', 'default' => '', 'order' => 5, }, }; my($option) = new Getopt::Simple; if (! $option -> getOptions($default, "Usage: patchMake.pl [options]") ) { # Failure. exit(-1); } } # End of init. # ----------------------------------------------------------------------------- sub Perl500502_Makefile { my($fileName) = "$ENV{'SOURCE_DIR'}/Makefile"; my($line) = &readFile($fileName); print "Patching: $fileName\n"; for (@$line) { s/^(INST_DRV\s*=).+/$1 c:/; # c: -> d:? s/^#(USE_PERLCRT.+)/$1/; # Activate. s/^#(USE_SETARGV.+)/$1/; # Activate, so 'nmake test' works :-(. s/^(CCHOME\s*=).+/$1 \$\(MSDEVDIR\)/; # $(MSVCDIR) -> ($MSDEVDIR). s/^#(EMAIL\s*=).+/$1 ron\@savage.net.au/; # Identify the usual suspect. } &writeFile($fileName, $line); } # End of Perl500502_Makefile. # ----------------------------------------------------------------------------- sub Perl500503_Makefile { my($fileName) = "$ENV{'SOURCE_DIR'}/Makefile"; my($line) = &readFile($fileName); print "Patching: $fileName\n"; for (@$line) { s/^(INST_DRV\s*=).+/$1 c:/; # c: -> c:. s/^#(USE_PERLCRT.+)/$1/; # Activate. # s/^#(USE_SETARGV.+)/$1/; # Activate, so 'nmake test' works :-(. # s/^(CCHOME\s*=).+/$1 \$\(MSDEVDIR\)/; # $(MSVCDIR) -> ($MSDEVDIR). s/^#(EMAIL\s*=).+/$1 ron\@savage.net.au/; # Identify the usual suspect. } &writeFile($fileName, $line); } # End of Perl500503_Makefile. # ----------------------------------------------------------------------------- sub pgplot_MakefilePL { my($fileName) = "$ENV{'SOURCE_DIR'}/Makefile.PL"; my($line) = &readFile($fileName); print "Patching: $fileName\n"; for (@$line) { s#/usr/local/pgplot#/users/rons/pgplotlib#; } &writeFile($fileName, $line); } # End of pgplot_MakefilePL. # ----------------------------------------------------------------------------- sub pgplot_makehtml { my($fileName) = "$ENV{'SOURCE_DIR'}/makehtml"; my($line) = &readFile($fileName); print "Patching: $fileName\n"; $$line[0] = '#!/usr/gnu/bin/perl'; &writeFile($fileName, $line); } # End of makehtml. # ----------------------------------------------------------------------------- sub pgplot_sys_irix { my($fileName) = "$ENV{'SOURCE_DIR'}/sys_irix/f77_cc.conf"; my($line) = &readFile($fileName); print "Patching: $fileName\n"; for (@$line) { s/X11_s/X11/; } &writeFile($fileName, $line); } # End of sys_irix. # ----------------------------------------------------------------------------- sub pgplot_xsubppargs { my($fileName) = "$ENV{'SOURCE_DIR'}/Makefile"; my($line) = &readFile($fileName); print "Patching: $fileName\n"; for (@$line) { s/^XSUBPPARGS = (.+)$/XSUBPPARGS = -nolinenumbers $1/; s/-Olimit 3000/-OPT:Olimit=3000/; } &writeFile($fileName, $line); } # End of xsubppargs. # ----------------------------------------------------------------------------- sub tk_find { return if (! /^makefile$/i); my($fileName) = $File::Find::name; print "Patching: $fileName\n"; my($line) = &readFile($fileName); for (@$line) { # Tk under Win95. # $_ .= ' -IG:\\Include' if (/^INC = /); # s/C:(\/|\\)Temp/F:/i; # s/C:(\/|\\)Perl/H:/i; # nvi under IRIX. s/-Olimit 3000/-OPT:Olimit=3000/; } &writeFile($fileName, $line); } # End of tk_find. # ----------------------------------------------------------------------------- sub tk_tk { find(\&tk_find, $ENV{'SOURCE_DIR'}); } # End of tk_tk. # ----------------------------------------------------------------------------- sub vim_Makefile { my($fileName) = "$ENV{'SOURCE_DIR'}/Makefile"; my($line) = &readFile($fileName); print "Patching: $fileName\n"; for (@$line) { s/^#(CONF_OPT_PERL.+)/$1/; s/^#(CONF_OPT_PYTHON.+)/$1/; s/^#(CC = cc)/$1/; s/^#(CFLAGS = -OPT:Olimit=)(\d+)(.+)/${1}3000$3/; s/^#(prefix = \$\(HOME\))/$1\/vim/; } &writeFile($fileName, $line); } # End of vim_Makefile. # ----------------------------------------------------------------------------- sub vim_osdef { my($fileName) = "$ENV{'SOURCE_DIR'}/osdef.h"; my($line) = &readFile($fileName); print "Patching: $fileName\n"; for (@$line) { substr($_, 0, 0) = '/*' if (/extern\s+int\s+bcmp/); substr($_, length, 0) = '*/' if (/extern\s+int\s+bcmp/); substr($_, 0, 0) = '/*' if (/extern\s+void\s+bzero/); substr($_, length, 0) = '*/' if (/extern\s+void\s+bzero/); } &writeFile($fileName, $line); } # End of vim_osdef. # ----------------------------------------------------------------------------- sub Win32_any { find(\&Win32_findMakefile, $ENV{'SOURCE_DIR'}); } # End of Win32_any. # ----------------------------------------------------------------------------- sub Win32_findMakefile { return if (! /^Makefile$/i); my($fileName) = $File::Find::name; $fileName =~ tr|/|\\|; print "Patching: $fileName\n"; system('attrib', '-R', $_); my($line) = &readFile($_); my($i, $j); for ($i = 0; $i < $#{$line}; $i++) { # Skip lines starting with a '-' and which are not continuation lines. next if ( ($$line[$i] =~ /^\s*-/) && ($$line[$i - 1] !~ /\s+\\$/) ); # # Convert C:\Program Files into C:\Progra~1. # if ($$line[$i] =~ /^(.+)PROGRAM FILES(.+)$/i) # { # print "Replacing: <$$line[$i]> on line: ", ($i + 1), " \n"; # # $$line[$i] = "$1Progra~1$2"; # # print " With: <$$line[$i])>\n"; # print "\n"; # } # Add wininet.lib if necessary. if ( ($$line[$i] !~ /wininet.lib/) && ($$line[$i] =~ /^(LDLOADLIBS\s*=\s*)(.+)$/) ) { print "Replacing: <$$line[$i]> on line: ", ($i + 1), " \n"; $$line[$i] = "$1 wininet.lib $2"; print " With: <$$line[$i])>\n"; print "\n"; } # Convert '$(DEV_NULL) || $(NOOP)' into '$(DEV_NULL)'. if ($$line[$i] =~ /^(.+)\$\(DEV_NULL\)\s+\|\|\s+\$\(NOOP\)\s*$/) { print "Replacing: <$$line[$i]> on line: ", ($i + 1), " \n" if ($$switch{'verbose'}); $$line[$i] = "$1\$(DEV_NULL)"; print " With: <$$line[$i]>\n" if ($$switch{'verbose'}); print "\n" if ($$switch{'verbose'}); } # Convert '$(X:s,/,\,)' into '$(X)'. if ($$line[$i] =~ /\$\(([_A-Z]+?):s,\/,\\,\)/) { print "Replacing: <$$line[$i]> on line: ", ($i + 1), " \n" if ($$switch{'verbose'}); $$line[$i] =~ s/\$\(([_A-Z]+?):s,\/,\\,\)/\$$1/g; print " With: <$$line[$i]>\n" if ($$switch{'verbose'}); print "\n" if ($$switch{'verbose'}); } # Convert '$(X:s,\,\\,)' into '$(X)'. This may not be a good idea. if ($$line[$i] =~ /\$\(([_A-Z]+?):s,.,..,\)/) { print "Replacing: <$$line[$i]> on line: ", ($i + 1), " \n" if ($$switch{'verbose'}); $$line[$i] =~ s/\$\(([_A-Z]+?):s,.,..,\)/\$$1/g; print " With: <$$line[$i]>\n" if ($$switch{'verbose'}); print "\n" if ($$switch{'verbose'}); } # Convert '$(X:^"+")' into '$(X)'. This may not produce a meaningful result. if ($$line[$i] =~ /\$\(([_A-Z]+?):\^"\+"\)/) { print "Replacing: <$$line[$i]> on line: ", ($i + 1), " \n" if ($$switch{'verbose'}); $$line[$i] =~ s/\$\(([_A-Z]+?):\^"\+"\)/\$$1/g; print " With: <$$line[$i]>\n" if ($$switch{'verbose'}); print "\n" if ($$switch{'verbose'}); } # Convert @cd into cd. if ($$line[$i] =~ /^(\s+)\@cd(.+)$/) { print "Replacing: <$$line[$i]> on line: ", ($i + 1), " \n" if ($$switch{'verbose'}); $$line[$i] = "$1cd$2"; print " With: <$$line[$i]>\n" if ($$switch{'verbose'}); print "\n" if ($$switch{'verbose'}); } # Search for &&. $j = index($$line[$i], ' && '); # Split && into 2 lines. if ($j > 0) { my($part1) = substr($$line[$i], 0, $j); my($part2) = "\t" . substr($$line[$i], ($j + 3) ); $part2 = "$1cd$2" if ($part2 =~ /^(\s+)\@cd(.+)$/); print "Replacing: <$$line[$i]> on line: ", ($i + 1), " \n" if ($$switch{'verbose'}); print " With: <$part1>\n" if ($$switch{'verbose'}); print " and: <$part2>\n" if ($$switch{'verbose'}); print "\n" if ($$switch{'verbose'}); splice(@$line, $i, 1, $part1, $part2); } # Search for 'cd x' not followed by 'cd ..'. if ( ($$line[$i] =~ /^(\s+)cd\s+(?!\.\.)/) && ($$line[$i + 2] !~ /^\s+cd\s+\.\./) ) { my($part) = "\tcd .."; print "Replacing: <$$line[$i]> on line: ", ($i + 1), " \n" if ($$switch{'verbose'}); print " and: <$$line[$i + 1]>\n" if ($$switch{'verbose'}); print " and: <$$line[$i + 2]>\n" if ($$switch{'verbose'}); print " With: <$$line[$i]>\n" if ($$switch{'verbose'}); print " and: <$$line[$i + 1]>\n" if ($$switch{'verbose'}); print " and: <$part>\n" if ($$switch{'verbose'}); print " and: <$$line[$i + 2]>\n" if ($$switch{'verbose'}); print "\n" if ($$switch{'verbose'}); splice(@$line, ($i + 2), 0, $part); } } &writeFile($_, $line); } # End of Win32_findMakefile. # ----------------------------------------------------------------------------- sub Win32_MakefilePL { find(\&Win32_findMakefilePL, $ENV{'SOURCE_DIR'}); } # End of Win32_any. # ----------------------------------------------------------------------------- sub Win32_findMakefilePL { return if (! /^Makefile.PL$/i); my($fileName) = $File::Find::name; $fileName =~ tr|/|\\|; print "Patching: $fileName\n"; my($line) = &readFile($_); my($i, $j); for ($i = 0; $i < $#{$line}; $i++) { # Cut out any line containing "'CPAI'". if ($$line[$i] =~ /'CAPI'/) { print "Deleting: <$$line[$i]> on line: ", ($i + 1), " \n"; print "\n"; splice(@$line, $i, 1) if ( ($$line[$i] =~ /'CAPI'/) ); } } system('attrib', '-R', $fileName); &writeFile($_, $line); } # End of Win32_find. # ----------------------------------------------------------------------------- sub xforms_mkconfigh { my($fileName) = "$ENV{'SOURCE_DIR'}/mkconfig.h"; print "Patching: $fileName\n"; my($line) = &readFile($fileName); for (@$line) { $_ = 'BIN_DIR=/local/users2/rons/perl/bin' if (/^BIN_DIR/); $_ = 'DOC_DIR=/local/users2/rons/perl/doc' if (/^DOC_DIR/); $_ = 'HEADER_DIR=/local/users2/rons/perl/include' if (/^HEADER_DIR/); $_ = 'LIB_DIR=/local/users2/rons/perl/lib' if (/^LIB_DIR/); $_ = 'MAN1_DIR=/local/users2/rons/perl/man1' if (/^MAN1_DIR/); $_ = 'MAN5_DIR=/local/users2/rons/perl/man5' if (/^MAN5_DIR/); } &writeFile($fileName, $line); } # End of xforms_mkconfigh. # ----------------------------------------------------------------------------- sub Xforms4Perl_find_1 { return if (! /^Makefile.PL$/); my($fileName) = $File::Find::name; print "Patching: $fileName\n"; my($line) = &readFile($fileName); for (@$line) { s#\'\'#\'-I/local/users2/rons/perl/include\'# if (/\s+'?INC'?/); } &writeFile($fileName, $line); } # End of Xforms4Perl_find_1. # ----------------------------------------------------------------------------- sub Xforms4Perl_find_2 { return if (! /^Makefile$/); my($fileName) = $File::Find::name; print "Patching: $fileName\n"; my($now) = time; utime $now, $now, $fileName; } # End of Xforms4Perl_find_2. # ----------------------------------------------------------------------------- sub Xforms4Perl_find_3 { return if (! /\.pl$/); my($fileName) = $File::Find::name; print "Patching: $fileName\n"; my($line) = &readFile($fileName); $$line[0] = '#!/usr/gnu/bin/perl'; &writeFile($fileName, $line); } # End of Xforms4Perl_find_3. # ----------------------------------------------------------------------------- sub Xforms4Perl_hashbang { find(\&Xforms4Perl_find_3, "$ENV{'SOURCE_DIR'}/DEMOS"); } # End of Xforms4Perl_hashbang. # ----------------------------------------------------------------------------- sub Xforms4Perl_Makefile { find(\&Xforms4Perl_find_2, "$ENV{'SOURCE_DIR'}/X11"); } # End of Xforms4Perl_Makefile. # ----------------------------------------------------------------------------- sub Xforms4Perl_MakefilePL { find(\&Xforms4Perl_find_1, "$ENV{'SOURCE_DIR'}/X11"); } # End of Xforms4Perl_MakefilePL. # ----------------------------------------------------------------------------- &init(); $0 =~ tr|\\|/|; $0 =~ s|.+/||; print "$0 V $VERSION.\n"; # Validate package. die('No package specified. Require 1 of: ' . join(' | ', keys(%package) ) ) if (! defined($package{$$switch{'package'} }) ); # Validate subPackage. my($found) = 0; for (@{$package{$$switch{'package'} } }) { $found = 1 if ($_ eq $$switch{'subPackage'}); } die("No subPackage specified") if (! $found); # Validate SOURCE_DIR. die("No setenv SOURCE_DIR") if (! defined($ENV{'SOURCE_DIR'}) || ! -d $ENV{'SOURCE_DIR'}); # Call worker. my($sub) = $$switch{'package'} . '_' . $$switch{'subPackage'}; &$sub(); print "Success\n"; # Success. exit(0); __END__ =head1 NAME patchMake.pl - Convert Unix-format make files into Windows format =head1 SYNOPSIS Run this via makeModule.bat. makeModule takes 4 parameters. Eg 1. 2nd parameter has no '-'. 3rd parameter is '0_13': ...>makeModule 1 libwin32 0_13 0.13 ...>makeModule 2 libwin32 0_13 0.13 Output: 142 lines, from: Installing C:\Perl\Site\5.00502\Lib\MSWin32-x86\auto\Win32\ChangeNotify\ChangeNotify.bs to: Installing C:\Perl\Site\5.00502\Lib\Win32API\Registry.pm Eg 2. 2nd parameter has 1 '-'. 3rd parameter is '1.30': ...>makeModule 1 Getopt-Simple 1.30 1.30 ...>makeModule 2 Getopt-Simple 1.30 1.30 Output: Installing C:\Perl\Site\5.00502\Lib\Getopt\testSimple.pl Installing C:\Perl\Site\5.00502\Lib\Getopt\Simple.pm Eg 3. 2nd parameter has 2 '-'s. 3rd parameter is '1.00': ...>makeModule 1 Lingua-EN-Stem 1.00 1.00 ...>makeModule 2 Lingua-EN-Stem 1.00 1.00 Output: Installing C:\Perl\Site\5.00502\Lib\Lingua\EN\Stem.pm =head1 DESCRIPTION Convert makefiles output by 'Perl Makefile.PL' into a format acceptable to nmake, and perhaps dmake. Along the way, various patches are applied to various files. For details, see: sub Win32_findMakefile and sub Win32_findMakefilePL =head1 AUTHOR C was written by Ron Savage Iron@savage.net.auE> in 1998. =head1 LICENCE Copyright © 1998, Ron Savage. All rights reserved. All Programs of mine are 'OSI Certified Open Source Software'; you can redistribute them and/or modify them under the terms of The Artistic License, a copy of which is available at: http://www.opensource.org/licenses/index.html