xref: /freebsd/share/mk/bsd.prog.mk (revision 5d68012a5432e2e40f6338c4b3f507436554dceb)
13585b293SGarrett Wollman#	from: @(#)bsd.prog.mk	5.26 (Berkeley) 6/25/91
27f3dea24SPeter Wemm# $FreeBSD$
3afe61c15SRodney W. Grimes
4e0301e5dSPeter Wemm.if !target(__initialized__)
5e0301e5dSPeter Wemm__initialized__:
63585b293SGarrett Wollman.if exists(${.CURDIR}/../Makefile.inc)
7afe61c15SRodney W. Grimes.include "${.CURDIR}/../Makefile.inc"
8afe61c15SRodney W. Grimes.endif
9e0301e5dSPeter Wemm.endif
10afe61c15SRodney W. Grimes
11c7cbe79eSDmitrij Tejblum.SUFFIXES: .out .o .c .cc .cpp .cxx .C .m .y .l .s .S
12afe61c15SRodney W. Grimes
13e82b0b99SJordan K. HubbardCFLAGS+=${COPTS} ${DEBUG_FLAGS}
14afe61c15SRodney W. Grimes
15e82b0b99SJordan K. Hubbard.if !defined(DEBUG_FLAGS)
16afe61c15SRodney W. GrimesSTRIP?=	-s
17e82b0b99SJordan K. Hubbard.endif
18afe61c15SRodney W. Grimes
193d8cd70cSPaul Traina.if defined(NOSHARED) && ( ${NOSHARED} != "no" && ${NOSHARED} != "NO" )
203585b293SGarrett WollmanLDFLAGS+= -static
213585b293SGarrett Wollman.endif
22afe61c15SRodney W. Grimes
2347bf8a5cSRuslan Ermilov.if defined(PROG_CXX)
2447bf8a5cSRuslan ErmilovPROG=	${PROG_CXX}
2547bf8a5cSRuslan Ermilov.endif
2647bf8a5cSRuslan Ermilov
27afe61c15SRodney W. Grimes.if defined(PROG)
28afe61c15SRodney W. Grimes.if defined(SRCS)
29afe61c15SRodney W. Grimes
3070a6e331SBruce Evans# If there are Objective C sources, link with Objective C libraries.
3170a6e331SBruce Evans.if ${SRCS:M*.m} != ""
3270a6e331SBruce EvansOBJCLIBS?= -lobjc
3370a6e331SBruce EvansLDADD+=	${OBJCLIBS}
3470a6e331SBruce Evans.endif
3570a6e331SBruce Evans
363585b293SGarrett WollmanOBJS+=  ${SRCS:N*.h:R:S/$/.o/g}
37afe61c15SRodney W. Grimes
385d68012aSRuslan Ermilov${PROG}: ${OBJS}
395d68012aSRuslan Ermilov.if defined(PROG_CXX)
405d68012aSRuslan Ermilov	${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
415d68012aSRuslan Ermilov.else
425d68012aSRuslan Ermilov	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
435d68012aSRuslan Ermilov.endif
445d68012aSRuslan Ermilov
45fd2e43eaSBruce Evans.else !defined(SRCS)
46afe61c15SRodney W. Grimes
475d68012aSRuslan Ermilov.if !target(${PROG})
4847bf8a5cSRuslan Ermilov.if defined(PROG_CXX)
4947bf8a5cSRuslan ErmilovSRCS=	${PROG}.cc
5047bf8a5cSRuslan Ermilov.else
51afe61c15SRodney W. GrimesSRCS=	${PROG}.c
5247bf8a5cSRuslan Ermilov.endif
53afe61c15SRodney W. Grimes
54a4c39c7aSBruce Evans# Always make an intermediate object file because:
55a4c39c7aSBruce Evans# - it saves time rebuilding when only the library has changed
56a4c39c7aSBruce Evans# - the name of the object gets put into the executable symbol table instead of
57a4c39c7aSBruce Evans#   the name of a variable temporary object.
58a4c39c7aSBruce Evans# - it's useful to keep objects around for crunching.
59a4c39c7aSBruce EvansOBJS=	${PROG}.o
60f5c75051SEivind Eklund
61987afe2aSBruce Evans${PROG}: ${OBJS}
62f8ba1555SRuslan Ermilov.if defined(PROG_CXX)
63f8ba1555SRuslan Ermilov	${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
64f8ba1555SRuslan Ermilov.else
65de0d6977SRuslan Ermilov	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
66afe61c15SRodney W. Grimes.endif
675d68012aSRuslan Ermilov.endif
68f5c75051SEivind Eklund
696fe6af9fSEivind Eklund.endif
70afe61c15SRodney W. Grimes
71862d3deaSRuslan Ermilov.if	!defined(NOMAN) && !defined(MAN) && \
72862d3deaSRuslan Ermilov	!defined(MAN1) && !defined(MAN2) && !defined(MAN3) && \
73afe61c15SRodney W. Grimes	!defined(MAN4) && !defined(MAN5) && !defined(MAN6) && \
74500d8265SRuslan Ermilov	!defined(MAN7) && !defined(MAN8) && !defined(MAN9) && \
75862d3deaSRuslan Ermilov	!defined(MAN1aout)
7619ea15a1SRuslan ErmilovMAN=	${PROG}.1
7719ea15a1SRuslan ErmilovMAN1=	${MAN}
78afe61c15SRodney W. Grimes.endif
79afe61c15SRodney W. Grimes.endif
80afe61c15SRodney W. Grimes
81afe61c15SRodney W. Grimes.MAIN: all
82a7aaf57eSRuslan Ermilovall: objwarn ${PROG} ${SCRIPTS} ${FILES}
83862d3deaSRuslan Ermilov.if !defined(NOMAN)
84a7aaf57eSRuslan Ermilovall: all-man
85862d3deaSRuslan Ermilov.endif
86a7aaf57eSRuslan Ermilovall: _SUBDIR
87afe61c15SRodney W. Grimes
8889d11b8aSBruce EvansCLEANFILES+= ${PROG} ${OBJS}
89afe61c15SRodney W. Grimes
90218a2cd2SBruce Evans.if defined(PROG)
91663e9677SBruce Evans_EXTRADEPEND:
92cdaa52cfSJohn Birrell.if ${OBJFORMAT} == aout
93de0d6977SRuslan Ermilov	echo ${PROG}: `${CC} -Wl,-f ${CFLAGS} ${LDFLAGS} \
941c735bb4SBruce Evans	    ${LDADD:S/^/-Wl,/}` >> ${DEPENDFILE}
958c05a446SPeter Wemm.else
966e19760bSBruce Evans	echo ${PROG}: ${LIBC} ${DPADD} >> ${DEPENDFILE}
97f8ba1555SRuslan Ermilov.if defined(PROG_CXX)
98f8ba1555SRuslan Ermilov	echo ${PROG}: ${LIBSTDCPLUSPLUS} >> ${DEPENDFILE}
99f8ba1555SRuslan Ermilov.endif
1008c05a446SPeter Wemm.endif
101663e9677SBruce Evans.endif
102663e9677SBruce Evans
103afe61c15SRodney W. Grimes.if !target(install)
104afe61c15SRodney W. Grimes.if !target(beforeinstall)
105afe61c15SRodney W. Grimesbeforeinstall:
106afe61c15SRodney W. Grimes.endif
107afe61c15SRodney W. Grimes
108e902c1bbSTim Vanderhoek_INSTALLFLAGS:=	${INSTALLFLAGS}
109e902c1bbSTim Vanderhoek.for ie in ${INSTALLFLAGS_EDIT}
110e902c1bbSTim Vanderhoek_INSTALLFLAGS:=	${_INSTALLFLAGS${ie}}
111e902c1bbSTim Vanderhoek.endfor
112e902c1bbSTim Vanderhoek
113cd9a2f5cSJordan K. Hubbardrealinstall: beforeinstall
114afe61c15SRodney W. Grimes.if defined(PROG)
11595f8c826SRuslan Ermilov.if defined(PROGNAME)
11695f8c826SRuslan Ermilov	${INSTALL} ${COPY} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
11795f8c826SRuslan Ermilov	    ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}/${PROGNAME}
11895f8c826SRuslan Ermilov.else
1193585b293SGarrett Wollman	${INSTALL} ${COPY} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
120e902c1bbSTim Vanderhoek	    ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}
121afe61c15SRodney W. Grimes.endif
12295f8c826SRuslan Ermilov.endif
123afe61c15SRodney W. Grimes.if defined(HIDEGAME)
124dfcf88a3SRuslan Ermilov	(cd ${DESTDIR}${ORIGBINDIR}; ln -fs dm ${PROG}; \
125dfcf88a3SRuslan Ermilov	    chown -h ${BINOWN}:${ORIGBINGRP} ${PROG})
126afe61c15SRodney W. Grimes.endif
127afe61c15SRodney W. Grimes.if defined(LINKS) && !empty(LINKS)
128afe61c15SRodney W. Grimes	@set ${LINKS}; \
129afe61c15SRodney W. Grimes	while test $$# -ge 2; do \
130afe61c15SRodney W. Grimes		l=${DESTDIR}$$1; \
131afe61c15SRodney W. Grimes		shift; \
132afe61c15SRodney W. Grimes		t=${DESTDIR}$$1; \
133afe61c15SRodney W. Grimes		shift; \
134a4c39c7aSBruce Evans		${ECHO} $$t -\> $$l; \
1352336a7eaSBruce Evans		ln -f $$l $$t; \
1362336a7eaSBruce Evans	done; true
1372336a7eaSBruce Evans.endif
1382336a7eaSBruce Evans.if defined(SYMLINKS) && !empty(SYMLINKS)
1392336a7eaSBruce Evans	@set ${SYMLINKS}; \
1402336a7eaSBruce Evans	while test $$# -ge 2; do \
1412336a7eaSBruce Evans		l=$$1; \
1422336a7eaSBruce Evans		shift; \
1432336a7eaSBruce Evans		t=${DESTDIR}$$1; \
1442336a7eaSBruce Evans		shift; \
1452336a7eaSBruce Evans		${ECHO} $$t -\> $$l; \
1462336a7eaSBruce Evans		ln -fs $$l $$t; \
147afe61c15SRodney W. Grimes	done; true
148afe61c15SRodney W. Grimes.endif
149afe61c15SRodney W. Grimes
150f7ee8cfeSRuslan Ermilov.if defined(SCRIPTS) && !empty(SCRIPTS)
151f7ee8cfeSRuslan Ermilovrealinstall: _scriptsinstall
152f7ee8cfeSRuslan Ermilov
153f7ee8cfeSRuslan ErmilovSCRIPTSDIR?=	${BINDIR}
154f7ee8cfeSRuslan ErmilovSCRIPTSOWN?=	${BINOWN}
155f7ee8cfeSRuslan ErmilovSCRIPTSGRP?=	${BINGRP}
156f7ee8cfeSRuslan ErmilovSCRIPTSMODE?=	${BINMODE}
157f7ee8cfeSRuslan Ermilov
158f7ee8cfeSRuslan Ermilov.for script in ${SCRIPTS}
159f7ee8cfeSRuslan Ermilov.if defined(SCRIPTSNAME)
160f7ee8cfeSRuslan ErmilovSCRIPTSNAME_${script:T}?=	${SCRIPTSNAME}
161f7ee8cfeSRuslan Ermilov.else
162f7ee8cfeSRuslan ErmilovSCRIPTSNAME_${script:T}?=	${script:T:R}
163f7ee8cfeSRuslan Ermilov.endif
164f7ee8cfeSRuslan ErmilovSCRIPTSDIR_${script:T}?=	${SCRIPTSDIR}
165f7ee8cfeSRuslan ErmilovSCRIPTSOWN_${script:T}?=	${SCRIPTSOWN}
166f7ee8cfeSRuslan ErmilovSCRIPTSGRP_${script:T}?=	${SCRIPTSGRP}
167f7ee8cfeSRuslan ErmilovSCRIPTSMODE_${script:T}?=	${SCRIPTSMODE}
168a7aaf57eSRuslan Ermilov_scriptsinstall: _SCRIPTSINS_${script:T}
169a7aaf57eSRuslan Ermilov_SCRIPTSINS_${script:T}: ${script}
170f7ee8cfeSRuslan Ermilov	${INSTALL} ${COPY} -o ${SCRIPTSOWN_${.ALLSRC:T}} \
171f7ee8cfeSRuslan Ermilov	    -g ${SCRIPTSGRP_${.ALLSRC:T}} -m ${SCRIPTSMODE_${.ALLSRC:T}} \
172f7ee8cfeSRuslan Ermilov	    ${_INSTALLFLAGS} ${.ALLSRC} \
173f7ee8cfeSRuslan Ermilov	    ${DESTDIR}${SCRIPTSDIR_${.ALLSRC:T}}/${SCRIPTSNAME_${.ALLSRC:T}}
174f7ee8cfeSRuslan Ermilov.endfor
175f7ee8cfeSRuslan Ermilov.endif
176f7ee8cfeSRuslan Ermilov
177a7aaf57eSRuslan Ermilov.if defined(FILES) && !empty(FILES)
178a7aaf57eSRuslan Ermilovrealinstall: _filesinstall
179a7aaf57eSRuslan Ermilov
180a7aaf57eSRuslan ErmilovFILESDIR?=	${BINDIR}
181a7aaf57eSRuslan ErmilovFILESOWN?=	${SHAREOWN}
182a7aaf57eSRuslan ErmilovFILESGRP?=	${SHAREGRP}
183a7aaf57eSRuslan ErmilovFILESMODE?=	${SHAREMODE}
184a7aaf57eSRuslan Ermilov
185a7aaf57eSRuslan Ermilov.for file in ${FILES}
186a7aaf57eSRuslan Ermilov.if defined(FILESNAME)
187a7aaf57eSRuslan ErmilovFILESNAME_${file:T}?=	${FILESNAME}
188a7aaf57eSRuslan Ermilov.else
189a7aaf57eSRuslan ErmilovFILESNAME_${file:T}?=	${file:T}
190a7aaf57eSRuslan Ermilov.endif
191a7aaf57eSRuslan ErmilovFILESDIR_${file:T}?=	${FILESDIR}
192a7aaf57eSRuslan ErmilovFILESOWN_${file:T}?=	${FILESOWN}
193a7aaf57eSRuslan ErmilovFILESGRP_${file:T}?=	${FILESGRP}
194a7aaf57eSRuslan ErmilovFILESMODE_${file:T}?=	${FILESMODE}
195a7aaf57eSRuslan Ermilov_filesinstall: _FILESINS_${file:T}
196a7aaf57eSRuslan Ermilov_FILESINS_${file:T}: ${file}
197a7aaf57eSRuslan Ermilov	${INSTALL} ${COPY} -o ${FILESOWN_${.ALLSRC:T}} \
198a7aaf57eSRuslan Ermilov	    -g ${FILESGRP_${.ALLSRC:T}} -m ${FILESMODE_${.ALLSRC:T}} \
199a7aaf57eSRuslan Ermilov	    ${_INSTALLFLAGS} ${.ALLSRC} \
200a7aaf57eSRuslan Ermilov	    ${DESTDIR}${FILESDIR_${.ALLSRC:T}}/${FILESNAME_${.ALLSRC:T}}
201a7aaf57eSRuslan Ermilov.endfor
202a7aaf57eSRuslan Ermilov.endif
203a7aaf57eSRuslan Ermilov
204cd9a2f5cSJordan K. Hubbardinstall: afterinstall _SUBDIR
2053585b293SGarrett Wollman.if !defined(NOMAN)
2063585b293SGarrett Wollmanafterinstall: realinstall maninstall
2073585b293SGarrett Wollman.else
208afe61c15SRodney W. Grimesafterinstall: realinstall
2093585b293SGarrett Wollman.endif
210afe61c15SRodney W. Grimes.endif
211afe61c15SRodney W. Grimes
212d9584d76SJordan K. HubbardDISTRIBUTION?=	bin
21355ff8fb1SPoul-Henning Kamp.if !target(distribute)
214cd9a2f5cSJordan K. Hubbarddistribute: _SUBDIR
215398ac038SJordan K. Hubbard.for dist in ${DISTRIBUTION}
216398ac038SJordan K. Hubbard	cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${dist} SHARED=copies
217398ac038SJordan K. Hubbard.endfor
21855ff8fb1SPoul-Henning Kamp.endif
21955ff8fb1SPoul-Henning Kamp
220afe61c15SRodney W. Grimes.if !target(lint)
221cd9a2f5cSJordan K. Hubbardlint: ${SRCS} _SUBDIR
222afe61c15SRodney W. Grimes.if defined(PROG)
22308b44302SBruce Evans	${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC} | more 2>&1
224afe61c15SRodney W. Grimes.endif
225afe61c15SRodney W. Grimes.endif
226afe61c15SRodney W. Grimes
2276eb5e456SJordan K. Hubbard.if defined(NOTAGS)
2286eb5e456SJordan K. Hubbardtags:
2296eb5e456SJordan K. Hubbard.endif
2306eb5e456SJordan K. Hubbard
231afe61c15SRodney W. Grimes.if !target(tags)
232cd9a2f5cSJordan K. Hubbardtags: ${SRCS} _SUBDIR
233afe61c15SRodney W. Grimes.if defined(PROG)
2341ed9b1c3SEivind Eklund	@cd ${.CURDIR} && gtags ${GTAGSFLAGS} ${.OBJDIR}
2356eb5e456SJordan K. Hubbard.if defined(HTML)
2361ed9b1c3SEivind Eklund	@cd ${.CURDIR} && htags ${HTAGSFLAGS} -d ${.OBJDIR} ${.OBJDIR}
2376eb5e456SJordan K. Hubbard.endif
238afe61c15SRodney W. Grimes.endif
239afe61c15SRodney W. Grimes.endif
240afe61c15SRodney W. Grimes
241afe61c15SRodney W. Grimes.if !defined(NOMAN)
242afe61c15SRodney W. Grimes.include <bsd.man.mk>
243918fb560SRuslan Ermilov.else
244918fb560SRuslan Ermilov.if !target(all-man)
245918fb560SRuslan Ermilovall-man:
246918fb560SRuslan Ermilov.endif
247918fb560SRuslan Ermilov.if !target(maninstall)
248afe61c15SRodney W. Grimesmaninstall:
249afe61c15SRodney W. Grimes.endif
250918fb560SRuslan Ermilov.endif
2513585b293SGarrett Wollman
25269b87d3eSEivind Eklund.if !target(regress)
25369b87d3eSEivind Eklundregress:
25469b87d3eSEivind Eklund.endif
25569b87d3eSEivind Eklund
256368c8de4SJohn Polstra.if ${OBJFORMAT} != aout || make(checkdpadd) || defined(NEED_LIBNAMES)
2578c05a446SPeter Wemm.include <bsd.libnames.mk>
2588c05a446SPeter Wemm.endif
2598c05a446SPeter Wemm
2603585b293SGarrett Wollman.include <bsd.dep.mk>
261987afe2aSBruce Evans
26288505e11SRuslan Ermilov.if defined(PROG) && !exists(${.OBJDIR}/${DEPENDFILE})
263589d9341SBruce Evans${OBJS}: ${SRCS:M*.h}
264987afe2aSBruce Evans.endif
265987afe2aSBruce Evans
266cd9a2f5cSJordan K. Hubbard.include <bsd.obj.mk>
267d510ecb4SKris Kennaway
268d510ecb4SKris Kennaway.include <bsd.sys.mk>
269