getconf: don't include xpg4 bits, gcc7 includes xpg6 bits for us
[unleashed.git] / share / mk / prog.mk
blobb2339cb5e4998840e539c5928c677c468deeed9d
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}
115 .else
117 ${PROG}: ${OBJS} ${LIBC} ${DPADD}
118 ${_CCLINK} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} ${_PROGLDOPTS} ${OBJS} ${LDADD}
120 .endif # defined(DESTDIR)
121 .endif # defined(OBJS) && !empty(OBJS)
123 .if !defined(MAN)
124 MAN= ${PROG}.1
125 .endif # !defined(MAN)
126 .endif # defined(PROG)
128 .if !defined(_SKIP_BUILD)
129 realbuild: ${PROG}
130 .endif
132 all: _SUBDIRUSE
134 .if !target(clean)
135 cleanprog:
136 rm -f a.out [Ee]rrs mklog core *.core \
137 ${PROG} ${OBJS} ${LOBJS} ${CLEANFILES}
139 clean: _SUBDIRUSE cleanprog
140 cleandir: _SUBDIRUSE cleanprog
141 .else
142 cleandir: _SUBDIRUSE clean
143 .endif
145 .if defined(SRCS) && (!defined(MKDEP) || ${MKDEP} != autodep)
146 afterdepend: .depend
147 @(TMP=/tmp/_depend$$$$; \
148 sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.ln:/' \
149 < .depend > $$TMP; \
150 mv $$TMP .depend)
151 .endif
153 .if !target(install)
154 .if !target(beforeinstall)
155 beforeinstall:
156 .endif
157 .if !target(afterinstall)
158 afterinstall:
159 .endif
161 .if !empty(BINOWN)
162 PROG_INSTALL_OWN ?= -o ${BINOWN} -g ${BINGRP}
163 .endif
165 .if !target(realinstall)
166 realinstall: proginstall
167 .endif
168 .if !target(proginstall)
169 proginstall:
170 .if defined(PROG)
171 ${INSTALL} -d ${PROG_INSTALL_OWN} -m 755 ${DESTDIR}${BINDIR}
172 ${INSTALL} ${COPY} ${STRIP_FLAG} ${PROG_INSTALL_OWN} -m ${BINMODE} \
173 ${PROG} ${DESTDIR}${BINDIR}/${PROG_NAME}
174 .endif
175 .if defined(HIDEGAME)
176 (cd ${DESTDIR}/usr/games; rm -f ${PROG}; ln -s dm ${PROG})
177 .endif
178 .endif
180 .include <links.mk>
182 install: maninstall install_links _SUBDIRUSE
184 install_links:
185 .if !empty(SYMLINKS)
186 @set ${SYMLINKS}; ${_SYMLINKS_SCRIPT}
187 .endif
188 .if !empty(LINKS)
189 @set ${LINKS}; ${_LINKS_SCRIPT}
190 .endif
192 maninstall: afterinstall
193 afterinstall: realinstall
194 install_links: realinstall
195 proginstall: beforeinstall
196 realinstall: beforeinstall
197 .endif
199 .NOPATH: ${PROG}
200 .if defined(OBJS) && !empty(OBJS)
201 .NOPATH: ${OBJS}
202 .endif
204 .if defined(FILES) || defined(FILESGROUPS)
205 .include <files.mk>
206 .endif
208 .if ${MK_MAN} != "no"
209 .include <man.mk>
210 .endif
212 .if ${MK_NLS} != "no"
213 .include <nls.mk>
214 .endif
216 BUILDAFTER+= ${PROG} ${OBJS}
218 .include <obj.mk>
219 .include <dep.mk>
220 .include <subdir.mk>
222 .if !empty(PROG) && ${MK_STAGING_PROG} == "yes"
223 STAGE_BINDIR ?= ${STAGE_OBJTOP}${BINDIR}
224 STAGE_DIR.prog ?= ${STAGE_BINDIR}
225 .if ${PROG_NAME:U${PROG}} != ${PROG}
226 STAGE_AS_SETS += prog
227 STAGE_AS_${PROG} = ${PROG_NAME}
228 stage_as.prog: ${PROG}
229 .else
230 STAGE_SETS += prog
231 stage_files.prog: ${PROG}
232 .endif
233 .endif
235 .include <final.mk>
237 .endif