BSD 4_3_Reno release
[unix-history] / usr / src / share / mk / bsd.prog.mk
index daa821a..406f015 100644 (file)
+#      @(#)bsd.prog.mk 5.20 (Berkeley) 6/29/90
 
 
-MAKE=  pmake   # for now...
-CPP=   newcpp
+.if exists(${.CURDIR}/../Makefile.inc)
+.include "${.CURDIR}/../Makefile.inc"
+.endif
 
 
-# libraries used for dependency lines
-LIBUTIL=       /usr/lib/libutil.a
-LIBMATH=       /usr/lib/libm.a
-LIBKRB=                /usr/lib/libkrb.a
-LIBDES=                /usr/lib/libdes.a
-LIBCOMPAT=     /usr/lib/libcompat.a
+.SUFFIXES: .out .o .c .y .l .s .8 .7 .6 .5 .4 .3 .2 .1 .0
 
 
-# any specified manual pages -- if none have been specified at this point,
-# we make assumptions about what they are and what they're called.
-MANALL=        ${MAN1} ${MAN2} ${MAN3} ${MAN4} ${MAN5} ${MAN6} ${MAN7} ${MAN8}
+.8.0 .7.0 .6.0 .5.0 .4.0 .3.0 .2.0 .1.0:
+       nroff -mandoc -h ${.IMPSRC} > ${.TARGET}
 
 
-# user defines:
-#      SUBDIR -- the list of subdirectories to be processed
-#
-# if SUBDIR is set, we're in a makefile that processes subdirectories;
-# for all the standard targets, change to the subdirectory and make the
-# target.  If making one of the subdirectories, change to it and make
-# the target "all".  Machine dependent subdirectories take precedence
-# over standard subdirectories.
-.if defined(SUBDIR)
-all depend clean cleandir lint install tags:
-       @for entry in ${SUBDIR}; do
-               (echo "====> $$entry"
-               if test -d $${entry}.${MACHINE}; then
-                       cd $${entry}.${MACHINE}
-               else
-                       cd $${entry}
-               fi
-               ${MAKE} ${.TARGET})
-       done
+CFLAGS+=${COPTS}
+
+STRIP?=        -s
+
+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
 
 
-${SUBDIR}:
-       @if test -d ${.TARGET}.${MACHINE}; then
-               cd ${.TARGET}.${MACHINE}
-       else
-               cd ${.TARGET}
-       fi
-       ${MAKE} all
-
-.else  # !SUBDIR
-
-# user defines:
-#      SHAREDSTRINGS -- boolean variable, if sharing strings in objects.
-#
-# if SHAREDSTRINGS is defined, use XSTR to build objects.
-#
 .if defined(SHAREDSTRINGS)
 .if defined(SHAREDSTRINGS)
-.NOTPARALLEL:
-XSTR=  xstr
+CLEANFILES+=strings
 .c.o:
 .c.o:
-       ${CC} -E ${.INCLUDES} ${CFLAGS} ${.IMPSRC} | ${XSTR} -c -
-       @${CC} ${.INCLUDES} ${CFLAGS} -c x.c -o ${.TARGET}
+       ${CC} -E ${CFLAGS} ${.IMPSRC} | xstr -c -
+       @${CC} ${CFLAGS} -c x.c -o ${.TARGET}
        @rm -f x.c
 .endif
 
        @rm -f x.c
 .endif
 
-# the default target is all
-.MAIN: all
+.if defined(PROG)
+.if defined(SRCS)
 
 
-# user defines:
-#      PROGC   -- the name of a program composed of a single source module
-#      PROGO   -- the name of a program composed of several object modules
-#      SRCLIB  -- the list of libraries that the program depends on;
-#                 normally from the LIB* list at the top of this file.
-#      LDLIB   -- the list of libraries that the program loads, in the
-#                 format expected by the loader.
+OBJS+= ${SRCS:.c=.o}
 
 
-all: ${PROGC} ${PROGO}
+${PROG}: ${OBJS} ${LIBC} ${DPADD}
+       ${CC} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
 
 
-# if the program is composed of a single source module, that module is
-# C source with the same name as the program.  If no manual pages have
-# been defined, it's in section 1 with the same name as the program.
-.if defined(PROGC)
-SRCS=  ${PROGC}.c
+.else defined(PROG)
 
 
-.if !defined(MAN1) && !defined(MAN2) && !defined(MAN3) && !defined(MAN4) && !defined(MAN5) && !defined(MAN6) && !defined(MAN7) && !defined(MAN8)
-MAN1=  ${PROGC}.0
-.endif
+SRCS= ${PROG}.c
 
 
-${PROGC}: ${SRCS} ${LIBC} ${SRCLIB}
-       ${CC} ${CFLAGS} -o ${.TARGET} ${SRCS} ${LDLIB}
+${PROG}: ${SRCS} ${LIBC} ${DPADD}
+       ${CC} ${CFLAGS} -o ${.TARGET} ${.CURDIR}/${SRCS} ${LDADD}
 
 
-.depend: ${SRCS}
-       set -
-       ${CPP} -M ${CFLAGS:M-[ID]*} ${.INCLUDES} ${.ALLSRC} |
-               sed "s/^/${PROGC}: /" > ${DEPENDFILE}.new
-       mv ${DEPENDFILE}.new ${DEPENDFILE}
+MKDEP= -p
 
 
-.endif # PROGC
+.endif
 
 
-# if the program is composed of several object modules, the modules are
-# the list of sources with the .o's translated to .c's.  If no manual
-# pages have been defined, it's in section 1 with the same name as the
-# program.  Objects depend on their C source counterparts.
-.if defined(PROGO)
+.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}
+
+_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
 
 
-OBJS=  ${SRCS:.c=.o}
+.MAIN: all
+all: ${PROG} ${MANALL} _PROGSUBDIR
 
 
-.if !defined(MAN1) && !defined(MAN2) && !defined(MAN3) && !defined(MAN4) && !defined(MAN5) && !defined(MAN6) && !defined(MAN7) && !defined(MAN8)
-MAN1=  ${PROGO}.0
+.if !target(clean)
+clean: _PROGSUBDIR
+       rm -f a.out [Ee]rrs mklog core ${PROG} ${OBJS} ${CLEANFILES}
 .endif
 
 .endif
 
-${PROGO}: ${OBJS} ${LIBC} ${SRCLIB}
-       ${CC} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDLIB}
+.if !target(cleandir)
+cleandir: _PROGSUBDIR
+       rm -f a.out [Ee]rrs mklog core ${PROG} ${OBJS} ${CLEANFILES}
+       rm -f .depend ${.CURDIR}/tags ${MANALL}
+.endif
 
 
+# some of the rules involve .h sources, so remove them from mkdep line
+.if !target(depend)
+depend: .depend _PROGSUBDIR
 .depend: ${SRCS}
 .depend: ${SRCS}
-       set -
-       set ${OBJS}
-       rm -f ${DEPENDFILE}.new
-       for entry in ${.ALLSRC}; do
-               ${CPP} -M ${CFLAGS:M-[ID]*} ${.INCLUDES} $$entry |
-                       sed "s/^/$$1: /" >> ${DEPENDFILE}.new
-               shift
-       done
-       mv ${DEPENDFILE}.new ${DEPENDFILE}
-
-${OBJS}: ${.PREFIX}.c
-
-.endif # PROGO
-
-depend: .depend
-
-# user defines:
-#      CLEANFILES      -- list of files to be removed for the target clean;
-#                         used, for example, to specify .c's produced from
-#                         .y's.
-JUNKFILES=     a.out Errs errs mklog core
-clean:
-       rm -f ${PROGC} ${PROGO} ${OBJS} ${CLEANFILES} ${JUNKFILES}
-
-TAGSFILE=      tags
-cleandir: clean
-       rm -f ${MANALL} ${TAGSFILE} ${DEPENDFILE}
-
-LINTFLAGS=     -chapbx
-lint: ${SRCS}
-       lint ${LINTFLAGS} ${CFLAGS} ${.ALLSRC}
-
-tags: ${SRCS}
-       ctags ${.ALLSRC}
-
-# user defines:
-#      MDIR    -- default manual page installation directory
-#      MANMODE -- default manual page installation mode
-#      STRIP   -- default strip flag
-#      BINMODE -- default binary installation mode
-#      BINOWN  -- default binary owner
-#      BINGRP  -- default binary group
-MDIR?=         /usr/share/man/cat
-MANMODE?=      444
-STRIP?=                -s
-BINMODE?=      755
-BINOWN?=       bin
-BINGRP?=       bin
+.if defined(PROG)
+       mkdep ${MKDEP} ${CFLAGS:M-[ID]*} ${.ALLSRC:M*.c}
+.endif
+.endif
+
+.if !target(install)
+.if !target(beforeinstall)
+beforeinstall:
+.endif
+.if !target(afterinstall)
+afterinstall:
+.endif
 
 
-# install target -- creates manual pages, then installs the binaries,
-# manual pages, and manual page links.
-install: ${MANALL}
+realinstall: _PROGSUBDIR
+.if defined(PROG)
        install ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
        install ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
-           ${PROGC} ${PROGO} ${DESTDIR}${DIR}
-.if defined(MAN1)
-       install -c -o ${BINOWN} -g ${BINGRP} -m ${MANMODE} ${MAN1} \
-           ${DESTDIR}${MDIR}1
-.endif
-.if defined(MAN2)
-       install -c -o ${BINOWN} -g ${BINGRP} -m ${MANMODE} ${MAN2} \
-           ${DESTDIR}${MDIR}2
-.endif
-.if defined(MAN3)
-       install -c -o ${BINOWN} -g ${BINGRP} -m ${MANMODE} ${MAN3} \
-           ${DESTDIR}${MDIR}3
-.endif
-.if defined(MAN4)
-       install -c -o ${BINOWN} -g ${BINGRP} -m ${MANMODE} ${MAN4} \
-           ${DESTDIR}${MDIR}4
-.endif
-.if defined(MAN5)
-       install -c -o ${BINOWN} -g ${BINGRP} -m ${MANMODE} ${MAN5} \
-           ${DESTDIR}${MDIR}5
-.endif
-.if defined(MAN6)
-       install -c -o ${BINOWN} -g ${BINGRP} -m ${MANMODE} ${MAN6} \
-           ${DESTDIR}${MDIR}6
-.endif
-.if defined(MAN7)
-       install -c -o ${BINOWN} -g ${BINGRP} -m ${MANMODE} ${MAN7} \
-           ${DESTDIR}${MDIR}7
-.endif
-.if defined(MAN8)
-       install -c -o ${BINOWN} -g ${BINGRP} -m ${MANMODE} ${MAN8} \
-           ${DESTDIR}${MDIR}8
-.endif
-# user defines:
-#      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.
-#      MLINKS  -- list of manual page linkes of the form "link target
-#                 link target"; for example, "a.1 b.2 c.3 d.4" would
-#                 link ${MDIR}1/a.0 to ${MDIR}2/b.0 and ${MDIR}3/c.0
-#                 to ${MDIR}4/d.0.
-.if defined(LINKS)
-       @set ${LINKS}
-       @while :; do
-               if `test $$# -lt 2`; then
-                       break;
-               fi
-               t=$$1
-               shift
-               l=$$1
-               shift
-               echo $$l -\> $$t
-               rm -f $$t
-               ln ${DESTDIR}$$l ${DESTDIR}$$t
-       done
-.endif # LINKS
-.if defined(MLINKS)
-       @set ${MLINKS}
-       @while :; do
-               if `test $$# -lt 2`; then
-                       break;
-               fi
-               name=$$1
-               shift
-               dir=${MDIR}`expr $$name : '[^\.]*\.\(.*\)'`
-               t=${DESTDIR}$${dir}/`expr $$name : '\([^\.]*\)'`.0
-               name=$$1
-               shift
-               dir=${MDIR}`expr $$name : '[^\.]*\.\(.*\)'`
-               l=${DESTDIR}$${dir}/`expr $$name : '\([^\.]*\)'`.0
-               echo $$l -\> $$t
-               rm -f $$t
-               ln $$l $$t
-       done
-.endif # MLINKS
-.endif # SUBDIR
+           ${PROG} ${DESTDIR}${BINDIR}
+.endif
+.if defined(HIDEGAME)
+       (cd ${DESTDIR}/usr/games; rm -f ${PROG}; ln -s dm ${PROG}; \
+           chown games.bin ${PROG})
+.endif
+.if defined(LINKS) && !empty(LINKS)
+       @set ${LINKS}; \
+       while test $$# -ge 2; do \
+               l=${DESTDIR}$$1; \
+               shift; \
+               t=${DESTDIR}$$1; \
+               shift; \
+               echo $$t -\> $$l; \
+               rm -f $$t; \
+               ln $$l $$t; \
+       done; true
+.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
+
+.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