home news blogs forums events research newsletter whitepapers careers


Network Computing Network Computing Powered by InformationWeek Business Technology Network
InformationWeek 500 Conference -- September 14-16, 2008 Registed Today!

IMMERSE YOURSELF:

SOA

  |

Data Center

  |

802.11n

  |

Data Privacy

  |
APO  |

Virtualization

  |

NAC

  |

Security

  |

Network Mgmt

  |

Enterprise Apps

  |

Storage & Servers




Dependable Make Files: Listings

Listing 1: A make file dependency generator lists the header files required by each object-file target.

.

A. Listing of the Perl script:

1 #!/usr/bin/perl
2 # @(#) makedepend List make target dependencies
3 # Author: Dale Mensch, July 1993
4 # Modified by: Becca Thomas, January 1994
5 
6 # CONFIGURATION PARAMETERS:
7 
8 # Using GNU make?
9 $have_gmake = 0; # 0 = No, 1 = Yes
10 
11 # Choose the source-file suffix:
12 $source_suffix = '.c'; # Possibilities: .C, .cpp, .cc
13 
14 # Choose the object-file suffix:
15 $object_suffix = '.o'; # Another possibility: .xo
16 
17 # List directories containing header files that don't change:
18 $ignore_include_dirs = '/usr/include'; # Don't need to list these
19 
20 # Location of standard header files:
21 $add_include_dirs = '-I/usr/include'; # If not included automatically
22 
23 # Command that runs preprocessor, includes headers, excludes comments:
24 $cpp_cmd = 'cc -E';
25 
26 # MAIN PROGRAM:
27 
28 # Check correct command line usage:
29 die "Usage: $0 target [target...]\n" unless (@ARGV);# At least one
30 
31 # Open pipe to read make (or gmake) output:
32 if ($have_gmake) {
33 open(MAKE, "gmake -n -W $ARGV[0] |"); # -W outdates target
34 } else {
35 # Rename target because if non-existent it's treated as out-of-date:
36 ($sample_target = $ARGV[0]) =~ s/$source_suffix$/$object_suffix/;
37 if (-e $sample_target) { # If the sample target exists
38 $saved_target = "$sample_target"."~"; # Backup copy name
39 rename($sample_target, $saved_target); # Squirrel away
40 }
41 open(MAKE, "make -n $sample_target |"); # Make treats as dated
42 }
43 
44 # Determine necessary include directives:
45 while (<MAKE>) { # For each make-command output line
46 chop; # Remove trailing newline
47 @cmd_line = split(/[ \t]+/, $_); # Tokenize at whitespace
48 
49 while (@cmd_line) {
50 $make_token = shift (@cmd_line); # For each token
51 if ($make_token =~ /^-I|^-D/) { # Include/define?
52 $directive_token = $make_token; # Yes, save it
53 if (! $is_directive{$directive_token}) { # Not seen
54 $is_directive{$directive_token} .= $directive_token;
55 # Add to catenated string of include directories:
56 $cpp_directives .= " "; # (Catenation saves
57 $cpp_directives .= $directive_token;# original order)
58 }
59 }
60 } # End of while ($make_token = ...
61 } # End of while (<MAKE>) {
62 
63 # Add any necessary include directories:
64 $cpp_directives .= " $add_include_dirs ";
65 
66 # For each source file named on command line
67 while (@ARGV) { # While there are arguments
68 undef %includes; # Reset array before next file
69 $source_file = shift; # Save name for later use
70 if (! -r $source_file) { # Can file be read?
71 print STDERR "Source file \"$source_file\" not readable.\n";
72 next; # Try another source file, if available
73 }
74 # Preprocessor names all include directives:
75 open(CPP, "$cpp_cmd $cpp_directives $source_file |");
76 
77 # Create list of all included files:
78 while (<CPP>) {
79 s#//.*$##; # Delete C++ "//" comment
80 if (/^(#|#line)\s*\d+\s+["<](\S+)[">]\s+.*$/ &&
81 ! m.$ignore_include_dirs. ) { # Grab relevant includes
82 $includes{$2} .= $2 unless $includes{$2}; # Save name
83 } # End of if (/^ ...
84 } # End of while (<CPP>) {
85 
86 # Report target name:
87 $_ = $source_file;
88 s/$source_suffix$/$object_suffix/; # Create target name
89 print "$_ :"; # Dependency or rules line
90 
91 # List the prerequisites for the target:
92 foreach $dependency (sort keys(%includes)) {
93 print " \\\n"; # continuation line
94 print "\t$includes{$dependency}";# Important: tab first
95 }
96 print "\n\n"; # Empty lines between targets
97 }
98 rename($saved_target, $sample_target) if $saved_target;

B. Sample prototype Makefile:

# Make file to build program
#
CFLAGS = -g # for symbolic debugging
#
OBJS = module1.o module2.o
#
program: $(OBJS)
cc -o $@ $(OBJS)
#
# Object file dependencies:
#

C. Completed make file with object-file dependencies included:

# Make file to build program
#
CFLAGS = -g # for symbolic debugging
#
OBJS = module1.o module2.o
#
program: $(OBJS)
cc -o $@ $(OBJS)
#
# Object file dependencies:
#
module1.o : \
./module1.h \
module1.c
module2.o : \
module2.c

Listing 2: The zloop Bourne shell script lets you operate on selected compressed files.

A. Listing of the zloop program:

1 #! /bin/sh
2 # @(#) zloop Loop through compressed files, running command on each
3 # Author: Jerry Peek, April 1990, updated July 1993
4 # Modified by Kees Hendrikse, February 1994
5 
6 Myname=`basename $0` # Name of this program
7 Usage="Usage: $Myname 'command line to run' file.{Z|z|gz|zip}..."
8 
9 # Check command-line arguments:
10 case $# in
11 0|1) echo $Usage 1>&2 ; exit 1 ;;
12 esac
13 
14 # Save command quoting white space:
15 Cmd="$1"; shift # shift away command argument
16 
17 for File # For all remaining arguments (files)
18 do
19 case $File in
20 *.Z) Zcat=zcat ;;
21 *.z) Zcat=pcat ;;
22 *.gz) Zcat=gzcat ;;
23 *.zip) Zcat="unzip -c" ;;
24 *) echo "File type of \"$File\" not recognized." >&2
25 continue ;;
26 esac
27 
28 # Display a header, run the command, report any errors:
29 echo "
30 ==== $Myname: $Zcat $File | $Cmd ====" 1>&2
31 eval $Zcat $File \| $Cmd
32 Status=$?
33 case "$Status" in
34 0) ;;
35 *) echo "Note command that returned $Status exit status:
36 '$Zcat $File | $Cmd'" 1>&2 ;;
37 esac
38 done

B. Using zloop to print some compressed files:

$ ls ch*
ch01.Z ch02.Z ch03.Z ch04.Z ch05.Z
$ zloop 'pr | lp -d ast' ch0[1-3].Z
==== zloop: zcat ch01.Z | pr | lp -d ast ====
request id is ast-1904 (standard input)
==== zloop: zcat ch02.Z | pr | lp -d ast ====
request id is ast-1905 (standard input)
==== zloop: zcat ch03.Z | pr | lp -d ast ====
request id is ast-1906 (standard input)
$ []

C. Discarding the headers from the last example:

$ zloop 'pr | lp -d ast' ch0[1-3].Z 2>/dev/null
request id is ast-1907 (standard input)
request id is ast-1908 (standard input)
request id is ast-1909 (standard input)
$ []

D. Running grep to search for a text in compressed files:

$ zloop 'grep -i "System V"' ch0[12].Z
==== zloop: zcat ch01.Z | grep -i "System V" ====
Note command that returned 1 exit status:
'/usr/bin/zcat ch01.Z | grep -i "System V"'
==== zloop: zcat ch02.Z | grep -i "System V" ====
1 #ifdef TERMIO /* System V or BSD4.3+ */
$ []
Print This Page


e-mail Send as e-mail





Ready to take that job and shove it?

Function:

Keyword(s):

State:
SPONSOR
RECENT JOB POSTINGS
CAREER NEWS
Go beyond Google and get vertical. These specialized search sites will help you find the business information you need -- fast.

Ari Balogh was named to the post of chief technology officer as the companys for a "realignment" of employees.










InformationWeek U.S. IT Salary Survey 2008
Salaries for business technology professionals are falling. Here's what you need to know in order to make good hiring decisions and personal career choices. Download Today
 
ROLLING RIGHT ALONG
Follow key Network Computing Reviews from conception to completion. This Week: Holistic APM.



Network Computing Reports Emerging Enterprise Podcast Series: Secrets to Success








TechSearch


Microsite of the Week


Powerful Information at Your Fingertips



InformationWeek Business Technology Network
InformationWeekInformationWeek 500InformationWeek 500 ConferenceInformationWeek AnalyticsInformationWeek CIO
InformationWeek EventsInformationWeek ReportsInformationWeek MagazinebMightyByte and SwitchDark Reading
Digital LibraryIntelligent EnterpriseInternet EvolutionNetwork ComputingNo Jitter
space
Techweb Events Network
InteropVoiceConWeb 2.0 ExpoWeb 2.0 SummitEnterprise 2.0 ConferenceMobile Business ExpoSoftware ConferenceCSI - Computer Security Institute
Black HatGTECEnergy CampMashup CampStartup Camp
space
Light Reading Communications Network
Light ReadingLight Reading EuropeUnstrungLight Reading's Cable Digital NewsConstantinopleInternet Evolution
Heavy ReadingLight Reading Live!Light Reading InsiderEthernet ExpoOptical ExpoTeleco TVTower Technology Summit
space
Financial Technology Network
Advanced TradingBank Systems & TechnologyInsurance & TechnologyWall Street & TechnologyAccelerating Wall StreetBank Systems & Technology Executive SummitBuyside Trading SummitInsurance & Technology Executive Summit
space
Microsoft Technology Network
MSDN MagazineTechNetThe Architecture Journal
space
App Infrastructure   |   Messaging & Collaboration   |   Network & Systems Mgmt   |   Network Infrastructure   |   Security  |   Storage & Servers   |   Wireless   |   Enterprise Apps
About Us  |  Contact Us  |  Site Map  |  Technology Marketing Solutions  |   Briefing Centers
Copyright © 2008  United Business Media LLC  |  Privacy Statement  |  Terms of Service  |  Your California Privacy Rights