Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Convert makefile to Perl

by Sara (Acolyte)
on Aug 14, 2002 at 14:35 UTC ( #190089=perlquestion: print w/ replies, xml ) Need Help??
Sara has asked for the wisdom of the Perl Monks concerning the following question:

hello guys , can you give me a hint to r-write this shell script to perl , I am having hard time only on the for loop part :
LS = /bin/ls MV = /bin/mv TR = /bin/tr AWK = /opt/corp/sir/nbss/tools/utils/gawk NOIMGEN = ../../../nbsstools/noisgen/bin/noimgen NOIPGEN = ../../../nbsstools/noisgen/bin/noipgen OBJDIR = $(NOIVERDIR)/obj compile: setup: @if [ ! -d $(OBJDIR) ]; then mkdir $(OBJDIR); fi genfiles: setup @cd ../src; for PDL in `$(LS) *.pdl | $(TR) '.' ' ' | $(AWK) '{pri +nt $$1}'`; do \ if [ ! -f $${PDL}.cxx -o $${PDL}.pdl -nt $${PDL}.cxx ]; then +\ echo Generating $${PDL}... ; \ $(NOIPGEN) $${PDL}.pdl >> $(OBJDIR)/noipgen.err 2>&1; \ fi \ done @if [ -f $(OBJDIR)/noipgen.err ]; then $(MV) $(OBJDIR)/noipgen.err + $(OBJDIR)/noipgen.debug; fi @cd ../src; for MDL in `$(LS) *.mdl | $(TR) '.' ' ' | $(AWK) '{pri +nt $$1}'`; do \ if [ ! -f $${MDL}.cxx -o $${MDL}.mdl -nt $${MDL}.cxx ]; then +\ echo Generating $${MDL}... ; \ $(NOIMGEN) $${MDL}.mdl >> $(OBJDIR)/noimgen.err 2>&1; \ fi \ done @if [ -f $(OBJDIR)/noimgen.err ]; then $(MV) $(OBJDIR)/noimgen.err + $(OBJDIR)/noimgen.debug; fi clean: @if [ -d $(OBJDIR) ]; then $(RM) $(OBJDIR)/*; fi

edited: Wed Aug 14 19:40:42 2002 by jeffa - title change (was: shell to Perl)

Comment on Convert makefile to Perl
Download Code
Re: shell to perl
by derby (Abbot) on Aug 14, 2002 at 15:11 UTC
    Well, this is more than and ordinary shell script - its a makefile. While I wouldn't want to rewrite a makefile in perl, you could simplify the genfiles recipe by replacing the shell script there with a perl script.

    The recipe for genfiles basically does this

    chdir to src foreach basename of "*.pdl" files if( $basname.cxx does not exist ) or ( $basname.pdl is newer than $basename.cxx ) then execute NOIPGEN on $basename.pdl outputting stderr and stdout to $OBJDIR/noipgen.err endif endfor if( $OBJDIR/noipgen.err exists ) then mv the noipgen.err file to noipgen.debug endif chdir to src foreach basename of "*mdl" files if( $basname.cxx does not exist ) or ( $basnemae.mdl is newer than $basname.cxx) then execute NOIMGEN on $basename.mdl outputting stderr and stdout to $OBJEDIR/noimgen.err endif endfor if( $OBJDIR/noimgen.err exists ) then mv the noimgen.err file to noimgen.debug endif

    You could easily combine those two things into a perl script and then change the recipe to be something like this:

    genfiles: setup @my_script pdl $NOIPGEN $OBJDIR noipgen.err @my_script mdl $NOIMGEN $OBJDIR noimgen.err

    -derby

    update but now that I think about it some more that whole script could be replaced by more generic makefiles recipes that show target files have a dependancies on pdl and mdl files. Check out the make book.

      thanks derby :)
      While I wouldn't want to rewrite a makefile in perl

      How about rewriting make in Perl? :)

        I beg to differ. cons is not Make. It's a make-like thing with a different basic philosophy. If you want Make in Perl, you would simply use pmake, which is a pure-Perl version that can understand normal Makefiles, including everything that ExtUtils::MakeMaker puts out.

        -- Randal L. Schwartz, Perl hacker

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://190089]
Approved by Courage
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (9)
As of 2015-07-06 08:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (70 votes), past polls