]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | # SPDX-License-Identifier: BSD-3-Clause |
2 | # Copyright(c) 2010-2014 Intel Corporation | |
7c673cae FG |
3 | |
4 | ##### if sourced from kernel Kbuild system | |
5 | ifneq ($(KERNELRELEASE),) | |
6 | override EXTRA_CFLAGS = $(MODULE_CFLAGS) $(EXTRA_KERNEL_CFLAGS) | |
7 | obj-m += $(MODULE).o | |
8 | ifneq ($(MODULE),$(notdir $(SRCS-y:%.c=%))) | |
9 | $(MODULE)-objs += $(notdir $(SRCS-y:%.c=%.o)) | |
10 | endif | |
11 | ||
12 | ##### if launched from rte build system | |
13 | else | |
14 | ||
15 | include $(RTE_SDK)/mk/internal/rte.install-pre.mk | |
16 | include $(RTE_SDK)/mk/internal/rte.clean-pre.mk | |
17 | include $(RTE_SDK)/mk/internal/rte.build-pre.mk | |
7c673cae FG |
18 | |
19 | # VPATH contains at least SRCDIR | |
20 | VPATH += $(SRCDIR) | |
21 | ||
22 | _BUILD = $(MODULE).ko | |
23 | _INSTALL = $(INSTALL-FILES-y) $(SYMLINK-FILES-y) \ | |
24 | $(RTE_OUTPUT)/kmod/$(MODULE).ko | |
25 | _CLEAN = doclean | |
26 | ||
27 | SRCS_LINKS = $(addsuffix _link,$(SRCS-y)) | |
28 | ||
29 | compare = $(strip $(subst $(1),,$(2)) $(subst $(2),,$(1))) | |
30 | ||
31 | .PHONY: all | |
32 | all: install | |
33 | ||
34 | .PHONY: install | |
35 | install: build _postinstall | |
36 | ||
37 | _postinstall: build | |
38 | ||
39 | .PHONY: build | |
40 | build: _postbuild | |
41 | ||
42 | # Link all sources in build directory | |
43 | %_link: FORCE | |
44 | $(if $(call compare,$(notdir $*),$*),\ | |
45 | @if [ ! -f $(notdir $(*)) ]; then ln -nfs $(SRCDIR)/$(*) . ; fi,\ | |
46 | @if [ ! -f $(notdir $(*)) ]; then ln -nfs $(SRCDIR)/$(*) . ; fi) | |
47 | ||
48 | # build module | |
49 | $(MODULE).ko: $(SRCS_LINKS) | |
50 | @if [ ! -f $(notdir Makefile) ]; then ln -nfs $(SRCDIR)/Makefile . ; fi | |
51 | @$(MAKE) -C $(RTE_KERNELDIR) M=$(CURDIR) O=$(RTE_KERNELDIR) \ | |
52 | CC="$(KERNELCC)" CROSS_COMPILE=$(CROSS) V=$(if $V,1,0) | |
53 | ||
54 | # install module in $(RTE_OUTPUT)/kmod | |
55 | $(RTE_OUTPUT)/kmod/$(MODULE).ko: $(MODULE).ko | |
56 | @echo INSTALL-MODULE $(MODULE).ko | |
57 | @[ -d $(RTE_OUTPUT)/kmod ] || mkdir -p $(RTE_OUTPUT)/kmod | |
58 | @cp -f $(MODULE).ko $(RTE_OUTPUT)/kmod | |
59 | ||
60 | # install module | |
61 | modules_install: | |
62 | @$(MAKE) -C $(RTE_KERNELDIR) M=$(CURDIR) O=$(RTE_KERNELDIR) \ | |
63 | modules_install | |
64 | ||
65 | .PHONY: clean | |
66 | clean: _postclean | |
67 | ||
68 | # do a make clean and remove links | |
69 | .PHONY: doclean | |
70 | doclean: | |
71 | @if [ ! -f $(notdir Makefile) ]; then ln -nfs $(SRCDIR)/Makefile . ; fi | |
72 | $(Q)$(MAKE) -C $(RTE_KERNELDIR) M=$(CURDIR) O=$(RTE_KERNELDIR) clean | |
73 | @$(foreach FILE,$(SRCS-y) $(SRCS-n) $(SRCS-),\ | |
74 | if [ -h $(notdir $(FILE)) ]; then rm -f $(notdir $(FILE)) ; fi ;) | |
75 | @if [ -h $(notdir Makefile) ]; then rm -f $(notdir Makefile) ; fi | |
76 | @rm -f $(_BUILD_TARGETS) $(_INSTALL_TARGETS) $(_CLEAN_TARGETS) \ | |
77 | $(INSTALL-FILES-all) | |
78 | ||
79 | include $(RTE_SDK)/mk/internal/rte.install-post.mk | |
80 | include $(RTE_SDK)/mk/internal/rte.clean-post.mk | |
81 | include $(RTE_SDK)/mk/internal/rte.build-post.mk | |
7c673cae FG |
82 | |
83 | .PHONY: FORCE | |
84 | FORCE: | |
85 | ||
86 | endif |