Received: (from majordom@localhost) by hyperreal.org (8.8.5/8.8.5) id FAA23212; Sun, 24 Aug 1997 05:21:59 -0700 (PDT) Received: from gate-isdn.ukweb.com (gate-isdn.ukweb.com [194.152.65.149]) by hyperreal.org (8.8.5/8.8.5) with SMTP id FAA23208 for ; Sun, 24 Aug 1997 05:21:55 -0700 (PDT) Received: from aardvark.ukweb.com [192.168.2.4] by gate-isdn.ukweb.com with smtp (Exim 1.61 #1) id 0x2bg7-0005zV-00; Sun, 24 Aug 1997 13:21:59 +0100 Date: Sun, 24 Aug 1997 13:21:46 +0100 (BST) From: Paul Sutton To: new-httpd@hyperreal.org Subject: Make libraries; fix dependencies Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: new-httpd-owner@apache.org Precedence: bulk Reply-To: new-httpd@apache.org Here is an updated version of my patch to fix the dependencies between the top level (src) Makefile and the object files in the sub dirs (core, os/*, modules/*). Currently src/Makefile knows the names of all the object files in core, os/* and modules/standard and makes httpd dependent on them. Doing a "make httpd" builds the object file *in the src directory*, which is wrong. This patch fixes this by building core, os/* and modules/standard object files into a library. src/Makefile only knows about the library files, and doesn't care about the individual object files. To rebuild the libraries when the object files change src/Makefile always does a make in os/*, core and modules/standard. (For modules/standard, read "any modules/* directory where Configure auto-creates a makefile). The advantages of this patch are (a) src/Makefile does not need to repeat information that only sub-directory makefiles should know, such as object file names (b) doing "make httpd" now works (c) the os specific directory (os/unix) can contain multiple object files since src/Makefile does not need to know about them (d) it is now easier to add additional subdirectories if necessary by adding them to the SUBDIRS macro (e) we can add additional recursive targets such as depend, distclean etc with rules such as "depend distclean clean :: ...." The disadvantages are (a) ordering of the .a files on the link line may be important (b) httpd always gets relinked on doing a make at the top level I think this is a useful clean up, fixes some problems with the current makefile, and reduces redundant information between src/Makefile and the lower level makefiles, so I give it +1. //pcs Index: Configure =================================================================== RCS file: /export/home/cvs/apachen/src/Configure,v retrieving revision 1.138 diff -u -r1.138 Configure --- Configure 1997/08/23 04:00:19 1.138 +++ Configure 1997/08/24 12:09:27 @@ -815,19 +815,46 @@ print "};"; \ }' -# Add the module targets to the Makefile +# figure out which module dir require use to autocreate a Makefile. +# for these dirs we must not list the object files from the AddModule +# lines individually since the auto-generated Makefile will create +# a library called libMODDIR.a for it (MODDIR is the module dir +# name). We create two variable here: +# +# AUTODIRS Space separated list of module directories, relative to +# src +# AUTOLIBS Space separated list of auto-generated library files + +for moddir in $MODDIRS +do + if [ -f modules/$moddir/Makefile.tmpl ] ; then + AUTODIRS="$AUTODIRS modules/$moddir" + AUTOLIBS="$AUTOLIBS modules/$moddir/lib$moddir.a" + fi +done -awk >>Makefile <$tmpfile '\ +# Add the module targets to the Makefile. Do not add inidividual object +# targets for auto-generated directories. +awk -v AUTODIRS="$AUTODIRS" >>Makefile <$tmpfile '\ + BEGIN { split ( AUTODIRS, tmp, / /); \ + for ( key in tmp ) { autodirs[tmp[key]] = 1; } } \ /^Module/ { modules[n++] = $3 } \ /^%Module/ { modules[n++] = $3 } \ - END { print "MODULES=\\"; \ + END { print "MODULES=\\"; \ for (i = 0; i < n; ++i) { \ - if (i < n-1) printf (" %s \\\n", modules[i]); \ - else printf (" %s\n", modules[i]); \ + split ( modules[i], pp, /\//); \ + dir = pp[1] "/" pp[2] ; \ + if ( dir in autodirs ) { continue; }\ + else printf (" %s\\\n", modules[i]); \ } \ - print "" \ }' +# Now add the auto-generated library targets +for lib in $AUTOLIBS; do + echo " $lib \\" >> Makefile +done +echo >> Makefile + #################################################################### # Continue building Makefile.config. # @@ -930,39 +957,43 @@ done ) >> modules/Makefile -for moddir in $MODDIRS ; do - if [ ! -f modules/$moddir/Makefile.tmpl ] ; then - continue - fi - echo "Creating Makefile in modules/$moddir" +for moddir in $AUTODIRS ; do + echo "Creating Makefile in $moddir" - cat Makefile.config > modules/$moddir/Makefile - awk >> modules/$moddir/Makefile < $tmpfile '\ + cat Makefile.config > $moddir/Makefile + basedir=`echo $moddir | sed 's|^[^/]*/||g'` + awk >> $moddir/Makefile < $tmpfile '\ BEGIN { printf "OBJS=" }\ - ($1 == "Module" && $3 ~ /^modules\/'$moddir'\//) { \ + ($1 == "Module" && $3 ~ /^modules\/'$basedir'\//) { \ split ($3, pp, "/"); \ printf "%s ", pp[3]; \ } \ END {printf "\n"}' - cat << 'EOF' >> modules/$moddir/Makefile + echo "LIB=lib$basedir.a" >> $moddir/Makefile + cat << 'EOF' >> $moddir/Makefile CFLAGS=$(OPTIM) $(CFLAGS1) $(EXTRA_CFLAGS) LIBS=$(EXTRA_LIBS) $(LIBS1) INCLUDES=$(INCLUDES1) $(EXTRA_INCLUDES) LDFLAGS=$(LDFLAGS1) $(EXTRA_LDFLAGS) INCDIR=../../main -all: $(OBJS) +all: $(LIB) + +$(LIB): $(OBJS) + rm -f $@ + ar crv $@ $(OBJS) + $(RANLIB) $@ .c.o: $(CC) -c $(INCLUDES) $(CFLAGS) $(SPACER) $< clean: - rm -f $(OBJS) + rm -f $(OBJS) $(LIB) $(OBJS): Makefile EOF -cat >> modules/$moddir/Makefile < modules/$moddir/Makefile.tmpl +cat >> $moddir/Makefile < $moddir/Makefile.tmpl done Index: Makefile.tmpl =================================================================== RCS file: /export/home/cvs/apachen/src/Makefile.tmpl,v retrieving revision 1.59 diff -u -r1.59 Makefile.tmpl --- Makefile.tmpl 1997/08/24 02:51:33 1.59 +++ Makefile.tmpl 1997/08/24 12:09:28 @@ -9,20 +9,17 @@ LDFLAGS=$(LDFLAGS1) $(EXTRA_LDFLAGS) OBJS= \ - main/alloc.o main/http_main.o main/http_core.o \ - main/http_config.o main/http_request.o main/http_log.o \ - main/http_protocol.o main/rfc1413.o main/util.o \ - main/util_script.o main/buff.o main/md5c.o \ - main/util_md5.o main/explain.o main/http_bprintf.o \ - main/util_date.o main/util_snprintf.o main/fnmatch.o \ modules.o \ - $(OSOBJ) \ - $(MODULES) + $(MODULES) \ + $(OSDIR)/libos.a \ + main/libmain.a + +SUBDIRS=main $(OSDIR) modules .c.o: $(CC) -c $(INCLUDES) $(CFLAGS) $(SPACER) $< -all: @@Configuration@@ os-dir core-dir modules/last-built httpd +all: @@Configuration@@ httpd @@Configuration@@: Configuration.tmpl @echo "@@Configuration@@ older than Configuration.tmpl, or doesn't exist." @@ -31,36 +28,30 @@ @echo "If not, you will at least have to touch @@Configuration@@." @false -httpd: $(REGLIB) $(OBJS) +httpd: $(REGLIB) modules.o subdirs rm -f buildmark.c echo 'const char SERVER_BUILT[] = "'`/bin/date`'";' > buildmark.c $(CC) -c buildmark.c $(CC) $(LDFLAGS) -o httpd buildmark.o $(OBJS) $(REGLIB) $(LIBS) -regex/libregex.a: - (cd regex; $(MAKE) lib CC='$(CC)' AUX_CFLAGS='$(CFLAGS)' RANLIB='$(RANLIB)') +subdirs: + for i in $(SUBDIRS); do \ + ( cd $$i; $(MAKE) CC='$(CC)' AUX_CFLAGS='$(CFLAGS)' RANLIB='$(RANLIB)') \ + done -modules/last-built: - (cd modules; \ - $(MAKE) CC='$(CC)' AUX_CFLAGS='$(CFLAGS)' RANLIB='$(RANLIB)') +$(REGLIB): + (cd regex; $(MAKE) lib CC='$(CC)' AUX_CFLAGS='$(CFLAGS)' RANLIB='$(RANLIB)') support: support-dir support-dir: cd support; $(MAKE) CC='$(CC)' AUX_CFLAGS='$(CFLAGS)' RANLIB='$(RANLIB)' -core-dir: - cd main; $(MAKE) CC='$(CC)' AUX_CFLAGS='$(CFLAGS)' RANLIB='$(RANLIB)' - -os-dir: - cd $(OSDIR); $(MAKE) CC='$(CC)' AUX_CFLAGS='$(CFLAGS)' RANLIB='$(RANLIB)' - clean: rm -f httpd *.o $(OBJS) - cd main; $(MAKE) clean - cd regex; $(MAKE) clean - cd modules; $(MAKE) clean - cd support; $(MAKE) clean + for i in $(SUBDIRS) regex; do \ + ( cd $$i; $(MAKE) $@ ) \ + done dist.tar: # Assure a semi-sensible configuration going out... Index: main/Makefile.tmpl =================================================================== RCS file: /export/home/cvs/apachen/src/main/Makefile.tmpl,v retrieving revision 1.2 diff -u -r1.2 Makefile.tmpl --- Makefile.tmpl 1997/08/13 09:28:46 1.2 +++ Makefile.tmpl 1997/08/24 12:09:29 @@ -16,10 +16,17 @@ .c.o: $(CC) -c $(INCLUDES) $(CFLAGS) $(SPACER) $< -all: $(OBJS) +LIB= libmain.a + +all: $(LIB) + +$(LIB): $(OBJS) + rm -f $@ + ar crv $@ $(OBJS) + $(RANLIB) $@ clean: - rm -f $(OBJS) + rm -f $(OBJS) $(LIB) # Work around broken compilers http_bprintf.o: http_bprintf.c Index: os/unix/Makefile.tmpl =================================================================== RCS file: /export/home/cvs/apachen/src/os/unix/Makefile.tmpl,v retrieving revision 1.2 diff -u -r1.2 Makefile.tmpl --- Makefile.tmpl 1997/08/23 22:25:26 1.2 +++ Makefile.tmpl 1997/08/24 12:09:30 @@ -6,13 +6,22 @@ OBJS= os.o -all: $(OBJS) +LIB= libos.a + +all: $(LIB) + +$(LIB): $(OBJS) + rm -f $@ + ar crv $@ $(OBJS) + $(RANLIB) $@ .c.o: $(CC) -c $(INCLUDES) $(CFLAGS) $(SPACER) $< clean: rm -f $(OBJS) + +$(OBJS): Makefile # DO NOT REMOVE os.o: os.c