1# $OpenBSD: bsd.prog.mk,v 1.82 2020/09/22 10:31:46 martijn 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 59LIBAGENTX?= ${DESTDIR}/usr/lib/libagentx.a 60LIBTLS?= ${DESTDIR}/usr/lib/libtls.a 61LIBTERMCAP?= ${DESTDIR}/usr/lib/libtermcap.a 62LIBTERMLIB?= ${DESTDIR}/usr/lib/libtermlib.a 63LIBUSBHID?= ${DESTDIR}/usr/lib/libusbhid.a 64LIBUTIL?= ${DESTDIR}/usr/lib/libutil.a 65LIBY?= ${DESTDIR}/usr/lib/liby.a 66LIBZ?= ${DESTDIR}/usr/lib/libz.a 67 68.if ${MACHINE_ARCH} == "alpha" || ${MACHINE_ARCH} == "amd64" || \ 69 ${MACHINE_ARCH} == "arm" || ${MACHINE_ARCH} == "i386" 70LIBARCH?= ${DESTDIR}/usr/lib/lib${MACHINE_ARCH}.a 71.else 72LIBARCH?= 73.endif 74 75.if defined(PROG) 76SRCS ?= ${PROG}.c 77MAN ?= ${PROG}.1 78.endif 79 80# if we have several progs, define appropriate vars instead 81.if defined(PROGS) 82. for p in ${PROGS} 83SRCS_$p ?= $p.c 84OBJS_$p = ${SRCS_$p:N*.h:N*.sh:R:S/$/.o/} 85DPADD_$p ?= ${DPADD} 86LDADD_$p ?= ${LDADD} 87 88# XXX still create SRCS, because it's what bsd.dep.mk understands 89SRCS += ${SRCS_$p} 90 91# and we can write the actual target already 92. if defined(OBJS_$p) && !empty(OBJS_$p) 93. if !empty(SRCS_$p:M*.C) || !empty(SRCS_$p:M*.cc) || \ 94 !empty(SRCS_$p:M*.cpp) || !empty(SRCS_$p:M*.cxx) 95$p: ${LIBCRT0} ${OBJS_$p} ${LIBC} ${CRTBEGIN} ${CRTEND} ${DPADD_$p} 96 ${CXX} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} ${OBJS_$p} ${LDADD_$p} 97. else 98$p: ${LIBCRT0} ${OBJS_$p} ${LIBC} ${CRTBEGIN} ${CRTEND} ${DPADD_$p} 99 ${CC} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} ${OBJS_$p} ${LDADD_$p} 100. endif 101. endif 102. endfor 103MAN ?= ${PROGS:=.1} 104.endif 105 106.if defined(PROG) || defined(PROGS) 107# ... so we create appropriate full list of obj, dep, lex, yacc... 108. if !empty(SRCS:N*.h:N*.sh) 109OBJS+= ${SRCS:N*.h:N*.sh:R:S/$/.o/} 110DEPS+= ${OBJS:.o=.d} 111. endif 112 113_LEXINTM?=${SRCS:M*.l:.l=.c} 114_YACCINTM?=${SRCS:M*.y:.y=.c} 115.endif 116 117.if defined(PROG) 118. if defined(OBJS) && !empty(OBJS) 119. if !empty(SRCS:M*.C) || !empty(SRCS:M*.cc) || \ 120 !empty(SRCS:M*.cpp) || !empty(SRCS:M*.cxx) 121${PROG}: ${LIBCRT0} ${OBJS} ${LIBC} ${CRTBEGIN} ${CRTEND} ${DPADD} 122 ${CXX} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} ${OBJS} ${LDADD} 123. else 124${PROG}: ${LIBCRT0} ${OBJS} ${LIBC} ${CRTBEGIN} ${CRTEND} ${DPADD} 125 ${CC} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} ${OBJS} ${LDADD} 126. endif 127. endif # defined(OBJS) && !empty(OBJS) 128.endif 129 130.MAIN: all 131all: ${PROG} ${PROGS} _SUBDIRUSE 132 133BUILDAFTER += ${PROG} ${PROGS} ${OBJS} 134 135.if !target(clean) 136clean: _SUBDIRUSE 137 rm -f a.out [Ee]rrs mklog *.core y.tab.h \ 138 ${PROG} ${PROGS} ${OBJS} ${_LEXINTM} ${_YACCINTM} ${CLEANFILES} 139.endif 140 141cleandir: _SUBDIRUSE clean 142 143.if !target(install) 144.if !target(beforeinstall) 145beforeinstall: 146.endif 147.if !target(afterinstall) 148afterinstall: 149.endif 150 151.if !target(realinstall) 152realinstall: 153. if defined(PROG) 154 ${INSTALL} ${INSTALL_COPY} ${INSTALL_STRIP} \ 155 -o ${BINOWN} -g ${BINGRP} \ 156 -m ${BINMODE} ${PROG} ${DESTDIR}${BINDIR}/${PROG} 157. endif 158. if defined(PROGS) 159. for p in ${PROGS} 160 ${INSTALL} ${INSTALL_COPY} ${INSTALL_STRIP} \ 161 -o ${BINOWN} -g ${BINGRP} \ 162 -m ${BINMODE} $p ${DESTDIR}${BINDIR}/$p 163. endfor 164. endif 165.endif 166 167install: maninstall _SUBDIRUSE 168.if defined(LINKS) && !empty(LINKS) 169. for lnk file in ${LINKS} 170 @l=${DESTDIR}${lnk}; \ 171 t=${DESTDIR}${file}; \ 172 echo $$t -\> $$l; \ 173 rm -f $$t; ln $$l $$t 174. endfor 175.endif 176 177maninstall: afterinstall 178afterinstall: realinstall 179realinstall: beforeinstall 180.endif 181 182.if !defined(NOMAN) 183.include <bsd.man.mk> 184.endif 185 186# if we already got bsd.lib.mk we don't want to wreck that 187.if !defined(_LIBS) 188.s.o: 189 ${COMPILE.S} -MD -MF ${.TARGET:R}.d -o $@ ${.IMPSRC} 190 191.S.o: 192 ${COMPILE.S} -MD -MF ${.TARGET:R}.d -o $@ ${.IMPSRC} 193.endif 194 195.include <bsd.obj.mk> 196.include <bsd.dep.mk> 197.include <bsd.subdir.mk> 198.include <bsd.sys.mk> 199