From d472e1dfbf2ff39a9abba9d5ea97a813a29bc46b Mon Sep 17 00:00:00 2001 From: "Janet B. Anderson" Date: Fri, 5 Jul 2002 21:59:35 +0000 Subject: [PATCH] Remove cmplr DEPENDS options and simplify .depends build rules. --- configure/CONFIG.gnuCommon | 2 - configure/CONFIG_COMMON | 32 +-- configure/RULES_BUILD | 26 +- configure/os/CONFIG.hpux-parisc.hpux-parisc | 1 - configure/os/CONFIG.osf-alpha.osf-alpha | 2 - .../os/CONFIG.solaris-sparc.solaris-sparc | 1 - configure/os/CONFIG.solaris-x86.solaris-x86 | 2 - configure/os/CONFIG.sun4-68k.sun4-68k | 2 - ...CONFIG.win32-x86-borland.win32-x86-borland | 8 - configure/tools/makeDependsTargets.pl | 63 ----- configure/tools/mkmf.pl | 233 +++++++++--------- 11 files changed, 131 insertions(+), 241 deletions(-) delete mode 100644 configure/tools/makeDependsTargets.pl diff --git a/configure/CONFIG.gnuCommon b/configure/CONFIG.gnuCommon index ff32cb1de..bf01fc785 100644 --- a/configure/CONFIG.gnuCommon +++ b/configure/CONFIG.gnuCommon @@ -35,5 +35,3 @@ STATIC_LDFLAGS_NO = SHRLIB_LDFLAGS_YES = -shared SHRLIB_LDFLAGS_NO = -HDEPENDS_FLAGS_CMPLR = -MM - diff --git a/configure/CONFIG_COMMON b/configure/CONFIG_COMMON index 0e1faea9a..9b6291858 100644 --- a/configure/CONFIG_COMMON +++ b/configure/CONFIG_COMMON @@ -268,36 +268,22 @@ COMPILE.c = $(CC) -c $(CPPFLAGS) $(CFLAGS) $(call PATH_FILTER,$(INCLUDES)) $(SOU COMPILE.cpp = $(CCC) -c $(CPPFLAGS) $(CXXFLAGS) $(call PATH_FILTER,$(INCLUDES)) $(SOURCE_CXXFLAG) #-------------------------------------------------- -# Build depends command here +# Depends command -HOST_HDEPENDS_CMD = MKMF -CROSS_HDEPENDS_CMD = MKMF - -HDEPENDS_CMD = $($(BUILD_CLASS)_HDEPENDS_CMD) - -HDEPENDS.c_CMPLR = $(CC) -HDEPENDS.cpp_CMPLR = $(CCC) -HDEPENDSFLAGS_CMPLR += $(CPPFLAGS) $(INCLUDES) $< > $*$(DEP) - -HDEPENDS.c_MKMF = $(PERL) $(TOOLS)/mkmf.pl -HDEPENDS.cpp_MKMF = $(PERL) $(TOOLS)/mkmf.pl -HDEPENDSFLAGS_MKMF = -m $*$(DEP) $(HDEPENDS_INCLUDES_MKMF) $@ $< -HDEPENDS_INCLUDES_MKMF = $(filter .%,$(subst -I,,$(INCLUDES))) - -HDEPENDS.c = $(HDEPENDS.c_$(HDEPENDS_CMD)) -HDEPENDS.cpp = $(HDEPENDS.cpp_$(HDEPENDS_CMD)) -HDEPENDSFLAGS = $(HDEPENDSFLAGS_$(HDEPENDS_CMD)) -HDEPENDS_FLAGS = $(HDEPENDS_FLAGS_$(HDEPENDS_CMD)) -HDEPENDS_CMD.c = -$(HDEPENDS.c) $(HDEPENDS_FLAGS) $(HDEPENDSFLAGS) -HDEPENDS_CMD.cpp = -$(HDEPENDS.cpp) $(HDEPENDS_FLAGS) $(HDEPENDSFLAGS) -HDEPENDS_TARGETS_CMD = $(PERL) $(TOOLS)/makeDependsTargets.pl $*$(DEP) +HDEPENDS_FLAGS = +HDEPENDS_INCLUDES = $(filter .%,$(subst -I,,$(INCLUDES))) +HDEPENDSFLAGS = -m $*$(DEP) $(HDEPENDS_INCLUDES) $@ $< +HDEPENDS_CMD_YES = -$(MKMF) $(HDEPENDS_FLAGS) $(HDEPENDSFLAGS) +HDEPENDS_CMD_NO = echo "" +HDEPENDS_CMD = $(HDEPENDS_CMD_$(HDEPENDS)) #-------------------------------------------------- # depends definition TARGET_SRCS = $(foreach name, $(TESTPROD) $(PROD) $(LIBRARY), $($(name)_SRCS)) SRC_FILES = $(LIB_SRCS) $(LIBSRCS) $(SRCS) $(PROD_SRCS) $(TARGET_SRCS) -HDEPENDS_FILES = $(addsuffix $(DEP),$(notdir $(basename $(SRC_FILES)))) +HDEPENDS_FILES_YES = $(addsuffix $(DEP),$(notdir $(basename $(SRC_FILES)))) +HDEPENDS_FILES = $(HDEPENDS_FILES_$(HDEPENDS)) #--------------------------------------------------------------- # Names of installed items diff --git a/configure/RULES_BUILD b/configure/RULES_BUILD index 7c80df989..b1ed7ee92 100644 --- a/configure/RULES_BUILD +++ b/configure/RULES_BUILD @@ -81,11 +81,9 @@ all: install -include $(CONFIG)/RULES_JAVA -ifeq ($(HDEPENDS),YES) ifneq (,$(strip $(HDEPENDS_FILES))) -include $(HDEPENDS_FILES) endif -endif #--------------------------------------------------------------- # Create included Makefile for prod,testprod, and library targets @@ -197,38 +195,22 @@ $(OBJLIBNAME):%$(OBJ): $(OBJLIB_LD_OBJS) $(COMPILE.c) -traditional $< %$(OBJ): %.c -ifeq ($(HDEPENDS),YES) - @$(RM) $*$(DEP) - @$(HDEPENDS_CMD.c) - @$(HDEPENDS_TARGETS_CMD) $*$(DEP) -endif + @$(HDEPENDS_CMD) @$(RM) $@ $(COMPILE.c) $(call PATH_FILTER,$<) %$(OBJ): %.cc -ifeq ($(HDEPENDS),YES) - @$(RM) $*$(DEP) - @$(HDEPENDS_CMD.cpp) - @$(HDEPENDS_TARGETS_CMD) $*$(DEP) -endif + @$(HDEPENDS_CMD) @$(RM) $@ $(COMPILE.cpp) $(call PATH_FILTER,$<) $(COMPILE_FILTER.cpp) %$(OBJ): %.cpp -ifeq ($(HDEPENDS),YES) - @$(RM) $*$(DEP) - @$(HDEPENDS_CMD.cpp) - @$(HDEPENDS_TARGETS_CMD) $*$(DEP) -endif + @$(HDEPENDS_CMD) @$(RM) $@ $(COMPILE.cpp) $(call PATH_FILTER,$<) $(COMPILE_FILTER.cpp) %$(OBJ): %.C -ifeq ($(HDEPENDS),YES) - @$(RM) $*$(DEP) - @$(HDEPENDS_CMD.cpp) - @$(HDEPENDS_TARGETS_CMD) $*$(DEP) -endif + @$(HDEPENDS_CMD) @$(RM) $@ $(COMPILE.cpp) $(call PATH_FILTER,$<) $(COMPILE_FILTER.cpp) diff --git a/configure/os/CONFIG.hpux-parisc.hpux-parisc b/configure/os/CONFIG.hpux-parisc.hpux-parisc index 53f067ad8..580fc6f32 100644 --- a/configure/os/CONFIG.hpux-parisc.hpux-parisc +++ b/configure/os/CONFIG.hpux-parisc.hpux-parisc @@ -56,4 +56,3 @@ TARGET_LDFLAGS += -AA -mt SHRLIB_LDFLAGS_YES = -G -h $@ -HDEPENDS_FLAGS_CMPLR = +m diff --git a/configure/os/CONFIG.osf-alpha.osf-alpha b/configure/os/CONFIG.osf-alpha.osf-alpha index f340f017a..6f2ef8f24 100644 --- a/configure/os/CONFIG.osf-alpha.osf-alpha +++ b/configure/os/CONFIG.osf-alpha.osf-alpha @@ -42,8 +42,6 @@ STATIC_LDLIBS_NO= SHRLIB_LDFLAGS_YES = -shared -HDEPENDS_FLAGS_CMPLR = - ############# ??????????? #####ACC_SFLAGS_YES= -non_shared #####ACC_SFLAGS_NO= -call_shared diff --git a/configure/os/CONFIG.solaris-sparc.solaris-sparc b/configure/os/CONFIG.solaris-sparc.solaris-sparc index 8880549c6..87cf32f8f 100644 --- a/configure/os/CONFIG.solaris-sparc.solaris-sparc +++ b/configure/os/CONFIG.solaris-sparc.solaris-sparc @@ -52,5 +52,4 @@ STATIC_LDLIBS_NO= SHRLIB_LDFLAGS_YES = -G -h $@ -z ignore -z combreloc -z lazyload -HDEPENDS_FLAGS_CMPLR = -xM1 diff --git a/configure/os/CONFIG.solaris-x86.solaris-x86 b/configure/os/CONFIG.solaris-x86.solaris-x86 index 5d8e7c7c0..5d34e2a50 100644 --- a/configure/os/CONFIG.solaris-x86.solaris-x86 +++ b/configure/os/CONFIG.solaris-x86.solaris-x86 @@ -53,5 +53,3 @@ STATIC_LDLIBS_NO= SHRLIB_LDFLAGS_YES = -G -h $@ -z ignore -z combreloc -z lazyload -HDEPENDS_FLAGS_CMPLR = -xM1 - diff --git a/configure/os/CONFIG.sun4-68k.sun4-68k b/configure/os/CONFIG.sun4-68k.sun4-68k index 8d43a237b..4a1ba1ad6 100644 --- a/configure/os/CONFIG.sun4-68k.sun4-68k +++ b/configure/os/CONFIG.sun4-68k.sun4-68k @@ -46,5 +46,3 @@ STATIC_LDLIBS_NO= SHRLIB_LDFLAGS_YES = -assert pure-text -h $@ -HDEPENDS_FLAGS_CMPLR = -xM1 - diff --git a/configure/os/CONFIG.win32-x86-borland.win32-x86-borland b/configure/os/CONFIG.win32-x86-borland.win32-x86-borland index 19221376d..99416a202 100644 --- a/configure/os/CONFIG.win32-x86-borland.win32-x86-borland +++ b/configure/os/CONFIG.win32-x86-borland.win32-x86-borland @@ -270,13 +270,5 @@ LINK.cpp += , $@ ,,$(LINKLIBS) $(subst /,\\,$(LDLIBS)) # override of CONFIG_SITE default SHARED_LIBRARIES = YES -# gnu compiler used to create depends files -HDEPENDS_FLAGS_CMPLR = -MM -HDEPENDS.c_CMPLR = gcc -HDEPENDS.cpp_CMPLR = g++ - # override of CONFIG_COMMON HDEPENDS_INCLUDES_MKMF = $(filter-out $(BORLAND_INC),$(subst -I,,$(INCLUDES))) -# override of CONFIG_SITE -HOST_HDEPENDS_CMD=MKMF - diff --git a/configure/tools/makeDependsTargets.pl b/configure/tools/makeDependsTargets.pl deleted file mode 100644 index 86d4f28a4..000000000 --- a/configure/tools/makeDependsTargets.pl +++ /dev/null @@ -1,63 +0,0 @@ -eval 'exec perl -S $0 ${1+"$@"}' # -*- Mode: perl -*- - if $running_under_some_shell; # makeDependsTargets.pl - -# $Id$ -# -# Author: Janet Anderson -# - -sub Usage -{ - my ($txt) = @_; - - print "Usage:\n"; - print "\makeDependsTargets infile\n"; - print "\nError: $txt\n" if $txt; - - exit 2; -} - -# need at least one args: ARGV[0] -Usage("need an arg") if $#ARGV < 0; - -use Cwd; -use File::Path; -use File::Copy; - -$depfile = $ARGV[0]; -$tempfile = "$ARGV[0].temp"; - -if (-f $depfile) { - unlink("$tempfile"); - copy ($depfile, $tempfile) or die "$! copying $depfile"; - open(OUT,">> $depfile") or die "$! opening $depfile"; - open(IN,"< $tempfile") or die "$! opening $tempfile"; - print OUT "\n#Depend files must be targets to avoid 'No rule to make target ...' errors\n"; - $startline = 1; - while ($line = ) { - next if ( $line =~ /\s*#/ ); # skip comments - chomp($line); - #$line =~ s/[ ]//g; # remove blanks and tabs - next if ( $line =~ /^$/ ); # skip empty lines - $depends = $line; - if ( $startline ) { - $depends =~ s/.*?://; - } - @dependsarray = split(//,$depends); - if ( $dependsarray[$#dependsarray] =~ /\\/ - or ( $dependsarray[$#dependsarray-1] =~ /\\/ ) ) { - $depends =~ s/[ ]*\\\cM?$//; - $startline = 0; - } else { - $depends =~ s/[ ]*\cM?$//; - $startline = 1; - } - print OUT "$depends : \n"; - } - - print OUT "\n"; - close IN or die "Cannot close $tempfile: $!"; - close OUT or die "Cannot close $depfile: $!"; - unlink("$tempfile"); -} - diff --git a/configure/tools/mkmf.pl b/configure/tools/mkmf.pl index 4bc520177..aa1d3078f 100755 --- a/configure/tools/mkmf.pl +++ b/configure/tools/mkmf.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl #----------------------------------------------------------------------- -# mkmf.pl: Perl script to create include file dependancies +# mkmf.pl: Perl script to create #include file dependancies # # Limitations: # @@ -11,148 +11,151 @@ # 3) Does not keep track of the macros defined in #include files so can't # do #ifdefs #ifndef ... # 4) Does not know where system include files are located -# +# 5) Uses only #include lines with single or double quoted file names +# #----------------------------------------------------------------------- -require 5; -use strict; -use File::Basename; use Getopt::Std; -use vars qw( $opt_d $opt_m $opt_v ); # declare these global to be shared with Getopt:Std -my $version = '$Id$ '; +my $version = 'mkmf.pl,v 1.5 2002/03/25 21:33:24 jba Exp $ '; +my $endline = $/; +my %delim_match = ( q/'/ => q/'/, q/"/ => q/"/); +my %output; +my @includes; -# initialize variables: use getopts for these -getopts( 'dm:v' ) || die "\aSyntax: $0 [-d] [-m makefile] [-v] [targets]\n"; -$opt_v = 1 if $opt_d; # debug flag turns on verbose flag also -print "$0 $version\n" if $opt_v; +use vars qw( $opt_d $opt_m ); +getopts( 'dm:' ) || die "\aSyntax: $0 [-d] [-f dependsFile] includeDirs objFile srcFile\n"; +my $debug = $opt_d; +my $depFile = $opt_m; -$opt_m = 'depends' unless $opt_m; # set default file name -print "Making depends file $opt_m ...\n" if $opt_v; +print "$0 $version\n" if $debug; +# directory list my @dirs; my $i; foreach $i (0 .. $#ARGV-2) { push @dirs, $ARGV[$i]; } -#some generic declarations -my( $file, $line); -my %scanned; # list of directories/files already scanned -my $object = $ARGV[$#ARGV-1]; # object file -my $source = $ARGV[$#ARGV]; # sourcefile from object +my $objFile = $ARGV[$#ARGV-1]; +my $srcFile = $ARGV[$#ARGV]; -#some constants -my $endline = $/; -my %delim_match = ( q/'/ => q/'/, # hash to find includefile delimiter pair - q/"/ => q/"/, - q/ q/>/ ); +if( $debug ) { + print "DEBUG: dirs= @dirs\n"; + print "DEBUG: source= $srcFile\n"; + print "DEBUG: object= $objFile\n"; +} -#formatting command for MAKEFILE, keeps very long lines to 80 characters -format MAKEFILE = -^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< \~ +print "Generating dependencies for $objFile\n" if $debug; +scanFile($srcFile); +scanIncludesList(); + +$depFile = 'depends' unless $depFile; + +print "Creating file $depFile\n" if $debug; +printList($depFile,$objFile); + +print "\n ALL DONE \n\n" if $debug; + + + +#---------------------------------------- +sub printList{ + my $depFile = shift; + my $objFile = shift; + my $line; + + unlink($depFile) or die "Can't delete $depFile: $!\n" if -f $depFile; + + open DEPENDS, ">$depFile" or die "\aERROR opening file $depFile for writing: $!\n"; + + my $old_handle = select(DEPENDS); + +#Limit lines to 80 characters +# a dot marks the end of the format +format DEPENDS_FMT = +^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\~ $line . -sub print_formatted_list{ -#this routine, in conjunction with the format line above, can be used to break up long lines -# it is currently used to break up the potentially long defs of SRC, OBJ, CPPDEFS, etc. -# not used for the dependency lists - $line = "@_"; - local $: = " \t\n"; # the default formatting word boundary includes the hyphen, but not here +format TARGETS_FMT = +^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<:~ +$line +. + + print "# DO NOT EDIT: This file created by $version\n\n"; + + local $: = " \t\n"; # remove hyphen from word boundary defaults + + $~ = DEPENDS_FMT; + $line = "$objFile : @includes"; while ( length $line > 78 ) { - write MAKEFILE, $line; + write ; } - print MAKEFILE $line unless $line eq ''; - print MAKEFILE "\n"; + print $line unless $line eq ''; + print "\n\n"; + print "#Depend files must be targets to avoid 'No rule to make target ...' errors\n"; + + $~ = TARGETS_FMT; + $line = "@includes"; + while ( length $line > 78 ) { + write ; + } + print "$line :" unless $line eq ''; + + select($old_handle) ; # in this case, STDOUT } -#begin writing makefile -open MAKEFILE, ">$opt_m" or die "\aERROR opening file $opt_m for writing: $!\n"; -printf MAKEFILE "# Makefile created by %s $version\n\n", basename($0); - -if( $opt_d ) { - print "DEBUG: dirs= @dirs\n"; - print "DEBUG: source= $source\n"; - print "DEBUG: object= $object\n"; -} - -my %includes_in; # hash of includes in a given source file (hashed against the corresponding object) -#subroutine to scan file for include files -# first argument is $object, second is $file -sub scanfile_for_keywords { - my $object = shift; +#------------------------------------------- +# scan file for #includes +sub scanFile { my $file = shift; - local $/ = $endline; - #if file has already been scanned, return - return if $scanned{$file}; - print "Scanning file $file of object $object ...\n" if $opt_v; - open FILE, $file or die "\aERROR opening file $file of object $object: $!\n"; + my $incfile; + my $line; + print "Scanning file $file\n" if $debug; + open FILE, $file or return; foreach $line ( ) { - next if !($line =~ m/^[ ]*\#?[ ]*include/); - if( $line =~ /^[\#?\s]*include\s*(['""'<])([\w\.\/]*)$delim_match{\1}/ix ) { - $includes_in{$file} .= ' ' . $2 if $2; - } + $incfile = findNextIncName($line); + next if !$incfile; + next if $output{$incfile}; + push @includes,$incfile; + $output{$incfile} = 1; } close FILE; - $scanned{$file} = 1; - print " uses includes=$includes_in{$file}.\n" if $opt_d; } -&scanfile_for_keywords( $object, $source ); - -my %includes; # global list of includes -my @cmdline; -my %obj_of_include; # hash of includes for current object -print "Collecting dependencies for $object ...\n" if $opt_v; -@cmdline = "$object: "; -#includes: done in subroutine since it must be recursively called to look for embedded includes -&get_include_list( $object, $source ); -#write the command line: if no file-specific command, use generic command for this suffix -&print_formatted_list(@cmdline) if $#cmdline > 1 ; - -# subroutine to seek out includes recursively -sub get_include_list { - my( $incfile, $incname, $incpath ); - my @paths; - my $object = shift; - my $file = shift; - my $include; - foreach ( split /\s+/, $includes_in{$file} ) { - print "object=$object, file=$file, include=$_.\n" if $opt_d; - if ( $scanned{"$_"} ) { - print "DEBUG: skipping scanned file $_\n" if $opt_d; - next; - } - $include = $_; - $incname = basename($_); - next if ( $incname eq '' ); - $incpath = dirname($_); - undef $incpath if $incpath eq './'; - undef $incpath if $incpath eq '.'; - if( $incpath =~ /^\// ) { - @paths = $incpath; # exact incpath specified, use it - } else { - @paths = @dirs; - } - foreach ( @paths ) { - local $/ = '/'; chomp; # remove trailing / if present - my $newincpath = "$_/$incpath" if $_; - undef $newincpath if $newincpath eq './'; - $incfile = "$newincpath$incname"; - print "DEBUG: checking for $incfile in $_\n" if $opt_d; - if ( -f $incfile and $obj_of_include{$incfile} ne $object ) { - push @cmdline, $incfile; - $includes{$incfile} = 1; - chomp( $newincpath ); - $newincpath = '.' if $newincpath eq ''; - &scanfile_for_keywords($object,$incfile); - $obj_of_include{$incfile} = $object; - &get_include_list($object,$incfile); # recursively look for includes - last; - } - } - $scanned{"$include"} = 1; +#------------------------------------------ +# scan files in includes list +sub scanIncludesList { + my $file; + foreach $file (@includes) { + scanFile($file); } } +#----------------------------------------- +# find filename on #include line +sub findNextIncName { + my $line = shift; + my $incname = ""; + my $incfile = 0; + my $dir; + + local $/ = $endline; + return 0 if !($line =~ m/^[ ]*\#?[ ]*include/); + return 0 if !($line =~ /^[\#?\s]*include\s*(['""'<])([\w\.\/]*)$delim_match{\1}/ix); + return 0 if !$2; + $incname = $2; + + return $incname if -f $incname; + return 0 if ( $incname =~ /^\// || $incname =~ /^\\/ ); + + foreach $dir ( @dirs ) { + chomp($dir); + $incfile = "$dir/$incname"; + print "DEBUG: checking for $incname in $dir\n" if $debug; + return $incfile if -f $incfile; + } + return 0; +} +