Home

Syllabus

Notes

Homework

Grades


A Recursive Makefile Example

Makefile example

Here are some example Makefiles that demonstrate a recursive use of make

These are from a utility called "lha" used to compress or expand files in lha format.

In the base directory, ./Makefile

 
 
# Makefile for LHa topdir
#              Mar. 2, 1992, written by Masaru Oki.
#              AUG. 22,1994, modified by Nobutaka Watazaki
#               Jun.  7,1999, modified by Tsugio Okamoto
 
 
#-----------------------------------------------------------------------
# CONFIGURATION
#       SWITCHES macro definitions ... see config.eng or config.jpn.
#-----------------------------------------------------------------------
 
SHELL=/bin/sh
MAKE = make
 
#CC                    = cc
CC                     = gcc
SWITCHES       = -DNEED_INCREMENTAL_INDICATOR \
 -DTMP_FILENAME_TEMPLATE="\"/tmp/lhXXXXXX\""
 
#MACHINE     = -DSYSTIME_HAS_NO_TM -DFTIME -DEUC
#MACHINE     = -DSYSTIME_HAS_NO_TM -DEUC -DHAVE_TM_ZONE -DSYSV_SYSTEM_DIR
MACHINE     = -DSYSTIME_HAS_NO_TM -DEUC -DSYSV_SYSTEM_DIR -DMKTIME
 
#OPTIMIZE      = -O2 -fstrength-reduce -fomit-frame-pointer
OPTIMIZE       = -O2 -DSUPPORT_LH7 -DMKSTEMP
 
BINDIR = /usr/local/bin
MANDIR = /usr/local/man
MANSECT = n
 
INSTALL = install
INSTALLBIN = -s -m 755
INSTALLMAN = -m 644
 
SUBDIRS = src man
 
O              = .o
 
# missing library objects.
#       memset$(O) lhdir$(O)
LIBRARYOBJS    = patmatch$(O)
 
MYMAKEFLAGS = 'BINDIR=$(BINDIR)' 'MANDIR=$(MANDIR)' 'MANSECT=$(MANSECT)'\
 'INSTALL=$(INSTALL)' 'INSTALLBIN=$(INSTALLBIN)' 'INSTALLMAN=$(INSTALLMAN)'\
 'CC=$(CC)' 'SWITCHES=$(SWITCHES)' 'O=$(O)' 'LIBRARYOBJS=$(LIBRARYOBJS)' \
 'OPTIMIZE=$(OPTIMIZE)' 'MACHINE=$(MACHINE)'
 
all:
        @for i in $(SUBDIRS); do \
        echo "make all in $$i..."; \
        (cd $$i; $(MAKE) $(MFLAGS) $(MYMAKEFLAGS) all); done
 
install:
        @for i in $(SUBDIRS); do \
        echo "Installing in $$i..."; \
        (cd $$i; $(MAKE) $(MFLAGS) $(MYMAKEFLAGS) install); done
 
clean:
        @for i in $(SUBDIRS); do \
        echo "Clearing in $$i..."; \
        (cd $$i; $(MAKE) $(MFLAGS) $(MYMAKEFLAGS) clean); done
 
moreclean:
        @for i in $(SUBDIRS); do \
        echo "Clearing in $$i..."; \
        (cd $$i; $(MAKE) $(MFLAGS) $(MYMAKEFLAGS) moreclean); done
 

./src/Makefile

 
 
# Makefile for LHarc UNIX Archiver Driver
#                                     Copyright(C) MCMLXXXIX  Yooichi.Tagawa
# V0.01  Alpha Version                               1989.05.28  Y.Tagawa
# V0.02  Alpha Version R2                            1989.05.29  Y.Tagawa
# V0.03  Release #3  Beta Version             1989.07.02  Y.Tagawa
# V0.03b Modified                                            1989.07.13  Y.Tagawa
# V1.00  Fixed                                               1989.09.19  Y.Tagawa
#
# for OSK
# V1.08                                                              1990.10.09  Sakura Tomozou
# V2.00 + lzhuf4/5                                            1990.10.26  
#
# LHa for UNIX
# V0.01  Alpha Version                               1991.10.17  Masaru Oki
# V0.02  Alpha Version Rel.2                  1991.11.26  Masaru Oki
# V0.03  Beta Version                                1991.12.03  Masaru Oki
# V0.04  Beta Version  Rel.2                  1992.01.17  Masaru Oki
# V0.05  Beta Version  Final                  1992.02.17  Masaru Oki
 
 
LHOBJS         = lharc$(O) lhadd$(O) lhlist$(O) lhext$(O) header$(O)
HUFOBJS        = append$(O) crcio$(O) dhuf$(O) extract$(O) huf$(O) \
                 larc$(O) maketbl$(O) maketree$(O) shuf$(O) slide$(O) \
                 util$(O)
 
OBJS           = $(LHOBJS) $(HUFOBJS) $(LIBRARYOBJS)
 
CFLAGS         = $(OPTIMIZE) $(SWITCHES) $(MACHINE)
 
all : lha
 
lha     : $(OBJS)
        $(CC) -o $@ $(OBJS) $(LDFLAGS) 
 
$(LHOBJS) append$(O) slide$(O) extract$(O) : lha.h lha_macro.h
 
$(HUFOBJS) : lha.h lha_macro.h
crcio$(O) extract$(O) slide$(O) : lha.h lha_macro.h
 
lhdir$(O) : lhdir.h
 
$(OBJS) : ../Makefile
 
clean:
        rm -f core lha $(OBJS)
 
moreclean:
        rm -f core  *.o lha.tar lha.tar.Z  *~ #*  *.orig
 
install:
        $(INSTALL) $(INSTALLBIN) lha $(BINDIR)/lha

./man/Makefile

 
 
# Makefile for LHa man directory
 
 
NROFF = nroff
#NROFF = jman
 
all:    lha.man
 
lha.man: lha.n
        $(NROFF) -man lha.n > lha.man
 
install:
        $(INSTALL) $(INSTALLMAN) lha.n $(MANDIR)/man$(MANSECT)/lha.$(MANSECT)
 
clean:
        rm -f  *~
 
moreclean:
        rm -f lha.man core  *~  *.orig
size=2 width="100%" align=center>