include: reduce default stack size
[minix.git] / share / mk / bsd.kmodule.mk
blobee8aa573ea9924083a51b2544b025f19d19e9ea1
1 # $NetBSD: bsd.kmodule.mk,v 1.37 2012/08/10 16:34:23 joerg Exp $
3 # We are not building this with PIE
4 MKPIE=no
6 .include <bsd.init.mk>
7 .include <bsd.klinks.mk>
8 .include <bsd.sys.mk>
10 ##### Basic targets
11 realinstall: kmodinstall
13 KERN= $S/kern
15 CFLAGS+= -ffreestanding ${COPTS}
16 CPPFLAGS+= -nostdinc -I. -I${.CURDIR} -isystem $S -isystem $S/arch
17 CPPFLAGS+= -isystem ${S}/../common/include
18 CPPFLAGS+= -D_KERNEL -D_LKM -D_MODULE -DSYSCTL_INCLUDE_DESCR
20 # XXX until the kernel is fixed again...
21 CFLAGS+= -fno-strict-aliasing -Wno-pointer-sign
23 # XXX This is a workaround for platforms that have relative relocations
24 # that, when relocated by the module loader, result in addresses that
25 # overflow the size of the relocation (e.g. R_PPC_REL24 in powerpc).
26 # The real solution to this involves generating trampolines for those
27 # relocations inside the loader and removing this workaround, as the
28 # resulting code would be much faster.
29 .if ${MACHINE_CPU} == "arm"
30 CFLAGS+= -mlong-calls
31 .elif ${MACHINE_CPU} == "powerpc"
32 CFLAGS+= -mlongcall
33 .elif ${MACHINE_CPU} == "vax"
34 CFLAGS+= -fno-pic
35 .endif
37 # evbppc needs some special help
38 .if ${MACHINE} == "evbppc"
40 . ifndef PPC_INTR_IMPL
41 PPC_INTR_IMPL=\"powerpc/intr.h\"
42 . endif
43 . ifndef PPC_PCI_MACHDEP_IMPL
44 PPC_PCI_MACHDEP_IMPL=\"powerpc/pci_machdep.h\"
45 . endif
46 CPPFLAGS+= -DPPC_INTR_IMPL=${PPC_INTR_IMPL}
47 CPPFLAGS+= -DPPC_PCI_MACHDEP_IMPL=${DPPC_PCI_MACHDEP_IMPL}
49 . ifdef PPC_IBM4XX
50 CPPFLAGS+= -DPPC_IBM4XX
51 . elifdef PPC_BOOKE
52 CPPFLAGS+= -DPPC_BOOKE
53 . else
54 CPPFLAGS+= -DPPC_OEA
55 . endif
57 .endif
60 _YKMSRCS= ${SRCS:M*.[ly]:C/\..$/.c/} ${YHEADER:D${SRCS:M*.y:.y=.h}}
61 DPSRCS+= ${_YKMSRCS}
62 CLEANFILES+= ${_YKMSRCS}
64 .if exists($S/../sys/modules/xldscripts/kmodule)
65 KMODSCRIPT= $S/../sys/modules/xldscripts/kmodule
66 .else
67 KMODSCRIPT= ${DESTDIR}/usr/libdata/ldscripts/kmodule
68 .endif
70 PROG?= ${KMOD}.kmod
72 ##### Build rules
73 realall: ${PROG}
75 .if (defined(USE_COMBINE) && ${USE_COMBINE} != "no" && !commands(${_P}) \
76 && !defined(NOCOMBINE.${_P}) && !defined(NOCOMBINE))
77 .for f in ${SRCS:N*.h:N*.sh:N*.fth:C/\.[yl]$/.c/g}
78 .if (${CPPFLAGS.$f:D1} == "1" || ${CPUFLAGS.$f:D2} == "2" \
79 || ${COPTS.$f:D3} == "3" || ${OBJCOPTS.$f:D4} == "4" \
80 || ${CXXFLAGS.$f:D5} == "5") \
81 || ("${f:M*.[cyl]}" == "" || commands(${f:R:S/$/.o/}))
82 XOBJS+= ${f:R:S/$/.o/}
83 .else
84 XSRCS+= ${f}
85 NODPSRCS+= ${f}
86 .endif
87 .endfor
89 .if !empty(XOBJS)
90 ${XOBJS}: ${DPSRCS}
91 .endif
93 ${PROG}: ${XOBJS} ${XSRCS} ${DPSRCS} ${DPADD}
94 ${_MKTARGET_LINK}
95 ${CC} ${LDFLAGS} -nostdlib -MD -combine -r -Wl,-T,${KMODSCRIPT},-d \
96 -o ${.TARGET} ${CFLAGS} ${CPPFLAGS} ${XOBJS} \
97 ${XSRCS:@.SRC.@${.ALLSRC:M*.c:M*${.SRC.}}@:O:u} && \
98 echo '.-include "${KMOD}.d"' > .depend
100 .else
101 OBJS+= ${SRCS:N*.h:N*.sh:R:S/$/.o/g}
103 ${OBJS} ${LOBJS}: ${DPSRCS}
105 ${PROG}: ${OBJS} ${DPADD}
106 ${_MKTARGET_LINK}
107 ${CC} ${LDFLAGS} -nostdlib -r -Wl,-T,${KMODSCRIPT},-d \
108 -o ${.TARGET} ${OBJS}
109 .endif
111 ##### Install rules
112 .if !target(kmodinstall)
113 .if !defined(KMODULEDIR)
114 _OSRELEASE!= ${HOST_SH} $S/conf/osrelease.sh -k
115 # Ensure these are recorded properly in METALOG on unprived installes:
116 KMODULEARCHDIR?= ${MACHINE}
117 _INST_DIRS= ${DESTDIR}/stand/${KMODULEARCHDIR}
118 _INST_DIRS+= ${DESTDIR}/stand/${KMODULEARCHDIR}/${_OSRELEASE}
119 _INST_DIRS+= ${DESTDIR}/stand/${KMODULEARCHDIR}/${_OSRELEASE}/modules
120 KMODULEDIR= ${DESTDIR}/stand/${KMODULEARCHDIR}/${_OSRELEASE}/modules/${KMOD}
121 .endif
122 _PROG:= ${KMODULEDIR}/${PROG} # installed path
124 .if ${MKUPDATE} == "no"
125 ${_PROG}! ${PROG} # install rule
126 .if !defined(BUILD) && !make(all) && !make(${PROG})
127 ${_PROG}! .MADE # no build at install
128 .endif
129 .else
130 ${_PROG}: ${PROG} # install rule
131 .if !defined(BUILD) && !make(all) && !make(${PROG})
132 ${_PROG}: .MADE # no build at install
133 .endif
134 .endif
135 ${_MKTARGET_INSTALL}
136 dirs=${_INST_DIRS:Q}; \
137 for d in $$dirs; do \
138 ${INSTALL_DIR} $$d; \
139 done
140 ${INSTALL_DIR} ${KMODULEDIR}
141 ${INSTALL_FILE} -o ${KMODULEOWN} -g ${KMODULEGRP} -m ${KMODULEMODE} \
142 ${.ALLSRC} ${.TARGET}
144 kmodinstall:: ${_PROG}
145 .PHONY: kmodinstall
146 .PRECIOUS: ${_PROG} # keep if install fails
148 .undef _PROG
149 .endif # !target(kmodinstall)
151 ##### Clean rules
152 CLEANFILES+= a.out [Ee]rrs mklog core *.core ${PROG} ${OBJS} ${LOBJS}
154 ##### Custom rules
155 lint: ${LOBJS}
156 .if defined(LOBJS) && !empty(LOBJS)
157 ${LINT} ${LINTFLAGS} ${LDFLAGS:C/-L[ ]*/-L/Wg:M-L*} ${LOBJS} ${LDADD}
158 .endif
160 ##### Pull in related .mk logic
161 LINKSOWN?= ${KMODULEOWN}
162 LINKSGRP?= ${KMODULEGRP}
163 LINKSMODE?= ${KMODULEMODE}
164 .include <bsd.man.mk>
165 .include <bsd.links.mk>
166 .include <bsd.dep.mk>
167 .include <bsd.clean.mk>
169 .-include "$S/arch/${MACHINE_CPU}/include/Makefile.inc"
170 .-include "$S/arch/${MACHINE}/include/Makefile.inc"