libstand: Consolidate tftp sendrecv into net.c sendrecv
[unleashed.git] / share / mk / prog.mk
blob6cfecfb5382b7009425e3a45d8165b315eafc8bd
1 # $Id: prog.mk,v 1.32 2017/05/06 17:30:09 sjg Exp $
3 .if !target(__${.PARSEFILE}__)
4 __${.PARSEFILE}__:
6 .include <init.mk>
8 # FreeBSD at least expects MAN8 etc.
9 .if defined(MAN) && !empty(MAN)
10 _sect:=${MAN:E}
11 MAN${_sect}=${MAN}
12 .endif
14 .SUFFIXES: .out .o .c .cc .C .y .l .s .8 .7 .6 .5 .4 .3 .2 .1 .0
16 CFLAGS+= ${COPTS}
18 .if ${MACHINE_ARCH} == "sparc64"
19 CFLAGS+= -mcmodel=medlow
20 .endif
22 # ELF platforms depend on crtbegin.o and crtend.o
23 .if ${OBJECT_FMT} == "ELF"
24 .ifndef LIBCRTBEGIN
25 LIBCRTBEGIN= ${DESTDIR}/usr/lib/crti.o
26 .MADE: ${LIBCRTBEGIN}
27 .endif
28 .ifndef LIBCRTEND
29 LIBCRTEND= ${DESTDIR}/usr/lib/crtn.o
30 .MADE: ${LIBCRTEND}
31 .endif
32 _SHLINKER= ${SHLINKDIR}/ld.elf_so
33 .else
34 LIBCRTBEGIN?=
35 LIBCRTEND?=
36 _SHLINKER= ${SHLINKDIR}/ld.so
37 .endif
39 .ifndef LIBCRT0
40 LIBCRT0= ${DESTDIR}/usr/lib/crt1.o
41 .MADE: ${LIBCRT0}
42 .endif
44 # here is where you can define what LIB* are
45 .-include <libnames.mk>
46 .if ${MK_DPADD_MK} == "yes"
47 # lots of cool magic, but might not suit everyone.
48 .include <dpadd.mk>
49 .endif
51 .if ${MK_GPROF} == "yes"
52 CFLAGS+= ${CC_PG} ${PROFFLAGS}
53 LDADD+= ${CC_PG}
54 .if ${MK_DPADD_MK} == "no"
55 LDADD_LIBC_P?= -lc_p
56 LDADD_LAST+= ${LDADD_LIBC_P}
57 .endif
58 .endif
60 .if defined(SHAREDSTRINGS)
61 CLEANFILES+=strings
62 .c.o:
63 ${CC} -E ${CFLAGS} ${.IMPSRC} | xstr -c -
64 @${CC} ${CFLAGS} -c x.c -o ${.TARGET}
65 @rm -f x.c
67 ${CXX_SUFFIXES:%=%.o}:
68 ${CXX} -E ${CXXFLAGS} ${.IMPSRC} | xstr -c -
69 @mv -f x.c x.cc
70 @${CXX} ${CXXFLAGS} -c x.cc -o ${.TARGET}
71 @rm -f x.cc
72 .endif
75 .if defined(PROG)
76 BINDIR ?= ${prefix}/bin
78 SRCS?= ${PROG}.c
79 .for s in ${SRCS:N*.h:N*.sh:M*/*}
80 ${.o .po .lo:L:@o@${s:T:R}$o@}: $s
81 .endfor
82 .if !empty(SRCS:N*.h:N*.sh)
83 OBJS+= ${SRCS:T:N*.h:N*.sh:R:S/$/.o/g}
84 LOBJS+= ${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln}
85 .endif
87 .if defined(OBJS) && !empty(OBJS)
88 .NOPATH: ${OBJS} ${PROG} ${SRCS:M*.[ly]:C/\..$/.c/} ${YHEADER:D${SRCS:M*.y:.y=.h}}
90 # this is known to work for NetBSD 1.6 and FreeBSD 4.2
91 .if ${TARGET_OSNAME} == "NetBSD" || ${TARGET_OSNAME} == "FreeBSD"
92 _PROGLDOPTS=
93 .if ${SHLINKDIR} != "/usr/libexec" # XXX: change or remove if ld.so moves
94 _PROGLDOPTS+= -Wl,-dynamic-linker=${_SHLINKER}
95 .endif
96 .if defined(LIBDIR) && ${SHLIBDIR} != ${LIBDIR}
97 _PROGLDOPTS+= -Wl,-rpath-link,${DESTDIR}${SHLIBDIR}:${DESTDIR}/usr/lib \
98 -L${DESTDIR}${SHLIBDIR}
99 .endif
100 _PROGLDOPTS+= -Wl,-rpath,${SHLIBDIR}:/usr/lib
102 .if defined(PROG_CXX)
103 _CCLINK= ${CXX}
104 _SUPCXX= -lstdc++ -lm
105 .endif
106 .endif # NetBSD
108 _CCLINK?= ${CC}
110 .if defined(DESTDIR) && exists(${LIBCRT0}) && ${LIBCRT0} != "/dev/null"
112 ${PROG}: ${LIBCRT0} ${OBJS} ${LIBC} ${DPADD}
113 ${_CCLINK} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} -nostdlib ${_PROGLDOPTS} -L${DESTDIR}/usr/lib ${LIBCRT0} ${LIBCRTBEGIN} ${OBJS} ${LDADD} -L${DESTDIR}/usr/lib ${_SUPCXX} -lgcc -lc -lgcc ${LIBCRTEND}
114 .if !empty(BUILDVERSION)
115 mcs -d -a 'Unleashed ${BUILDVERSION}' ${PROG}
116 .endif
118 .else
120 ${PROG}: ${LIBCRT0} ${OBJS} ${LIBC} ${DPADD}
121 ${_CCLINK} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} ${_PROGLDOPTS} ${OBJS} ${LDADD}
122 .if !empty(BUILDVERSION)
123 mcs -d -a 'Unleashed ${BUILDVERSION}' ${PROG}
124 .endif
126 .endif # defined(DESTDIR)
127 .endif # defined(OBJS) && !empty(OBJS)
129 .if !defined(MAN)
130 MAN= ${PROG}.1
131 .endif # !defined(MAN)
132 .endif # defined(PROG)
134 .if !defined(_SKIP_BUILD)
135 realbuild: ${PROG}
136 .endif
138 all: _SUBDIRUSE
140 .if !target(clean)
141 cleanprog:
142 rm -f a.out [Ee]rrs mklog core *.core \
143 ${PROG} ${OBJS} ${LOBJS} ${CLEANFILES}
145 clean: _SUBDIRUSE cleanprog
146 cleandir: _SUBDIRUSE cleanprog
147 .else
148 cleandir: _SUBDIRUSE clean
149 .endif
151 .if defined(SRCS) && (!defined(MKDEP) || ${MKDEP} != autodep)
152 afterdepend: .depend
153 @(TMP=/tmp/_depend$$$$; \
154 sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.ln:/' \
155 < .depend > $$TMP; \
156 mv $$TMP .depend)
157 .endif
159 .if !target(install)
160 .if !target(beforeinstall)
161 beforeinstall:
162 .endif
163 .if !target(afterinstall)
164 afterinstall:
165 .endif
167 .if !empty(BINOWN)
168 PROG_INSTALL_OWN ?= -o ${BINOWN} -g ${BINGRP}
169 .endif
171 .if !target(realinstall)
172 realinstall: proginstall
173 .endif
174 .if !target(proginstall)
175 proginstall:
176 .if defined(PROG)
177 ${INSTALL} -d ${PROG_INSTALL_OWN} -m 755 ${DESTDIR}${BINDIR}
178 ${INSTALL} ${COPY} ${STRIP_FLAG} ${PROG_INSTALL_OWN} -m ${BINMODE} \
179 ${PROG} ${DESTDIR}${BINDIR}/${PROG_NAME}
180 .endif
181 .if defined(HIDEGAME)
182 (cd ${DESTDIR}/usr/games; rm -f ${PROG}; ln -s dm ${PROG})
183 .endif
184 .endif
186 .include <links.mk>
188 install: maninstall install_links _SUBDIRUSE
190 install_links:
191 .if !empty(SYMLINKS)
192 @set ${SYMLINKS}; ${_SYMLINKS_SCRIPT}
193 .endif
194 .if !empty(LINKS)
195 @set ${LINKS}; ${_LINKS_SCRIPT}
196 .endif
198 maninstall: afterinstall
199 afterinstall: realinstall
200 install_links: realinstall
201 proginstall: beforeinstall
202 realinstall: beforeinstall
203 .endif
205 .NOPATH: ${PROG}
206 .if defined(OBJS) && !empty(OBJS)
207 .NOPATH: ${OBJS}
208 .endif
210 .if defined(FILES) || defined(FILESGROUPS)
211 .include <files.mk>
212 .endif
214 .if ${MK_MAN} != "no"
215 .include <man.mk>
216 .endif
218 .if ${MK_NLS} != "no"
219 .include <nls.mk>
220 .endif
222 BUILDAFTER+= ${PROG} ${OBJS}
224 .include <obj.mk>
225 .include <dep.mk>
226 .include <subdir.mk>
228 .if !empty(PROG) && ${MK_STAGING_PROG} == "yes"
229 STAGE_BINDIR ?= ${STAGE_OBJTOP}${BINDIR}
230 STAGE_DIR.prog ?= ${STAGE_BINDIR}
231 .if ${PROG_NAME:U${PROG}} != ${PROG}
232 STAGE_AS_SETS += prog
233 STAGE_AS_${PROG} = ${PROG_NAME}
234 stage_as.prog: ${PROG}
235 .else
236 STAGE_SETS += prog
237 stage_files.prog: ${PROG}
238 .endif
239 .endif
241 .include <final.mk>
243 .endif