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