Add Makefile support for host programs (.nx) just like we support normal
[dragonfly.git] / share / mk / bsd.hostprog.mk
1 # $DragonFly: src/share/mk/bsd.hostprog.mk,v 1.1 2004/06/10 10:31:29 joerg Exp $
2
3 .include <bsd.init.mk>
4
5 .SUFFIXES: .out .nx .no .c .cc .cpp .cxx .C .m .y .l .s .S
6
7 .if defined(PROG_CXX)
8 PROG=   ${PROG_CXX}
9 .endif
10
11 .if !defined(SRCS)
12 .if defined(PROG_CXX)
13 SRCS=   ${PROG}.cc
14 .else
15 SRCS=   ${PROG}.c
16 .endif
17 .endif
18
19 all: objwarn ${PROG}.nx
20
21 .if defined(PROG)
22
23 # If there are Objective C sources, link with Objective C libraries.
24 .if ${SRCS:M*.m} != ""
25 OBJCLIBS?= -lobjc
26 LDADD+= ${OBJCLIBS}
27 .endif
28
29 OBJS+=  ${SRCS:N*.h:N*.patch:R:S/$/.no/g}
30 _PATCHES= ${SRCS:M*.patch}
31 .for _PATCH in ${SRCS:T:N*.h.patch:M*.patch}
32 .for _OBJ in ${_PATCH:R:R:S/$/.no/}
33 OBJS:=  ${OBJS:N${_OBJ}} ${_OBJ}
34 .endfor
35 .endfor
36 .undef _PATCHES
37
38 ${PROG}.nx: ${OBJS}
39 .if defined(PROG_CXX)
40         ${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
41 .else
42         ${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
43 .endif
44 .endif
45
46 CLEANFILES+= ${PROG}.nx ${OBJS}
47
48 all: ${PROG}.nx
49
50 _EXTRADEPEND:
51         echo ${PROG}.nx: ${LIBC} ${DPADD} >> ${DEPENDFILE}
52 .if defined(PROG_CXX)
53         echo ${PROG}.nx: ${LIBSTDCPLUSPLUS} >> ${DEPENDFILE}
54 .endif
55
56 .include <bsd.dep.mk>
57
58 .if defined(PROG) && !exists(${.OBJDIR}/${DEPENDFILE})
59 ${OBJS}: ${SRCS:M*.h}
60 .endif
61
62 .include <bsd.obj.mk>
63
64 .include <bsd.sys.mk>