Home | History | Annotate | Line # | Download | only in mk
bsd.prog.mk revision 1.17
      1 #	@(#)bsd.prog.mk	5.26 (Berkeley) 6/25/91
      2 
      3 .if exists(${.CURDIR}/../Makefile.inc)
      4 .include "${.CURDIR}/../Makefile.inc"
      5 .endif
      6 
      7 .SUFFIXES: .out .o .c .y .l .s .8 .7 .6 .5 .4 .3 .2 .1 .0
      8 
      9 .8.0 .7.0 .6.0 .5.0 .4.0 .3.0 .2.0 .1.0:
     10 	nroff -mandoc ${.IMPSRC} > ${.TARGET}
     11 
     12 CFLAGS+=${COPTS}
     13 
     14 STRIP?=	-s
     15 
     16 BINGRP?=	bin
     17 BINOWN?=	bin
     18 BINMODE?=	555
     19 
     20 LIBCRT0?=	/usr/lib/crt0.o
     21 LIBC?=		/usr/lib/libc.a
     22 LIBCOMPAT?=	/usr/lib/libcompat.a
     23 .ifndef EXPORTABLE_SYSTEM
     24 LIBCRYPT?=	/usr/lib/libcrypt.a
     25 .endif
     26 LIBCURSES?=	/usr/lib/libcurses.a
     27 LIBDBM?=	/usr/lib/libdbm.a
     28 LIBDES?=	/usr/lib/libdes.a
     29 LIBL?=		/usr/lib/libl.a
     30 LIBKDB?=	/usr/lib/libkdb.a
     31 LIBKRB?=	/usr/lib/libkrb.a
     32 LIBM?=		/usr/lib/libm.a
     33 LIBMP?=		/usr/lib/libmp.a
     34 LIBPC?=		/usr/lib/libpc.a
     35 LIBPLOT?=	/usr/lib/libplot.a
     36 LIBRESOLV?=	/usr/lib/libresolv.a
     37 LIBRPC?=	/usr/lib/librpc.a
     38 LIBRPCSVC?=	/usr/lib/librpcsvc.a
     39 LIBTERM?=	/usr/lib/libterm.a
     40 LIBUTIL?=	/usr/lib/libutil.a
     41 
     42 .if defined(SHAREDSTRINGS)
     43 CLEANFILES+=strings
     44 .c.o:
     45 	${CC} -E ${CFLAGS} ${.IMPSRC} | xstr -c -
     46 	@${CC} ${CFLAGS} -c x.c -o ${.TARGET}
     47 	@rm -f x.c
     48 .endif
     49 
     50 .if defined(PROG)
     51 .if defined(SRCS)
     52 
     53 OBJS+=  ${SRCS:R:S/$/.o/g}
     54 
     55 .if defined(LDONLY)
     56 
     57 ${PROG}: ${LIBCRT0} ${LIBC} ${OBJS} ${DPADD}
     58 	${LD} ${LDFLAGS} -o ${.TARGET} ${LIBCRT0} ${OBJS} ${LIBC} ${LDADD}
     59 
     60 .else defined(LDONLY)
     61 
     62 ${PROG}: ${OBJS} ${LIBC} ${DPADD}
     63 	${CC} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
     64 
     65 .endif
     66 
     67 .else defined(PROG)
     68 
     69 SRCS= ${PROG}.c
     70 
     71 ${PROG}: ${SRCS} ${LIBC} ${DPADD}
     72 	${CC} ${LDFLAGS} ${CFLAGS} -o ${.TARGET} ${.CURDIR}/${SRCS} ${LDADD}
     73 
     74 MKDEP=	-p
     75 
     76 .endif
     77 
     78 .if	!defined(MAN1) && !defined(MAN2) && !defined(MAN3) && \
     79 	!defined(MAN4) && !defined(MAN5) && !defined(MAN6) && \
     80 	!defined(MAN7) && !defined(MAN8)
     81 MAN1=	${PROG}.0
     82 .endif
     83 .endif
     84 
     85 .if !defined(NOMAN)
     86 MANALL=	${MAN1} ${MAN2} ${MAN3} ${MAN4} ${MAN5} ${MAN6} ${MAN7} ${MAN8}
     87 .endif
     88 
     89 _PROGSUBDIR: .USE
     90 .if defined(SUBDIR) && !empty(SUBDIR)
     91 	@for entry in ${SUBDIR}; do \
     92 		(echo "===> $$entry"; \
     93 		if test -d ${.CURDIR}/$${entry}.${MACHINE}; then \
     94 			cd ${.CURDIR}/$${entry}.${MACHINE}; \
     95 		else \
     96 			cd ${.CURDIR}/$${entry}; \
     97 		fi; \
     98 		${MAKE} ${.TARGET:S/realinstall/install/:S/.depend/depend/}); \
     99 	done
    100 .endif
    101 
    102 .MAIN: all
    103 all: ${PROG} ${MANALL} _PROGSUBDIR
    104 
    105 .if !target(clean)
    106 clean: _PROGSUBDIR
    107 	rm -f a.out [Ee]rrs mklog core ${PROG} ${OBJS} ${CLEANFILES}
    108 .endif
    109 
    110 .if !target(cleandir)
    111 cleandir: _PROGSUBDIR
    112 	rm -f a.out [Ee]rrs mklog core ${PROG} ${OBJS} ${CLEANFILES}
    113 	rm -f .depend ${MANALL}
    114 .endif
    115 
    116 # some of the rules involve .h sources, so remove them from mkdep line
    117 .if !target(depend)
    118 depend: .depend _PROGSUBDIR
    119 .depend: ${SRCS}
    120 .if defined(PROG)
    121 	mkdep ${MKDEP} ${CFLAGS:M-[ID+]*} ${.ALLSRC:M*.c}
    122 .endif
    123 .endif
    124 
    125 .if !target(install)
    126 .if !target(beforeinstall)
    127 beforeinstall:
    128 .if defined(DESTDIR) || defined(BINDIR)
    129 	@if [ ! -d "${DESTDIR}${BINDIR}" ]; then \
    130                 /bin/rm -f ${DESTDIR}${BINDIR} ; \
    131                 mkdir -p ${DESTDIR}${BINDIR} ; \
    132                 chown root.wheel ${DESTDIR}${BINDIR} ; \
    133                 chmod 755 ${DESTDIR}${BINDIR} ; \
    134         else \
    135                 true ; \
    136         fi
    137 .endif
    138 .endif
    139 .if !target(afterinstall)
    140 afterinstall:
    141 .endif
    142 
    143 .if !target(realinstall)
    144 realinstall: _PROGSUBDIR
    145 .if defined(PROG)
    146 	install ${COPY} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
    147 	    ${PROG} ${DESTDIR}${BINDIR}
    148 .endif
    149 .if defined(HIDEGAME)
    150 	(cd ${DESTDIR}/usr/games; rm -f ${PROG}; ln -s dm ${PROG}; \
    151 	    chown games.bin ${PROG})
    152 .endif
    153 .if defined(LINKS) && !empty(LINKS)
    154 	@set ${LINKS}; \
    155 	while test $$# -ge 2; do \
    156 		l=${DESTDIR}$$1; \
    157 		shift; \
    158 		t=${DESTDIR}$$1; \
    159 		shift; \
    160 		echo $$t -\> $$l; \
    161 		rm -f $$t; \
    162 		ln $$l $$t; \
    163 	done; true
    164 .endif
    165 .endif
    166 
    167 install: maninstall
    168 maninstall: afterinstall
    169 afterinstall: realinstall
    170 realinstall: beforeinstall
    171 .endif
    172 
    173 .if !target(lint)
    174 lint: ${SRCS} _PROGSUBDIR
    175 .if defined(PROG)
    176 	@${LINT} ${LINTFLAGS} ${CFLAGS} ${.ALLSRC} | more 2>&1
    177 .endif
    178 .endif
    179 
    180 .if !target(obj)
    181 .if defined(NOOBJ)
    182 obj: _PROGSUBDIR
    183 .else
    184 obj: _PROGSUBDIR
    185 	@cd ${.CURDIR}; rm -f obj > /dev/null 2>&1 || true; \
    186 	here=`pwd`; subdir=`echo $$here | sed 's,^/usr/src/,,'`; \
    187 	if test $$here != $$subdir ; then \
    188 		dest=/usr/obj/$$subdir ; \
    189 		echo "$$here -> $$dest"; ln -s $$dest obj; \
    190 		if test -d /usr/obj -a ! -d $$dest; then \
    191 			mkdir -p $$dest; \
    192 		else \
    193 			true; \
    194 		fi; \
    195 	else \
    196 		true ; \
    197 		dest=$$here/obj ; \
    198 		echo "making $$here/obj" ; \
    199 		if test ! -d obj ; then \
    200 			mkdir $$here/obj; \
    201 		fi ; \
    202 	fi;
    203 .endif
    204 .endif
    205 
    206 .if !target(tags)
    207 tags: ${SRCS} _PROGSUBDIR
    208 .if defined(PROG)
    209 	-cd ${.CURDIR}; ctags -f /dev/stdout ${.ALLSRC} | \
    210 	    sed "s;\${.CURDIR}/;;" > tags
    211 .endif
    212 .endif
    213 
    214 .if !defined(NOMAN)
    215 .include <bsd.man.mk>
    216 .endif
    217