1#! /usr/local/gnu/bin/perl
2#
3#-----------------------------------------------------------------------
4#
5# purpose : to help create the spooles.a library from scratch
6#
7# the spooles.a library is a global library and contains all spooles
8# methods. (this is in contrast to local libraries that contain
9# methods for only one object, e.g., A2/src/A2.a)
10#
11# the spooles.a library is usually created once, by executing
12# "make global" in the spooles directory, which compiles each
13# and every source file in all the object/src directories.
14# (not quite true, just every src file that is found in
15# object/src/makefile, which is considered as gospel.)
16# the "make global" command goes into each object's src directory,
17# calls this perl script to create a makefile that will compile
18# each src file and load into the spooles.a library, and then
19# executes that makefile and removes it.
20#
21# for those systems that do not have perl installed, we have a
22# makeGlobalLib makefile in each object's src directory.
23# typing "make Global" in the spooles directory will use
24# this makefile. unfortunately, each object's /src/makefile
25# and /src/makeGlobalLib are separate and must be kept up to date
26# manually. (i.e., add another src file to /src/makefile and you
27# must add the same to /src/makeGlobalLib).
28#
29# this is my second perl script, so don't laugh,
30# just send me comments and suggestions.
31#
32# created -- 98dec16, cca
33#
34#-----------------------------------------------------------------------
35#
36#  open the makefile to extract out the src file names
37#
38$makefile = "makefile" ;
39open( MAKEFILE, $makefile ) or die "Cannot open $makefile" ;
40#
41#  read in each line, look for $(OBJ).a(srcname.o)
42#  put srcname into the @srcnames array
43#
44while ( $line = <MAKEFILE> ) {
45   chop($line) ;
46   if ( $line =~ /OBJ =/ ) {
47      ($first, $objname) = split /OBJ = /, $line
48   }
49   if ( $line =~ /\$\(OBJ\)\.a\(/ ) {
50      ($first, $second) = split /\$\(OBJ\)\.a\(/, $line ;
51      ($srcname, $remainder) = split /\.o\)/, $second ;
52      $srcname = $srcname . ".c" ;
53      push @srcnames, $srcname
54   }
55}
56#
57# now start printing the makefile to stdout
58#
59print "\ninclude ../../Make.inc" ;
60print "\n" ;
61print "\nOBJ = $objname" ;
62print "\n\nSRC = " ;
63foreach $src ( @srcnames ) {
64   $srcname = " \\\n     " . $src ;
65   print $srcname ;
66}
67print "\n\nOBJ_FILES = \$\{SRC:.c=.o\}" ;
68print "\n\n" ;
69print <<'EOF' ;
70.c.o :
71	$(PURIFY) $(CC) -c $(CFLAGS) $*.c -o $(OBJ)_$*.o
72
73../../spooles.a : ${OBJ_FILES}
74	$(AR) $(ARFLAGS) ../../spooles.a $(OBJ)_*.o
75	rm -f $(OBJ)_*.o
76	$(RANLIB) ../../spooles.a
77EOF
78