1 ###############################################################################
4 # @brief Kbuild for compiling linux drivers
6 # @author Yury GEORGIEVSKIY, CERN.
8 # @date Created on 08/04/2009
10 ###############################################################################
12 # Include specific Makefile to get driver configuraion settings
13 # Makefile from current directory supress one from upper level
14 include $(shell if [ -e $(M)/Makefile.specific ]; then \
15 echo $(M)/Makefile.specific; \
17 echo $(M)/../Makefile.specific; \
20 # Include generic definitions
21 include $(ROOTDIR)/makefiles/Kbuild.include
23 # Ensure lowecase drivername
24 DRIVER_NAME := $(shell echo $(DRIVER_NAME) | tr "[:upper:]" "[:lower:]")
26 CDCM_INC_DIR := $(ROOTDIR)
27 CDCM_D := $(ROOTDIR)/cdcm
30 CDCM_D_REL := $(call abs2rel, $(CDCM_D)/$(CPU)/$(KVER)/, $(M)/)
31 UTIL_D_REL := $(call abs2rel, $(ROOTDIR)/utils/driver/$(CPU)/$(KVER)/, $(M)/)
33 # Extra CC flags && needed pathes
34 # -I$(ROOTDIR) - This dir is not included directly because user can use it's
36 # Not using [ccflags-y] _ONLY_ to be able to compile with 2.6.9
37 # [ccflags-y] should be used when 2.6.9 is not used anymore
42 -I$(ROOTDIR)/skel/driver \
43 -I$(ROOTDIR)/utils/driver \
45 -DDRIVER_NAME=\"$(DRIVER_NAME)\" \
47 -DCOMPILE_TIME=$(shell date --utc +%s)
49 # What we need to build
50 obj-m := $(DRIVER_NAME).o
52 # Virgin driver (without any extra features) consists of _all_ '*.c'
53 #+ files in './driver' directory.
54 #+ User can already add some extra src files to compile in specific Kbuild
55 $(DRIVER_NAME)-y := $(OBJFILES)
57 # Took examples from xtensa/boot/lib
58 # Copy extra *.c files into local dir for compilation
59 quiet_cmd_copy_xtraf = COPY $@
60 cmd_copy_xtraf = cat $< > $@
62 # Remove already compiled extra *.c files from local dir
63 quiet_cmd_remove_xtraf = RM $<
64 cmd_remove_xtraf = rm -f $<
66 # User can define extra *.c files to compile driver
68 xtra = $(addsuffix $(SRCSFXS), $(notdir $(basename $(XTRA_DSRC))))
70 $(addprefix $(obj)/,$(xtra)): $(obj)/%: $(addsuffix %, $(dir $(XTRA_DSRC)))
71 $(call cmd,copy_xtraf)
73 $(DRIVER_NAME)-y += $(xtra:.c=.o)
75 $(addprefix $(obj)/,$(xtra:.c=.o)): %.o: %.c
76 $(call if_changed_rule,cc_o_c)
77 $(call cmd,remove_xtraf)
80 # If driver is 'skel' compliant?
84 SKEL_D = $(ROOTDIR)/skel/driver
86 # Get all *.c files from there
87 SKELSRCF = $(wildcard $(SKEL_D)/*.c)
89 # Kill all ',backup' files
90 FLTSKELFILES = $(filter-out $(SKEL_D)/$(comma)%, $(filter $(addprefix %, $(SRCSFXS)),$(SKELSRCF)))
92 # Final list of 'skel' *.c files
93 skel = $(addsuffix $(SRCSFXS),$(notdir $(basename $(FLTSKELFILES))))
95 # We copy 'skel' *.c files locally for compilation
96 # Check 'Static Pattern Rules' in makefile manual
97 $(addprefix $(obj)/,$(skel)): $(obj)/%: $(SKEL_D)/%
98 $(call cmd,copy_xtraf)
100 $(DRIVER_NAME)-y += $(skel:.c=.o)
102 # Should redefine .o compilation rule as skel *.c
103 #+ files should be removed after compilation
104 $(addprefix $(obj)/,$(skel:.c=.o)): %.o: %.c
105 $(call if_changed_rule,cc_o_c)
106 $(call cmd,remove_xtraf)
108 # 'skel' is CDCM compliant with VME && PCI bus support, using XML library
115 quiet_cmd_copy_symvers = COPY $@
116 cmd_copy_symvers = cat $^ > $@
118 # We need to copy 'vmebus' Module.symvers file locally to get
119 # rid of compilation warnings.
121 # $(extra-y) and $(targets) is _not_ working here
122 ifneq ($(DEP_SYMVERS),)
123 always += Module.symvers
126 # Copy .symvers files locally
127 $(obj)/Module.symvers: $(addsuffix /driver/$(CPU)/$(KVER)/Module.symvers, $(DEP_SYMVERS))
128 $(call cmd,copy_symvers)
133 ifeq ($(CONFIG_BUS_VME),y)
134 ccflags-y += -DCONFIG_BUS_VME
136 cdcmvme-$(CONFIG_BUS_VME) += cdcmVme.o
138 ccflags-y += -UCONFIG_BUS_VME
139 endif # CONFIG_BUS_VME
142 ifeq ($(CONFIG_BUS_PCI), y)
143 ccflags-y += -DCONFIG_BUS_PCI
144 cdcmpci-$(CONFIG_BUS_PCI) += cdcmPci.o cdcmPciDmaLinux.o
146 ccflags-y += -UCONFIG_BUS_PCI
147 endif # CONFIG_BUS_PCI
149 # This driver was generated by driverGen
150 ifeq ($(CONFIG_IS_DG),y)
151 ccflags-y += -DCONFIG_IS_DG
152 dgpci-$(CONFIG_BUS_PCI) = cdcm-driver-gen-pci.o
153 dgvme-$(CONFIG_BUS_VME) = cdcm-driver-gen-vme.o
154 dg-$(CONFIG_IS_DG) = $(dgpci-y) $(dgvme-y)
158 cdcm-$(IS_CDCM) := $(addprefix $(CDCM_D_REL), \
159 cdcmBoth.o cdcmDrvr.o cdcmLynxAPI.o \
160 cdcmMem.o cdcmThread.o cdcmTime.o \
161 $(cdcmvme-y) $(cdcmpci-y) $(dg-y))
163 # Major driver Utilities
164 utils-$(USE_UTILS) := $(addprefix $(UTIL_D_REL), drvr_load_file.o drvr_utils.o)
166 # Extra driver utilities
167 xml-$(USE_XML) := $(addprefix $(UTIL_D_REL), libinstkernel.o)
168 plx9030-$(USE_PLX9030) := $(addprefix $(UTIL_D_REL), plx9030.o)
169 plx9656-$(USE_PLX9656) := $(addprefix $(UTIL_D_REL), plx9656.o)
171 # Build-up final version with extra things for the driver
172 $(DRIVER_NAME)-y += $(cdcm-y) $(utils-y) $(xml-y) $(plx9030-y) $(plx9656-y)