config: remove unnecessary knobs
[unleashed.git] / kernel / mk / kmod-build.mk
blob5bf9d2b32368f87b69f0b7cf87c03c801ce65f35
2 # Build and install a kernel module
4 # Inputs from user's Makefile:
6 # MODULE - name of the kernel module
7 # MODULE_TYPE - "fs", "drv", etc.
8 # MODULE_TYPE_LINKS - "fs", "drv", etc. which will be hardlinked to
9 # MODULE_TYPE
10 # MODULE_DEPS - dependencies
11 # MODULE_CONF - name of .conf file to install
12 # MODULE_FW - firmware files to install
13 # SRCS - source files
14 # SRCS32 - additional source files (32-bit build only)
15 # SRCS64 - additional source files (64-bit build only)
16 # SRCS_DIRS - additional source directories to search in
17 # INCS - compiler include directives
18 # DEFS - compiler defines (e.g., -DFOO -UBAR)
19 # CERRWARN - compiler error warning args (e.g., -Wno-parentheses)
21 # Additionally, we get the following values from kmod.mk:
23 # BITS - should we build a 32-bit or a 64-bit binary
24 # SRCTOP - root of the repository
27 .include <unleashed.mk>
28 .include <init.mk>
30 .include <${SRCTOP}/cfgparam.mk>
32 # prevent kmod.mk inclusion in user's Makefile from setting up confusing targets
33 _KMOD_BUILD=yes
34 .include <${.CURDIR}/Makefile>
36 .include <${SRCTOP}/kernel/mk/defines.mk>
39 CFLAGS = \
40 ${KERNEL_CFLAGS} \
41 ${CERRWARN} \
42 ${INCS:%=-I%} \
43 ${DEFS}
45 LDFLAGS = ${KERNEL_LDFLAGS}
46 .if !empty(MODULE_DEPS)
47 LDFLAGS += -dy ${MODULE_DEPS:%=-N %}
48 .endif
50 # generate all the hard link names even though we may not use it all
51 LINKS=
52 .if !empty(MODULE_TYPE_LINKS)
53 .for type in ${MODULE_TYPE_LINKS}
54 LINKS += "/kernel/${MODULE_TYPE}/${MODULE}" \
55 "/kernel/${type}/${MODULE}"
56 .endfor
57 .endif
59 .OBJDIR: ${.CURDIR}/obj${BITS}
61 OBJS = ${SRCS:%.c=%.o} \
62 ${SRCS${BITS}:%.c=%.o}
64 all: ${MODULE}
66 clean cleandir:
68 .include <links.mk>
70 install:
71 ${INSTALL} -d -m 755 "${DESTDIR}/kernel/${MODULE_TYPE}"
72 ${INSTALL} -m 755 ${MODULE} "${DESTDIR}/kernel/${MODULE_TYPE}/${MODULE}"
73 .if !empty(LINKS)
74 @set ${LINKS}; ${_LINKS_SCRIPT}
75 .endif
77 .PHONY: all clean cleandir install
79 install-misc: install-conf install-fw
81 install-conf: ${MODULE_CONF}
82 .if !empty(MODULE_CONF)
83 ${INSTALL} -d -m 755 "${DESTDIR}/kernel/${MODULE_TYPE}"
84 ${INSTALL} -m 644 ${MODULE_CONF} "${DESTDIR}/kernel/${MODULE_TYPE}/${MODULE}.conf"
85 .endif
87 install-fw: ${MODULE_FW}
88 .if !empty(MODULE_FW)
89 ${INSTALL} -d -m 755 "${DESTDIR}/kernel/firmware/${MODULE}"
90 .for x in ${MODULE_FW}
91 ${INSTALL} -m 644 ${x} "${DESTDIR}/kernel/firmware/${MODULE}"
92 .endfor
93 .endif
95 .PHONY: install-misc install-conf install-fw
97 ${MODULE}: ${OBJS}
98 ${LD} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC}
99 ${CTFCONVERT} -L VERSION ${.TARGET}
101 .SUFFIXES: .o
103 .c.o:
104 @mkdir -p ${.TARGET:H}
105 ${CC} ${CFLAGS} -c -o ${.TARGET} ${.IMPSRC}