make: Complex Makefile
1
1 Appendix C Complex Makefile Example
1 ***********************************
1
1 Here is the makefile for the GNU 'tar' program. This is a moderately
1 complex makefile. The first line uses a '#!' setting to allow the
1 makefile to be executed directly.
1
1 Because it is the first target, the default goal is 'all'. An
1 interesting feature of this makefile is that 'testpad.h' is a source
1 file automatically created by the 'testpad' program, itself compiled
1 from 'testpad.c'.
1
1 If you type 'make' or 'make all', then 'make' creates the 'tar'
1 executable, the 'rmt' daemon that provides remote tape access, and the
1 'tar.info' Info file.
1
1 If you type 'make install', then 'make' not only creates 'tar',
1 'rmt', and 'tar.info', but also installs them.
1
1 If you type 'make clean', then 'make' removes the '.o' files, and the
1 'tar', 'rmt', 'testpad', 'testpad.h', and 'core' files.
1
1 If you type 'make distclean', then 'make' not only removes the same
1 files as does 'make clean' but also the 'TAGS', 'Makefile', and
1 'config.status' files. (Although it is not evident, this makefile (and
1 'config.status') is generated by the user with the 'configure' program,
1 which is provided in the 'tar' distribution, but is not shown here.)
1
1 If you type 'make realclean', then 'make' removes the same files as
1 does 'make distclean' and also removes the Info files generated from
1 'tar.texinfo'.
1
1 In addition, there are targets 'shar' and 'dist' that create
1 distribution kits.
1
1 #!/usr/bin/make -f
1 # Generated automatically from Makefile.in by configure.
1 # Un*x Makefile for GNU tar program.
1 # Copyright (C) 1991 Free Software Foundation, Inc.
1
1 # This program is free software; you can redistribute
1 # it and/or modify it under the terms of the GNU
1 # General Public License ...
1 ...
1 ...
1
1 SHELL = /bin/sh
1
1 #### Start of system configuration section. ####
1
1 srcdir = .
1
1 # If you use gcc, you should either run the
1 # fixincludes script that comes with it or else use
1 # gcc with the -traditional option. Otherwise ioctl
1 # calls will be compiled incorrectly on some systems.
1 CC = gcc -O
1 YACC = bison -y
1 INSTALL = /usr/local/bin/install -c
1 INSTALLDATA = /usr/local/bin/install -c -m 644
1
1 # Things you might add to DEFS:
1 # -DSTDC_HEADERS If you have ANSI C headers and
1 # libraries.
1 # -DPOSIX If you have POSIX.1 headers and
1 # libraries.
1 # -DBSD42 If you have sys/dir.h (unless
1 # you use -DPOSIX), sys/file.h,
1 # and st_blocks in `struct stat'.
1 # -DUSG If you have System V/ANSI C
1 # string and memory functions
1 # and headers, sys/sysmacros.h,
1 # fcntl.h, getcwd, no valloc,
1 # and ndir.h (unless
1 # you use -DDIRENT).
1 # -DNO_MEMORY_H If USG or STDC_HEADERS but do not
1 # include memory.h.
1 # -DDIRENT If USG and you have dirent.h
1 # instead of ndir.h.
1 # -DSIGTYPE=int If your signal handlers
1 # return int, not void.
1 # -DNO_MTIO If you lack sys/mtio.h
1 # (magtape ioctls).
1 # -DNO_REMOTE If you do not have a remote shell
1 # or rexec.
1 # -DUSE_REXEC To use rexec for remote tape
1 # operations instead of
1 # forking rsh or remsh.
1 # -DVPRINTF_MISSING If you lack vprintf function
1 # (but have _doprnt).
1 # -DDOPRNT_MISSING If you lack _doprnt function.
1 # Also need to define
1 # -DVPRINTF_MISSING.
1 # -DFTIME_MISSING If you lack ftime system call.
1 # -DSTRSTR_MISSING If you lack strstr function.
1 # -DVALLOC_MISSING If you lack valloc function.
1 # -DMKDIR_MISSING If you lack mkdir and
1 # rmdir system calls.
1 # -DRENAME_MISSING If you lack rename system call.
1 # -DFTRUNCATE_MISSING If you lack ftruncate
1 # system call.
1 # -DV7 On Version 7 Unix (not
1 # tested in a long time).
1 # -DEMUL_OPEN3 If you lack a 3-argument version
1 # of open, and want to emulate it
1 # with system calls you do have.
1 # -DNO_OPEN3 If you lack the 3-argument open
1 # and want to disable the tar -k
1 # option instead of emulating open.
1 # -DXENIX If you have sys/inode.h
1 # and need it 94 to be included.
1
1 DEFS = -DSIGTYPE=int -DDIRENT -DSTRSTR_MISSING \
1 -DVPRINTF_MISSING -DBSD42
1 # Set this to rtapelib.o unless you defined NO_REMOTE,
1 # in which case make it empty.
1 RTAPELIB = rtapelib.o
1 LIBS =
1 DEF_AR_FILE = /dev/rmt8
1 DEFBLOCKING = 20
1
1 CDEBUG = -g
1 CFLAGS = $(CDEBUG) -I. -I$(srcdir) $(DEFS) \
1 -DDEF_AR_FILE=\"$(DEF_AR_FILE)\" \
1 -DDEFBLOCKING=$(DEFBLOCKING)
1 LDFLAGS = -g
1
1 prefix = /usr/local
1 # Prefix for each installed program,
1 # normally empty or `g'.
1 binprefix =
1
1 # The directory to install tar in.
1 bindir = $(prefix)/bin
1
1 # The directory to install the info files in.
1 infodir = $(prefix)/info
1
1 #### End of system configuration section. ####
1
1 SRCS_C = tar.c create.c extract.c buffer.c \
1 getoldopt.c update.c gnu.c mangle.c \
1 version.c list.c names.c diffarch.c \
1 port.c wildmat.c getopt.c getopt1.c \
1 regex.c
1 SRCS_Y = getdate.y
1 SRCS = $(SRCS_C) $(SRCS_Y)
1 OBJS = $(SRCS_C:.c=.o) $(SRCS_Y:.y=.o) $(RTAPELIB)
1 AUX = README COPYING ChangeLog Makefile.in \
1 makefile.pc configure configure.in \
1 tar.texinfo tar.info* texinfo.tex \
1 tar.h port.h open3.h getopt.h regex.h \
1 rmt.h rmt.c rtapelib.c alloca.c \
1 msd_dir.h msd_dir.c tcexparg.c \
1 level-0 level-1 backup-specs testpad.c
1
1 .PHONY: all
1 all: tar rmt tar.info
1
1 tar: $(OBJS)
1 $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
1
1 rmt: rmt.c
1 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ rmt.c
1
1 tar.info: tar.texinfo
1 makeinfo tar.texinfo
1
1 .PHONY: install
1 install: all
1 $(INSTALL) tar $(bindir)/$(binprefix)tar
1 -test ! -f rmt || $(INSTALL) rmt /etc/rmt
1 $(INSTALLDATA) $(srcdir)/tar.info* $(infodir)
1
1 $(OBJS): tar.h port.h testpad.h
1 regex.o buffer.o tar.o: regex.h
1 # getdate.y has 8 shift/reduce conflicts.
1
1 testpad.h: testpad
1 ./testpad
1
1 testpad: testpad.o
1 $(CC) -o $@ testpad.o
1
1 TAGS: $(SRCS)
1 etags $(SRCS)
1
1 .PHONY: clean
1 clean:
1 rm -f *.o tar rmt testpad testpad.h core
1
1 .PHONY: distclean
1 distclean: clean
1 rm -f TAGS Makefile config.status
1
1 .PHONY: realclean
1 realclean: distclean
1 rm -f tar.info*
1
1 .PHONY: shar
1 shar: $(SRCS) $(AUX)
1 shar $(SRCS) $(AUX) | compress \
1 > tar-`sed -e '/version_string/!d' \
1 -e 's/[^0-9.]*\([0-9.]*\).*/\1/' \
1 -e q
1 version.c`.shar.Z
1
1 .PHONY: dist
1 dist: $(SRCS) $(AUX)
1 echo tar-`sed \
1 -e '/version_string/!d' \
1 -e 's/[^0-9.]*\([0-9.]*\).*/\1/' \
1 -e q
1 version.c` > .fname
1 -rm -rf `cat .fname`
1 mkdir `cat .fname`
1 ln $(SRCS) $(AUX) `cat .fname`
1 tar chZf `cat .fname`.tar.Z `cat .fname`
1 -rm -rf `cat .fname` .fname
1
1 tar.zoo: $(SRCS) $(AUX)
1 -rm -rf tmp.dir
1 -mkdir tmp.dir
1 -rm tar.zoo
1 for X in $(SRCS) $(AUX) ; do \
1 echo $$X ; \
1 sed 's/$$/^M/' $$X \
1 > tmp.dir/$$X ; done
1 cd tmp.dir ; zoo aM ../tar.zoo *
1 -rm -rf tmp.dir
1