1# $OpenBSD: bsd.prog.mk,v 1.81 2019/11/15 00:06:46 jsg Exp $ 2# $NetBSD: bsd.prog.mk,v 1.55 1996/04/08 21:19:26 jtc Exp $ 3# @(#)bsd.prog.mk 5.26 (Berkeley) 6/25/91 4 5.if exists(${.CURDIR}/../Makefile.inc) 6.include "${.CURDIR}/../Makefile.inc" 7.endif 8 9.include <bsd.own.mk> 10 11.SUFFIXES: .out .o .c .cc .cpp .C .cxx .y .l .s 12 13.if (defined(LDSTATIC) && !defined(STATICPIE)) || defined(NOPIE) 14CFLAGS+= ${NOPIE_FLAGS} 15CXXFLAGS+= ${NOPIE_FLAGS} 16AFLAGS+= ${NOPIE_FLAGS} 17LDFLAGS+= ${NOPIE_LDFLAGS} 18.endif 19 20.if ${WARNINGS:L} == "yes" 21CFLAGS+= ${CDIAGFLAGS} 22CXXFLAGS+= ${CXXDIAGFLAGS} 23.endif 24CFLAGS+= ${COPTS} 25CXXFLAGS+= ${CXXOPTS} 26 27CRTBEGIN?= ${DESTDIR}/usr/lib/crtbegin.o 28CRTEND?= ${DESTDIR}/usr/lib/crtend.o 29 30LIBCRT0?= ${DESTDIR}/usr/lib/crt0.o 31LIBC?= ${DESTDIR}/usr/lib/libc.a 32LIBCBOR?= ${DESTDIR}/usr/lib/libcbor.a 33LIBCRYPTO?= ${DESTDIR}/usr/lib/libcrypto.a 34LIBCURSES?= ${DESTDIR}/usr/lib/libcurses.a 35LIBEDIT?= ${DESTDIR}/usr/lib/libedit.a 36LIBELF?= ${DESTDIR}/usr/lib/libelf.a 37LIBEVENT?= ${DESTDIR}/usr/lib/libevent.a 38LIBEXPAT?= ${DESTDIR}/usr/lib/libexpat.a 39LIBFIDO2?= ${DESTDIR}/usr/lib/libfido2.a 40LIBFORM?= ${DESTDIR}/usr/lib/libform.a 41LIBFORMW?= ${DESTDIR}/usr/lib/libformw.a 42LIBKEYNOTE?= ${DESTDIR}/usr/lib/libkeynote.a 43LIBKVM?= ${DESTDIR}/usr/lib/libkvm.a 44LIBL?= ${DESTDIR}/usr/lib/libl.a 45LIBM?= ${DESTDIR}/usr/lib/libm.a 46LIBMENU?= ${DESTDIR}/usr/lib/libmenu.a 47LIBMENUW?= ${DESTDIR}/usr/lib/libmenuw.a 48LIBRADIUS?= ${DESTDIR}/usr/lib/libradius.a 49LIBOSSAUDIO?= ${DESTDIR}/usr/lib/libossaudio.a 50LIBPANEL?= ${DESTDIR}/usr/lib/libpanel.a 51LIBPANELW?= ${DESTDIR}/usr/lib/libpanelw.a 52LIBPCAP?= ${DESTDIR}/usr/lib/libpcap.a 53LIBPERL?= ${DESTDIR}/usr/lib/libperl.a 54LIBPTHREAD?= ${DESTDIR}/usr/lib/libpthread.a 55LIBRPCSVC?= ${DESTDIR}/usr/lib/librpcsvc.a 56LIBSKEY?= ${DESTDIR}/usr/lib/libskey.a 57LIBSNDIO?= ${DESTDIR}/usr/lib/libsndio.a 58LIBSSL?= ${DESTDIR}/usr/lib/libssl.a 59LIBTLS?= ${DESTDIR}/usr/lib/libtls.a 60LIBTERMCAP?= ${DESTDIR}/usr/lib/libtermcap.a 61LIBTERMLIB?= ${DESTDIR}/usr/lib/libtermlib.a 62LIBUSBHID?= ${DESTDIR}/usr/lib/libusbhid.a 63LIBUTIL?= ${DESTDIR}/usr/lib/libutil.a 64LIBY?= ${DESTDIR}/usr/lib/liby.a 65LIBZ?= ${DESTDIR}/usr/lib/libz.a 66 67.if ${MACHINE_ARCH} == "alpha" || ${MACHINE_ARCH} == "amd64" || \ 68 ${MACHINE_ARCH} == "arm" || ${MACHINE_ARCH} == "i386" 69LIBARCH?= ${DESTDIR}/usr/lib/lib${MACHINE_ARCH}.a 70.else 71LIBARCH?= 72.endif 73 74.if defined(PROG) 75SRCS ?= ${PROG}.c 76MAN ?= ${PROG}.1 77.endif 78 79# if we have several progs, define appropriate vars instead 80.if defined(PROGS) 81. for p in ${PROGS} 82SRCS_$p ?= $p.c 83OBJS_$p = ${SRCS_$p:N*.h:N*.sh:R:S/$/.o/} 84DPADD_$p ?= ${DPADD} 85LDADD_$p ?= ${LDADD} 86 87# XXX still create SRCS, because it's what bsd.dep.mk understands 88SRCS += ${SRCS_$p} 89 90# and we can write the actual target already 91. if defined(OBJS_$p) && !empty(OBJS_$p) 92. if !empty(SRCS_$p:M*.C) || !empty(SRCS_$p:M*.cc) || \ 93 !empty(SRCS_$p:M*.cpp) || !empty(SRCS_$p:M*.cxx) 94$p: ${LIBCRT0} ${OBJS_$p} ${LIBC} ${CRTBEGIN} ${CRTEND} ${DPADD_$p} 95 ${CXX} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} ${OBJS_$p} ${LDADD_$p} 96. else 97$p: ${LIBCRT0} ${OBJS_$p} ${LIBC} ${CRTBEGIN} ${CRTEND} ${DPADD_$p} 98 ${CC} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} ${OBJS_$p} ${LDADD_$p} 99. endif 100. endif 101. endfor 102MAN ?= ${PROGS:=.1} 103.endif 104 105.if defined(PROG) || defined(PROGS) 106# ... so we create appropriate full list of obj, dep, lex, yacc... 107. if !empty(SRCS:N*.h:N*.sh) 108OBJS+= ${SRCS:N*.h:N*.sh:R:S/$/.o/} 109DEPS+= ${OBJS:.o=.d} 110. endif 111 112_LEXINTM?=${SRCS:M*.l:.l=.c} 113_YACCINTM?=${SRCS:M*.y:.y=.c} 114.endif 115 116.if defined(PROG) 117. if defined(OBJS) && !empty(OBJS) 118. if !empty(SRCS:M*.C) || !empty(SRCS:M*.cc) || \ 119 !empty(SRCS:M*.cpp) || !empty(SRCS:M*.cxx) 120${PROG}: ${LIBCRT0} ${OBJS} ${LIBC} ${CRTBEGIN} ${CRTEND} ${DPADD} 121 ${CXX} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} ${OBJS} ${LDADD} 122. else 123${PROG}: ${LIBCRT0} ${OBJS} ${LIBC} ${CRTBEGIN} ${CRTEND} ${DPADD} 124 ${CC} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} ${OBJS} ${LDADD} 125. endif 126. endif # defined(OBJS) && !empty(OBJS) 127.endif 128 129.MAIN: all 130all: ${PROG} ${PROGS} _SUBDIRUSE 131 132BUILDAFTER += ${PROG} ${PROGS} ${OBJS} 133 134.if !target(clean) 135clean: _SUBDIRUSE 136 rm -f a.out [Ee]rrs mklog *.core y.tab.h \ 137 ${PROG} ${PROGS} ${OBJS} ${_LEXINTM} ${_YACCINTM} ${CLEANFILES} 138.endif 139 140cleandir: _SUBDIRUSE clean 141 142.if !target(install) 143.if !target(beforeinstall) 144beforeinstall: 145.endif 146.if !target(afterinstall) 147afterinstall: 148.endif 149 150.if !target(realinstall) 151realinstall: 152. if defined(PROG) 153 ${INSTALL} ${INSTALL_COPY} ${INSTALL_STRIP} \ 154 -o ${BINOWN} -g ${BINGRP} \ 155 -m ${BINMODE} ${PROG} ${DESTDIR}${BINDIR}/${PROG} 156. endif 157. if defined(PROGS) 158. for p in ${PROGS} 159 ${INSTALL} ${INSTALL_COPY} ${INSTALL_STRIP} \ 160 -o ${BINOWN} -g ${BINGRP} \ 161 -m ${BINMODE} $p ${DESTDIR}${BINDIR}/$p 162. endfor 163. endif 164.endif 165 166install: maninstall _SUBDIRUSE 167.if defined(LINKS) && !empty(LINKS) 168. for lnk file in ${LINKS} 169 @l=${DESTDIR}${lnk}; \ 170 t=${DESTDIR}${file}; \ 171 echo $$t -\> $$l; \ 172 rm -f $$t; ln $$l $$t 173. endfor 174.endif 175 176maninstall: afterinstall 177afterinstall: realinstall 178realinstall: beforeinstall 179.endif 180 181.if !defined(NOMAN) 182.include <bsd.man.mk> 183.endif 184 185# if we already got bsd.lib.mk we don't want to wreck that 186.if !defined(_LIBS) 187.s.o: 188 ${COMPILE.S} -MD -MF ${.TARGET:R}.d -o $@ ${.IMPSRC} 189 190.S.o: 191 ${COMPILE.S} -MD -MF ${.TARGET:R}.d -o $@ ${.IMPSRC} 192.endif 193 194.include <bsd.obj.mk> 195.include <bsd.dep.mk> 196.include <bsd.subdir.mk> 197.include <bsd.sys.mk> 198