1#	$NetBSD: bsd.klinks.mk,v 1.13 2014/08/10 05:57:31 matt Exp $
2#
3
4.include <bsd.own.mk>
5
6KLINK_MACHINE?=	${MACHINE}
7
8##### Default values
9.if !defined(S)
10.if defined(NETBSDSRCDIR)
11S=	${NETBSDSRCDIR}/sys
12.elif defined(BSDSRCDIR)
13S=	${BSDSRCDIR}/sys
14.else
15S=	/sys
16.endif
17.endif
18
19CLEANFILES+=	machine ${MACHINE_CPU} ${KLINK_MACHINE}
20.if ${KLINK_MACHINE} == "sun2" || ${KLINK_MACHINE} == "sun3"
21CLEANFILES+=	sun68k
22.elif ${KLINK_MACHINE} == "sparc64"
23CLEANFILES+=	sparc
24.elif ${KLINK_MACHINE} == "i386"
25CLEANFILES+=	x86
26.elif ${KLINK_MACHINE} == "amd64"
27CLEANFILES+=	x86 i386
28.elif ${KLINK_MACHINE} == "evbmips"
29CLEANFILES+=	algor sbmips
30.elif ${MACHINE_CPU} == "aarch64"
31CLEANFILES+=	arm
32.endif
33
34.if defined(XEN_BUILD) || ${KLINK_MACHINE} == "xen"
35CLEANFILES+=	xen xen-ma/machine # xen-ma
36CPPFLAGS+=	-I${.OBJDIR}/xen-ma
37.if ${MACHINE_CPU} == "i386"
38CLEANFILES+=	x86
39.endif
40.endif
41
42# XXX.  This should be done a better way.  It's @'d to reduce visual spew.
43# XXX   .BEGIN is used to make sure the links are done before anything else.
44.if !make(obj) && !make(clean) && !make(cleandir)
45.BEGIN:
46	-@rm -f machine && \
47	    ln -s $S/arch/${KLINK_MACHINE}/include machine
48	-@rm -f ${KLINK_MACHINE} && \
49	    ln -s $S/arch/${KLINK_MACHINE}/include ${KLINK_MACHINE}
50	-@if [ -d $S/arch/${MACHINE_CPU} ]; then \
51	    rm -f ${MACHINE_CPU} && \
52	    ln -s $S/arch/${MACHINE_CPU}/include ${MACHINE_CPU}; \
53	 fi
54# XXX. it gets worse..
55.if ${KLINK_MACHINE} == "sun2" || ${KLINK_MACHINE} == "sun3"
56	-@rm -f sun68k && \
57	    ln -s $S/arch/sun68k/include sun68k
58.endif
59.if ${KLINK_MACHINE} == "sparc64"
60	-@rm -f sparc && \
61	    ln -s $S/arch/sparc/include sparc
62.endif
63.if ${KLINK_MACHINE} == "amd64"
64	-@rm -f i386 && \
65	    ln -s $S/arch/i386/include i386
66.endif
67.if ${MACHINE_CPU} == "i386" || ${MACHINE_CPU} == "x86_64"
68	-@rm -f x86 && \
69	    ln -s $S/arch/x86/include x86
70.endif
71.if ${MACHINE_CPU} == "aarch64"
72	-@rm -f arm && \
73	    ln -s $S/arch/arm/include arm
74.endif
75.if defined(XEN_BUILD) || ${KLINK_MACHINE} == "xen"
76	-@rm -f xen && \
77	    ln -s $S/arch/xen/include xen
78	-@rm -rf xen-ma && mkdir xen-ma && \
79	    ln -s ../${XEN_BUILD:U${MACHINE_ARCH}} xen-ma/machine
80.endif
81.if ${KLINK_MACHINE} == "evbmips"
82	-@rm -f algor && \
83	    ln -s $S/arch/algor/include algor
84	-@rm -f sbmips && \
85	    ln -s $S/arch/sbmips/include sbmips
86.endif
87.endif
88