kernel mk: use .PATH instead of SRCS_DIRS
[unleashed.git] / kernel / mk / kmod-build.mk
blob4999ca208fe5a76e0e5ba9700b3730915514f0de
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>
29 .include <${SRCTOP}/Makefile.cfgparam>
31 # prevent kmod.mk inclusion in user's Makefile from setting up confusing targets
32 _KMOD_BUILD=yes
33 .include <${.CURDIR}/Makefile>
35 .include <${SRCTOP}/kernel/mk/defines.mk>
37 CFLAGS = \
38 $(KERNEL_CFLAGS) \
39 $(CERRWARN) \
40 $(INCS:%=-I%) \
41 $(DEFS)
43 LDFLAGS = $(KERNEL_LDFLAGS)
44 .if !empty(MODULE_DEPS)
45 LDFLAGS += -dy $(MODULE_DEPS:%=-N %)
46 .endif
48 # generate all the hard link names even though we may not use it all
49 LINKS=
50 .if !empty(MODULE_TYPE_LINKS)
51 .for type in ${MODULE_TYPE_LINKS}
52 .if !empty(BITS) && ${BITS} == 32
53 LINKS += "/kernel/${MODULE_TYPE}/${MODULE}" \
54 "/kernel/${type}/${MODULE}"
55 .else
56 LINKS += "/kernel/${MODULE_TYPE}/${CONFIG_MACH64}/${MODULE}" \
57 "/kernel/${type}/${CONFIG_MACH64}/${MODULE}"
58 .endif
59 .endfor
60 .endif
62 .OBJDIR: ${.CURDIR}/obj${BITS}
64 OBJS = $(SRCS:%.c=%.o) \
65 $(SRCS$(BITS):%.c=%.o)
67 all: ${MODULE}
69 clean cleandir:
71 .include <links.mk>
73 install:
74 .if !empty(BITS) && ${BITS} == 32
75 $(INS) -d -m 755 "$(DESTDIR)/kernel/${MODULE_TYPE}"
76 $(INS) -m 755 ${MODULE} "$(DESTDIR)/kernel/${MODULE_TYPE}/${MODULE}"
77 .else
78 $(INS) -d -m 755 "$(DESTDIR)/kernel/${MODULE_TYPE}/${CONFIG_MACH64}"
79 $(INS) -m 755 ${MODULE} "$(DESTDIR)/kernel/${MODULE_TYPE}/${CONFIG_MACH64}/${MODULE}"
80 .endif
81 .if !empty(LINKS)
82 @set ${LINKS}; ${_LINKS_SCRIPT}
83 .endif
85 .PHONY: all clean cleandir install
87 install-misc: install-conf install-fw
89 install-conf: ${MODULE_CONF}
90 .if !empty(MODULE_CONF)
91 $(INS) -d -m 755 "$(DESTDIR)/kernel/${MODULE_TYPE}"
92 $(INS) -m 644 ${MODULE_CONF} "$(DESTDIR)/kernel/${MODULE_TYPE}/${MODULE}.conf"
93 .endif
95 install-fw: ${MODULE_FW}
96 .if !empty(MODULE_FW)
97 $(INS) -d -m 755 "$(DESTDIR)/kernel/firmware/${MODULE}"
98 .for x in ${MODULE_FW}
99 $(INS) -m 644 ${x} "$(DESTDIR)/kernel/firmware/${MODULE}"
100 .endfor
101 .endif
103 .PHONY: install-misc install-conf install-fw
105 $(MODULE): $(OBJS)
106 ${QLD}$(LD) $(LDFLAGS) -o ${.TARGET} ${.ALLSRC}
107 ${QCTFCVT}$(CTFCONVERT) -L VERSION ${.TARGET}
109 .SUFFIXES: .o
111 .c.o:
112 @mkdir -p ${.TARGET:H}
113 ${QCC}$(CC) $(CFLAGS) -c -o ${.TARGET} ${.IMPSRC}