#!/usr/local/bin/perl -w # # arts2make # # Given a directory of articles, create a Makefile file. This # is done by reading from the Makefile.template file, # which contains a tag, which it expands into the # article list, and a tag, which expands into a # list of EPS files, on which the book may depend. # use Cwd; $cwd = cwd() ; use lib $cwd ; use BOOKSTUFF ; $usg = "Usage: arts2make.pl [-paperdir dirname]\n" ; # Any command line switches? # while ($ARGV[0] =~ /^-/) { $_ = shift; if (/^-paperdir$/) { $paperdir = shift ; } else { $usg ; die "Unrecognized switch: $_\n" ; } } open( IN, "Makefile.template" ) || die "Cannot open Makefile.template file.\n" ; open( OUT, ">Makefile" ) || die "Cannot open Makefile output file.\n" ; undef $/ ; $\ = "\n" ; $template= ; @lines = split /\n/m, $template ; foreach $line (@lines) { next if ( $line =~ /^%/ ) ; if( $line =~ // ) { &paperlist( $paperdir ) ; } elsif( $line =~ // ) { &figlist( $paperdir ) ; } elsif( $line =~ // ) { &warnings( $paperdir ) ; }else { print OUT $line ; } } exit() ; # &paperlist( $dirname ) ; # # Create a list of .tex files in directory $dirname. If $dirname # is not defined, then just look in the current directory. Translate # the name into the form used in the book, and list as a makefile # macro. sub paperlist { my( $dirname ) = @_ ; my( $file, @filelist, $filename, ) ; if( defined( $dirname ) ) { @filelist = glob( "$dirname$pathsep*.$ext_in" ); } else { @filelist = glob( "*.$ext_in" ); } print OUT "PAPERS = \\" ; foreach $file (@filelist) { # Obtain file root name by swapping output for input filename # extension, and stripping off any leading path elements. ( $filename = $file ) =~ s/$ext_in$/$ext_out/ ; $filename =~ s/^.*$pathsep([^$pathsep]*)/$1/ ; print OUT "\t$filename \\" ; } print OUT "" ; } # &figlist( $dirname ) ; # # Create a list of .*ps* files in directory $dirname. If $dirname # is not defined, then just look in the current directory. List # as a makefile macro. sub figlist { my( $dirname ) = @_ ; my( $file, @filelist, $filename, ) ; if( defined( $dirname ) ) { @filelist = glob( "$dirname$pathsep*.*ps*" ); } else { @filelist = glob( "*.*ps*" ); } print OUT "FIGURES = \\" ; foreach $file (@filelist) { # Obtain file root name by swapping output for input filename # extension, and stripping off any leading path elements. ( $filename = $file ) =~ s/^.*$pathsep([^$pathsep]*)/$1/ ; print OUT "\t$filename \\" ; } print OUT "" ; } # &warnings( $dirname ) # # If $dirname is defined, then the papers must live in another # directory. If that is so, then only GNU make can be used. # Print a warning to this effect, and set VPATH, the GNU make # variable that will help it find what it needs. # sub warnings{ my( $dirname ) = @_ ; if( defined($dirname) && ( $dirname ne "" ) ) { print OUT "# Papers are in another directory. Use GNU make" ; print OUT "# (gmake?) instead of make.\n" ; chdir $dirname ; $paperdir = cwd() ; print OUT "VPATH = $paperdir" ; chdir $cwd ; } }