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