14 ########################################################################
21 print "Usage: shell_include --source <file> --destination <file> [--make] [--help]\n";
23 print "--make will output makefile dependencies to stdout and exit\n";
24 print "--help will output this text and exit\n";
27 ########################################################################
35 's|source=s' => \$source,
36 'd|destination=s' => \$destination,
38 'h|help' => \$help ) )
49 die( "Missing input file - use --source <file>" ) if ( $source eq "" );
50 die( "Missing output file - use --destination <file>") if ( $destination eq "" );
53 ########################################################################
55 # read_input : Read in the initial input file into @lines
60 open( SOURCE, $source ) || die ( "Cannot open input file : $source" );
62 @lines = ( @lines, $_ );
67 ########################################################################
69 # Process #include directives
71 sub process_includes()
76 foreach my $line ( @lines ) {
78 if ( $line =~ /^(\s*)\#include(\s+)(\S+)/ ) {
81 if ( ! defined $included{ $filename } ) {
82 open( INC, $filename ) || die ( "Cannot open include file : $filename" );
83 @newlines = ( @newlines, "########################################################################\n" );
84 @newlines = ( @newlines, "#\n" );
85 @newlines = ( @newlines, "# Included file : $filename\n" );
86 @newlines = ( @newlines, "#\n" );
88 @newlines = ( @newlines, $_ );
91 @newlines = ( @newlines, "#\n" );
92 @newlines = ( @newlines, "# End of included file : $filename\n" );
93 @newlines = ( @newlines, "#\n" );
94 @newlines = ( @newlines, "########################################################################\n" );
95 $included{ $filename } = "";
98 @newlines = ( @newlines, $line );
105 ########################################################################
107 # write_output : write the final set of lines to the output file
111 open( DEST, ">$destination" ) || die( "Cannot open output file : $destination" );
112 foreach my $line ( @lines ) {
120 while ( &process_includes ) { };
122 print "$destination: $source ";
123 foreach my $inc ( sort( keys( %included ) ) ) {