BSD 4_3_Reno release
[unix-history] / usr / src / share / mk / bsd.prog.mk
index 1657bb0..406f015 100644 (file)
-# A Makefile for the BSD source tree.
-#
-#      @(#)bsd.prog.mk 5.5 (Berkeley) %G%
-#
-
-# user defines:
-#      BINDIR, BINGRP, BINMODE, BINOWN
-#              binary target directory, group, mode, owner
-#      CLEANFILES
-#              list of files to be removed for the target clean; used,
-#              for example, to specify .c's produced from .y's.
-#      LDLIB   the list of libraries that the program loads, in the format
-#              expected by the loader.
-#      LINKS   list of binary links of the form "link target link target";
-#              for example, "/bin/[ /usr/bin/test" would link /bin/[ to
-#              /usr/bin/test"; not particularly labor saving, but prevents
-#              needing your own install target.
-#      MANDIR, MANMODE
-#              manual page installation directory, mode
-#      MLINKS  list of man page links of the form "link target link target",
-#              with some trickiness so the suffix specifies the directory to
-#              use.  For example, "a.1 b.2 c.3 d.4" would link ${MANDIR}1/a.0
-#              to ${MANDIR}2/b.0 and ${MANDIR}3/c.0 to ${MANDIR}4/d.0.
-#      PROG    program name
-#      SHAREDSTRINGS
-#              objects share strings using ${XSTR}
-#      SRCS    list of .c sources if the program has multiple files.
-#      SRCLIB  the list of libraries that the program depends on; normally
-#              from the LIB* list in this file.
-#      STRIP   strip flag
-#
-# user macros:
-#      STDALL  standard all target
-#      STDCLEAN
-#              standard clean target
-#      STDCLEANDIR
-#              standard cleandir target
-#      STDDEPEND
-#              standard depend target
-#      STDLINT
-#              standard lint target
-#      STDINSTALL
-#              standard install target
-#      STDTAGS standard tags target
-
-# permit a hierarchy of Makefile include files
-.if exists(../Make.include)
-.include "../Make.include"
-.endif
-
-# name of the dependency file
-DEPENDFILE=    .depend
-
-# standard libraries
-LIBC=          /lib/libc.a
-LIBCOMPAT=     /usr/lib/libcompat.a
-LIBDES=                /usr/lib/libdes.a
-LIBKRB=                /usr/lib/libkrb.a
-LIBMATH=       /usr/lib/libm.a
-LIBUTIL=       /usr/lib/libutil.a
-
-# read-only version of standard .c.o rule
-READONLY: .USE
-       ${CC} ${CFLAGS} -c -R ${.IMPSRC}
-
-# if the user defines SHAREDSTRINGS, they want objects to share strings.
-# Turn off parallel makes (the strings file is single threaded) and
-# rewrite the .c.o rule to use XSTR to build the objects.
-.if defined(SHAREDSTRINGS)
-.NOTPARALLEL:
-XSTR=/usr/bin/xstr
-.c.o:
-       ${CC} -E ${CFLAGS} ${.IMPSRC} | ${XSTR} -c -
-       @${CC} ${CFLAGS} -c x.c -o ${.TARGET}
-       @rm -f x.c
-.endif
-
-# the default target.
-.MAIN: all
-
-# manual pages -- if the Makefile doesn't specify one, assume that they're
-# named in a standard way, i.e. it's in section 1 with the same name as the
-# program.
-MANALL=        ${MAN1} ${MAN2} ${MAN3} ${MAN4} ${MAN5} ${MAN6} ${MAN7} ${MAN8}
+#      @(#)bsd.prog.mk 5.20 (Berkeley) 6/29/90
 
 
-# In the BSD source tree, each program Makefile should specify PROG, the
-# name of the program.
-all: ${PROG}
-
-.if defined(SRCS)
-
-# if the program is composed of several object modules, the modules are
-# the list of sources with the .o's translated to .c's.
-OBJS=  ${SRCS:.c=.o}
-
-.if !defined(MAN1) && !defined(MAN2) && !defined(MAN3) && !defined(MAN4) && \
-       !defined(MAN5) && !defined(MAN6) && !defined(MAN7) && !defined(MAN8)
-MAN1=  ${PROG}.0
+.if exists(${.CURDIR}/../Makefile.inc)
+.include "${.CURDIR}/../Makefile.inc"
 .endif
 
 .endif
 
-${PROG}: ${OBJS} ${LIBC} ${SRCLIB}
-       ${CC} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDLIB}
+.SUFFIXES: .out .o .c .y .l .s .8 .7 .6 .5 .4 .3 .2 .1 .0
 
 
-.depend: ${SRCS}
-       @set ${OBJS}
-       @for entry in ${.ALLSRC}; do
-               echo "$$1:" \
-                   `${CPP} -M ${CFLAGS:M-[ID]*} ${.INCLUDES} $$entry`
-               shift
-       done > ${DEPENDFILE}
+.8.0 .7.0 .6.0 .5.0 .4.0 .3.0 .2.0 .1.0:
+       nroff -mandoc -h ${.IMPSRC} > ${.TARGET}
 
 
-${OBJS}: ${.PREFIX}.c
+CFLAGS+=${COPTS}
 
 
-.else
+STRIP?=        -s
 
 
-SRCS= ${PROG}.c
+BINGRP?=       bin
+BINOWN?=       bin
+BINMODE?=      555
+
+LIBC?=         /usr/lib/libc.a
+LIBCOMPAT?=    /usr/lib/libcompat.a
+LIBCURSES?=    /usr/lib/libcurses.a
+LIBDBM?=       /usr/lib/libdbm.a
+LIBDES?=       /usr/lib/libdes.a
+LIBL?=         /usr/lib/libl.a
+LIBKDB?=       /usr/lib/libkdb.a
+LIBKRB?=       /usr/lib/libkrb.a
+LIBM?=         /usr/lib/libm.a
+LIBMP?=                /usr/lib/libmp.a
+LIBPC?=                /usr/lib/libpc.a
+LIBPLOT?=      /usr/lib/libplot.a
+LIBRESOLV?=    /usr/lib/libresolv.a
+LIBRPC?=       /usr/lib/sunrpc.a
+LIBTERM?=      /usr/lib/libterm.a
+LIBUTIL?=      /usr/lib/libutil.a
 
 
-.if !defined(MAN1) && !defined(MAN2) && !defined(MAN3) && !defined(MAN4) && \
-       !defined(MAN5) && !defined(MAN6) && !defined(MAN7) && !defined(MAN8)
-MAN1=  ${PROG}.0
+.if defined(SHAREDSTRINGS)
+CLEANFILES+=strings
+.c.o:
+       ${CC} -E ${CFLAGS} ${.IMPSRC} | xstr -c -
+       @${CC} ${CFLAGS} -c x.c -o ${.TARGET}
+       @rm -f x.c
 .endif
 
 .endif
 
-${PROG}: ${SRCS} ${LIBC} ${SRCLIB}
-       ${CC} ${CFLAGS} -o ${.TARGET} ${SRCS} ${LDLIB}
-
-.depend: ${SRCS}
-       echo "${PROG}:" \
-           `${CPP} -M ${CFLAGS:M-[ID]*} ${.INCLUDES} ${.ALLSRC}` \
-                   > ${DEPENDFILE}
-
-.endif # defined(SRCS)
+.if defined(PROG)
+.if defined(SRCS)
 
 
-# standard targets
-depend: .depend
+OBJS+= ${SRCS:.c=.o}
 
 
-STDCLEAN: .USE
-       rm -f a.out Errs errs mklog core ${CLEANFILES} ${PROG} ${OBJS}
+${PROG}: ${OBJS} ${LIBC} ${DPADD}
+       ${CC} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
 
 
-clean: STDCLEAN
+.else defined(PROG)
 
 
-STDCLEANDIR: .USE
-       rm -f ${MANALL} ${TAGSFILE} ${DEPENDFILE}
+SRCS= ${PROG}.c
 
 
-cleandir: clean STDCLEANDIR
+${PROG}: ${SRCS} ${LIBC} ${DPADD}
+       ${CC} ${CFLAGS} -o ${.TARGET} ${.CURDIR}/${SRCS} ${LDADD}
 
 
-LINTFLAGS=-chapbx
-STDLINT: .USE
-       lint ${LINTFLAGS} ${CFLAGS} ${.ALLSRC}
+MKDEP= -p
 
 
-lint: ${SRCS} STDLINT
+.endif
 
 
-TAGSFILE=tags
-STDTAGS: .USE
-       ctags ${.ALLSRC}
+.if    !defined(MAN1) && !defined(MAN2) && !defined(MAN3) && \
+       !defined(MAN4) && !defined(MAN5) && !defined(MAN6) && \
+       !defined(MAN7) && !defined(MAN8) && !defined(NOMAN)
+MAN1=  ${PROG}.0
+.endif
+.endif
+MANALL=        ${MAN1} ${MAN2} ${MAN3} ${MAN4} ${MAN5} ${MAN6} ${MAN7} ${MAN8}
 
 
-tags: ${SRCS} STDTAGS
+_PROGSUBDIR: .USE
+.if defined(SUBDIR) && !empty(SUBDIR)
+       @for entry in ${SUBDIR}; do \
+               (echo "===> $$entry"; \
+               if test -d ${.CURDIR}/$${entry}.${MACHINE}; then \
+                       cd ${.CURDIR}/$${entry}.${MACHINE}; \
+               else \
+                       cd ${.CURDIR}/$${entry}; \
+               fi; \
+               ${MAKE} ${.TARGET:S/realinstall/install/:S/.depend/depend/}) \
+       done
+.endif
 
 
-MANDIR?=       /usr/share/man/cat
-MANMODE?=      444
-STRIP?=                -s
-BINMODE?=      755
-BINOWN?=       bin
-BINGRP?=       bin
+.MAIN: all
+all: ${PROG} ${MANALL} _PROGSUBDIR
 
 
-# install target -- creates manual pages, then installs the binaries,
-# links, manual pages, and manual page links.
-STDINSTALL: .USE
-       install ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
-           ${PROG} ${DESTDIR}${BINDIR}
-.if defined(MAN1)
-       install -c -o ${BINOWN} -g ${BINGRP} -m ${MANMODE} ${MAN1} \
-           ${DESTDIR}${MANDIR}1
+.if !target(clean)
+clean: _PROGSUBDIR
+       rm -f a.out [Ee]rrs mklog core ${PROG} ${OBJS} ${CLEANFILES}
 .endif
 .endif
-.if defined(MAN2)
-       install -c -o ${BINOWN} -g ${BINGRP} -m ${MANMODE} ${MAN2} \
-           ${DESTDIR}${MANDIR}2
+
+.if !target(cleandir)
+cleandir: _PROGSUBDIR
+       rm -f a.out [Ee]rrs mklog core ${PROG} ${OBJS} ${CLEANFILES}
+       rm -f .depend ${.CURDIR}/tags ${MANALL}
 .endif
 .endif
-.if defined(MAN3)
-       install -c -o ${BINOWN} -g ${BINGRP} -m ${MANMODE} ${MAN3} \
-           ${DESTDIR}${MANDIR}3
+
+# some of the rules involve .h sources, so remove them from mkdep line
+.if !target(depend)
+depend: .depend _PROGSUBDIR
+.depend: ${SRCS}
+.if defined(PROG)
+       mkdep ${MKDEP} ${CFLAGS:M-[ID]*} ${.ALLSRC:M*.c}
 .endif
 .endif
-.if defined(MAN4)
-       install -c -o ${BINOWN} -g ${BINGRP} -m ${MANMODE} ${MAN4} \
-           ${DESTDIR}${MANDIR}4
 .endif
 .endif
-.if defined(MAN5)
-       install -c -o ${BINOWN} -g ${BINGRP} -m ${MANMODE} ${MAN5} \
-           ${DESTDIR}${MANDIR}5
+
+.if !target(install)
+.if !target(beforeinstall)
+beforeinstall:
 .endif
 .endif
-.if defined(MAN6)
-       install -c -o ${BINOWN} -g ${BINGRP} -m ${MANMODE} ${MAN6} \
-           ${DESTDIR}${MANDIR}6
+.if !target(afterinstall)
+afterinstall:
 .endif
 .endif
-.if defined(MAN7)
-       install -c -o ${BINOWN} -g ${BINGRP} -m ${MANMODE} ${MAN7} \
-           ${DESTDIR}${MANDIR}7
+
+realinstall: _PROGSUBDIR
+.if defined(PROG)
+       install ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
+           ${PROG} ${DESTDIR}${BINDIR}
 .endif
 .endif
-.if defined(MAN8)
-       install -c -o ${BINOWN} -g ${BINGRP} -m ${MANMODE} ${MAN8} \
-           ${DESTDIR}${MANDIR}8
+.if defined(HIDEGAME)
+       (cd ${DESTDIR}/usr/games; rm -f ${PROG}; ln -s dm ${PROG}; \
+           chown games.bin ${PROG})
 .endif
 .endif
-.if defined(LINKS)
+.if defined(LINKS) && !empty(LINKS)
        @set ${LINKS}; \
        while test $$# -ge 2; do \
        @set ${LINKS}; \
        while test $$# -ge 2; do \
-               t=$$1; \
+               l=${DESTDIR}$$1; \
                shift; \
                shift; \
-               l=$$1; \
+               t=${DESTDIR}$$1; \
                shift; \
                shift; \
-               echo $$l -\> $$t; \
-               rm -f $$t; \
-               ln ${DESTDIR}$$l ${DESTDIR}$$t; \
-       done; true
-.endif # LINKS
-.if defined(MLINKS)
-       @set ${MLINKS}; \
-       while test $$# -ge 2; do \
-               name=$$1; \
-               shift; \
-               dir=${MANDIR}`expr $$name : '[^\.]*\.\(.*\)'`; \
-               t=${DESTDIR}$${dir}/`expr $$name : '\([^\.]*\)'`.0; \
-               name=$$1; \
-               shift; \
-               dir=${MANDIR}`expr $$name : '[^\.]*\.\(.*\)'`; \
-               l=${DESTDIR}$${dir}/`expr $$name : '\([^\.]*\)'`.0; \
-               echo $$l -\> $$t; \
+               echo $$t -\> $$l; \
                rm -f $$t; \
                ln $$l $$t; \
        done; true
                rm -f $$t; \
                ln $$l $$t; \
        done; true
-.endif # MLINKS
+.endif
+
+install: maninstall
+maninstall: afterinstall
+afterinstall: realinstall
+realinstall: beforeinstall
+.endif
+
+.if !target(lint)
+lint: ${SRCS} _PROGSUBDIR
+.if defined(PROG)
+       @${LINT} ${LINTFLAGS} ${CFLAGS} ${.ALLSRC} | more 2>&1
+.endif
+.endif
 
 
-install: ${MANALL} STDINSTALL
+.if !target(obj)
+.if defined(NOOBJ)
+obj: _PROGSUBDIR
+.else
+obj: _PROGSUBDIR
+       @cd ${.CURDIR}; rm -rf obj; \
+       here=`pwd`; dest=/usr/obj/`echo $$here | sed 's,/usr/src/,,'`; \
+       echo "$$here -> $$dest"; ln -s $$dest obj
+.endif
+.endif
+
+.if !target(tags)
+tags: ${SRCS} _PROGSUBDIR
+.if defined(PROG)
+       -cd ${.CURDIR}; ctags -f /dev/stdout ${.ALLSRC} | \
+           sed "s;\${.CURDIR}/;;" > tags
+.endif
+.endif
+
+.if !defined(NOMAN)
+.include <bsd.man.mk>
+.endif