ACE Tutorial 005
On the road to a multithreaded server


And last (and probably least) is the perl script that pulls the dependency stuff out of Makefile and into .depend.



  #!/usr/bin/perl

        # Open the Makefile that has been mangled by 'make depend'
        # and suck it into a perl array.
open(IF,"<Makefile") || die;
@makefile = <IF>;
close(IF);

        # Now open our .depend file and a temporary Makefile.
        # We'll split the original Makefile between these two.
open(DF,">.depend") || die;
open(MF,">Makefile.tmp") || die;

        # For each line we read out of the original file...
foreach (@makefile) {

        # If we're into the dependency section, write the line
        # into the .depend file.
        #
        if( $depend ) {
                print DF $_;
        }
        else {
                # If we haven't gotten to the dependency section yet
                # then see if the current line is the separator that
                # "make depend" causes to be inserted.
                #
                if( m/^\Q# DO NOT DELETE THIS LINE -- g++dep uses it.\E/ ) {

                        # If so, change our "mode" and skip this line.
                        ++$depend;
                        next;
                }

                # Also skip the "include .depend" that we insert.  If we
                # don't do this, it is possible to have a bunch of these
                # inserted into the output when we read an unmangled Makefile
                next if( m/^include .depend/ );

                # Print the non-dependency info to the temporary Makefile
                print MF $_;
        }
}

# Tell our new Makefile to include the dependency file
print MF "include .depend\n";

# Close the two output files...
close(DF);
close(MF);

# Unlink (remove) the original Makefile and rename our
# temporary file.  There's obviously room for error checking
# here but we've got the Makefile checked into some revision
# control system anyway.  Don't we?

unlink("Makefile");
rename("Makefile.tmp","Makefile");

exit(0);


[Tutorial Index] [Continue This Tutorial]