Deleted Added
full compact
prog.mk (253883) prog.mk (300313)
1# $Id: prog.mk,v 1.25 2013/07/18 05:46:24 sjg Exp $
1# $Id: prog.mk,v 1.26 2016/03/22 20:45:14 sjg Exp $
2
3.if !target(__${.PARSEFILE}__)
4__${.PARSEFILE}__:
5
6.include <init.mk>
7
8# FreeBSD at least expects MAN8 etc.
9.if defined(MAN) && !empty(MAN)
10_sect:=${MAN:E}
11MAN${_sect}=${MAN}
12.endif
13
14.SUFFIXES: .out .o .c .cc .C .y .l .s .8 .7 .6 .5 .4 .3 .2 .1 .0
15
16CFLAGS+= ${COPTS}
17
18.if ${TARGET_OSNAME} == "NetBSD"
19.if ${MACHINE_ARCH} == "sparc64"
20CFLAGS+= -mcmodel=medlow
21.endif
22
23# ELF platforms depend on crtbegin.o and crtend.o
24.if ${OBJECT_FMT} == "ELF"
25.ifndef LIBCRTBEGIN
26LIBCRTBEGIN= ${DESTDIR}/usr/lib/crtbegin.o
27.MADE: ${LIBCRTBEGIN}
28.endif
29.ifndef LIBCRTEND
30LIBCRTEND= ${DESTDIR}/usr/lib/crtend.o
31.MADE: ${LIBCRTEND}
32.endif
33_SHLINKER= ${SHLINKDIR}/ld.elf_so
34.else
35LIBCRTBEGIN?=
36LIBCRTEND?=
37_SHLINKER= ${SHLINKDIR}/ld.so
38.endif
39
40.ifndef LIBCRT0
41LIBCRT0= ${DESTDIR}/usr/lib/crt0.o
42.MADE: ${LIBCRT0}
43.endif
44.endif # NetBSD
45
46# here is where you can define what LIB* are
47.-include <libnames.mk>
48.if ${MK_DPADD_MK} == "yes"
49# lots of cool magic, but might not suit everyone.
50.include <dpadd.mk>
51.endif
52
53.if ${MK_GPROF} == "yes"
54CFLAGS+= ${CC_PG} ${PROFFLAGS}
55LDADD+= ${CC_PG}
56.if ${MK_DPADD_MK} == "no"
57LDADD_LIBC_P?= -lc_p
58LDADD_LAST+= ${LDADD_LIBC_P}
59.endif
60.endif
61
62.if defined(SHAREDSTRINGS)
63CLEANFILES+=strings
64.c.o:
65 ${CC} -E ${CFLAGS} ${.IMPSRC} | xstr -c -
66 @${CC} ${CFLAGS} -c x.c -o ${.TARGET}
67 @rm -f x.c
68
2
3.if !target(__${.PARSEFILE}__)
4__${.PARSEFILE}__:
5
6.include <init.mk>
7
8# FreeBSD at least expects MAN8 etc.
9.if defined(MAN) && !empty(MAN)
10_sect:=${MAN:E}
11MAN${_sect}=${MAN}
12.endif
13
14.SUFFIXES: .out .o .c .cc .C .y .l .s .8 .7 .6 .5 .4 .3 .2 .1 .0
15
16CFLAGS+= ${COPTS}
17
18.if ${TARGET_OSNAME} == "NetBSD"
19.if ${MACHINE_ARCH} == "sparc64"
20CFLAGS+= -mcmodel=medlow
21.endif
22
23# ELF platforms depend on crtbegin.o and crtend.o
24.if ${OBJECT_FMT} == "ELF"
25.ifndef LIBCRTBEGIN
26LIBCRTBEGIN= ${DESTDIR}/usr/lib/crtbegin.o
27.MADE: ${LIBCRTBEGIN}
28.endif
29.ifndef LIBCRTEND
30LIBCRTEND= ${DESTDIR}/usr/lib/crtend.o
31.MADE: ${LIBCRTEND}
32.endif
33_SHLINKER= ${SHLINKDIR}/ld.elf_so
34.else
35LIBCRTBEGIN?=
36LIBCRTEND?=
37_SHLINKER= ${SHLINKDIR}/ld.so
38.endif
39
40.ifndef LIBCRT0
41LIBCRT0= ${DESTDIR}/usr/lib/crt0.o
42.MADE: ${LIBCRT0}
43.endif
44.endif # NetBSD
45
46# here is where you can define what LIB* are
47.-include <libnames.mk>
48.if ${MK_DPADD_MK} == "yes"
49# lots of cool magic, but might not suit everyone.
50.include <dpadd.mk>
51.endif
52
53.if ${MK_GPROF} == "yes"
54CFLAGS+= ${CC_PG} ${PROFFLAGS}
55LDADD+= ${CC_PG}
56.if ${MK_DPADD_MK} == "no"
57LDADD_LIBC_P?= -lc_p
58LDADD_LAST+= ${LDADD_LIBC_P}
59.endif
60.endif
61
62.if defined(SHAREDSTRINGS)
63CLEANFILES+=strings
64.c.o:
65 ${CC} -E ${CFLAGS} ${.IMPSRC} | xstr -c -
66 @${CC} ${CFLAGS} -c x.c -o ${.TARGET}
67 @rm -f x.c
68
69.cc.o:
69${CXX_SUFFIXES:%=%.o}:
70 ${CXX} -E ${CXXFLAGS} ${.IMPSRC} | xstr -c -
71 @mv -f x.c x.cc
72 @${CXX} ${CXXFLAGS} -c x.cc -o ${.TARGET}
73 @rm -f x.cc
70 ${CXX} -E ${CXXFLAGS} ${.IMPSRC} | xstr -c -
71 @mv -f x.c x.cc
72 @${CXX} ${CXXFLAGS} -c x.cc -o ${.TARGET}
73 @rm -f x.cc
74
75.C.o:
76 ${CXX} -E ${CXXFLAGS} ${.IMPSRC} | xstr -c -
77 @mv -f x.c x.C
78 @${CXX} ${CXXFLAGS} -c x.C -o ${.TARGET}
79 @rm -f x.C
80.endif
81
82
83.if defined(PROG)
84SRCS?= ${PROG}.c
85.for s in ${SRCS:N*.h:N*.sh:M*/*}
86${.o .po .lo:L:@o@${s:T:R}$o@}: $s
87.endfor
88.if !empty(SRCS:N*.h:N*.sh)
89OBJS+= ${SRCS:T:N*.h:N*.sh:R:S/$/.o/g}
90LOBJS+= ${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln}
91.endif
92
93.if defined(OBJS) && !empty(OBJS)
94.NOPATH: ${OBJS} ${PROG} ${SRCS:M*.[ly]:C/\..$/.c/} ${YHEADER:D${SRCS:M*.y:.y=.h}}
95
96# this is known to work for NetBSD 1.6 and FreeBSD 4.2
97.if ${TARGET_OSNAME} == "NetBSD" || ${TARGET_OSNAME} == "FreeBSD"
98_PROGLDOPTS=
99.if ${SHLINKDIR} != "/usr/libexec" # XXX: change or remove if ld.so moves
100_PROGLDOPTS+= -Wl,-dynamic-linker=${_SHLINKER}
101.endif
102.if defined(LIBDIR) && ${SHLIBDIR} != ${LIBDIR}
103_PROGLDOPTS+= -Wl,-rpath-link,${DESTDIR}${SHLIBDIR}:${DESTDIR}/usr/lib \
104 -L${DESTDIR}${SHLIBDIR}
105.endif
106_PROGLDOPTS+= -Wl,-rpath,${SHLIBDIR}:/usr/lib
107
108.if defined(PROG_CXX)
109_CCLINK= ${CXX}
110_SUPCXX= -lstdc++ -lm
111.endif
112.endif # NetBSD
113
114_CCLINK?= ${CC}
115
116.if defined(DESTDIR) && exists(${LIBCRT0}) && ${LIBCRT0} != "/dev/null"
117
118${PROG}: ${LIBCRT0} ${OBJS} ${LIBC} ${DPADD}
119 ${_CCLINK} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} -nostdlib ${_PROGLDOPTS} -L${DESTDIR}/usr/lib ${LIBCRT0} ${LIBCRTBEGIN} ${OBJS} ${LDADD} -L${DESTDIR}/usr/lib ${_SUPCXX} -lgcc -lc -lgcc ${LIBCRTEND}
120
121.else
122
123${PROG}: ${LIBCRT0} ${OBJS} ${LIBC} ${DPADD}
124 ${_CCLINK} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} ${_PROGLDOPTS} ${OBJS} ${LDADD}
125
126.endif # defined(DESTDIR)
127.endif # defined(OBJS) && !empty(OBJS)
128
129.if !defined(MAN)
130MAN= ${PROG}.1
131.endif # !defined(MAN)
132.endif # defined(PROG)
133
134.if !defined(_SKIP_BUILD)
135all: ${PROG}
136.endif
137all: _SUBDIRUSE
138
139.if !target(clean)
140cleanprog:
141 rm -f a.out [Ee]rrs mklog core *.core \
142 ${PROG} ${OBJS} ${LOBJS} ${CLEANFILES}
143
144clean: _SUBDIRUSE cleanprog
145cleandir: _SUBDIRUSE cleanprog
146.else
147cleandir: _SUBDIRUSE clean
148.endif
149
150.if defined(SRCS) && (!defined(MKDEP) || ${MKDEP} != autodep)
151afterdepend: .depend
152 @(TMP=/tmp/_depend$$$$; \
153 sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.ln:/' \
154 < .depend > $$TMP; \
155 mv $$TMP .depend)
156.endif
157
158.if !target(install)
159.if !target(beforeinstall)
160beforeinstall:
161.endif
162.if !target(afterinstall)
163afterinstall:
164.endif
165
166.if !empty(BINOWN)
167PROG_INSTALL_OWN ?= -o ${BINOWN} -g ${BINGRP}
168.endif
169
170.if !target(realinstall)
171realinstall: proginstall
172.endif
173.if !target(proginstall)
174proginstall:
175.if defined(PROG)
176 [ -d ${DESTDIR}${BINDIR} ] || \
177 ${INSTALL} -d ${PROG_INSTALL_OWN} -m 775 ${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
185
186.include <links.mk>
187
188install: maninstall install_links _SUBDIRUSE
189
190install_links:
191.if !empty(SYMLINKS)
192 @set ${SYMLINKS}; ${_SYMLINKS_SCRIPT}
193.endif
194.if !empty(LINKS)
195 @set ${LINKS}; ${_LINKS_SCRIPT}
196.endif
197
198maninstall: afterinstall
199afterinstall: realinstall
200realinstall: beforeinstall
201.endif
202
203.if !target(lint)
204lint: ${LOBJS}
205.if defined(LOBJS) && !empty(LOBJS)
206 @${LINT} ${LINTFLAGS} ${LDFLAGS:M-L*} ${LOBJS} ${LDADD}
207.endif
208.endif
209
210.NOPATH: ${PROG}
211.if defined(OBJS) && !empty(OBJS)
212.NOPATH: ${OBJS}
213.endif
214
215.if ${MK_MAN} != "no"
216.include <man.mk>
217.endif
218
219.if ${MK_NLS} != "no"
220.include <nls.mk>
221.endif
222
223.include <obj.mk>
224.include <dep.mk>
225.include <subdir.mk>
226.include <final.mk>
227
228.endif
74.endif
75
76
77.if defined(PROG)
78SRCS?= ${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)
83OBJS+= ${SRCS:T:N*.h:N*.sh:R:S/$/.o/g}
84LOBJS+= ${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln}
85.endif
86
87.if defined(OBJS) && !empty(OBJS)
88.NOPATH: ${OBJS} ${PROG} ${SRCS:M*.[ly]:C/\..$/.c/} ${YHEADER:D${SRCS:M*.y:.y=.h}}
89
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
101
102.if defined(PROG_CXX)
103_CCLINK= ${CXX}
104_SUPCXX= -lstdc++ -lm
105.endif
106.endif # NetBSD
107
108_CCLINK?= ${CC}
109
110.if defined(DESTDIR) && exists(${LIBCRT0}) && ${LIBCRT0} != "/dev/null"
111
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
115.else
116
117${PROG}: ${LIBCRT0} ${OBJS} ${LIBC} ${DPADD}
118 ${_CCLINK} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} ${_PROGLDOPTS} ${OBJS} ${LDADD}
119
120.endif # defined(DESTDIR)
121.endif # defined(OBJS) && !empty(OBJS)
122
123.if !defined(MAN)
124MAN= ${PROG}.1
125.endif # !defined(MAN)
126.endif # defined(PROG)
127
128.if !defined(_SKIP_BUILD)
129all: ${PROG}
130.endif
131all: _SUBDIRUSE
132
133.if !target(clean)
134cleanprog:
135 rm -f a.out [Ee]rrs mklog core *.core \
136 ${PROG} ${OBJS} ${LOBJS} ${CLEANFILES}
137
138clean: _SUBDIRUSE cleanprog
139cleandir: _SUBDIRUSE cleanprog
140.else
141cleandir: _SUBDIRUSE clean
142.endif
143
144.if defined(SRCS) && (!defined(MKDEP) || ${MKDEP} != autodep)
145afterdepend: .depend
146 @(TMP=/tmp/_depend$$$$; \
147 sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.ln:/' \
148 < .depend > $$TMP; \
149 mv $$TMP .depend)
150.endif
151
152.if !target(install)
153.if !target(beforeinstall)
154beforeinstall:
155.endif
156.if !target(afterinstall)
157afterinstall:
158.endif
159
160.if !empty(BINOWN)
161PROG_INSTALL_OWN ?= -o ${BINOWN} -g ${BINGRP}
162.endif
163
164.if !target(realinstall)
165realinstall: proginstall
166.endif
167.if !target(proginstall)
168proginstall:
169.if defined(PROG)
170 [ -d ${DESTDIR}${BINDIR} ] || \
171 ${INSTALL} -d ${PROG_INSTALL_OWN} -m 775 ${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
179
180.include <links.mk>
181
182install: maninstall install_links _SUBDIRUSE
183
184install_links:
185.if !empty(SYMLINKS)
186 @set ${SYMLINKS}; ${_SYMLINKS_SCRIPT}
187.endif
188.if !empty(LINKS)
189 @set ${LINKS}; ${_LINKS_SCRIPT}
190.endif
191
192maninstall: afterinstall
193afterinstall: realinstall
194realinstall: beforeinstall
195.endif
196
197.if !target(lint)
198lint: ${LOBJS}
199.if defined(LOBJS) && !empty(LOBJS)
200 @${LINT} ${LINTFLAGS} ${LDFLAGS:M-L*} ${LOBJS} ${LDADD}
201.endif
202.endif
203
204.NOPATH: ${PROG}
205.if defined(OBJS) && !empty(OBJS)
206.NOPATH: ${OBJS}
207.endif
208
209.if ${MK_MAN} != "no"
210.include <man.mk>
211.endif
212
213.if ${MK_NLS} != "no"
214.include <nls.mk>
215.endif
216
217.include <obj.mk>
218.include <dep.mk>
219.include <subdir.mk>
220.include <final.mk>
221
222.endif