Home | History | Annotate | Download | only in linux
      1 
      2 # GNU Makefile for Broadcom Dongle Host Driver
      3 #
      4 # Copyright (C) 1999-2010, Broadcom Corporation
      5 # 
      6 #      Unless you and Broadcom execute a separate written software license
      7 # agreement governing use of this software, this software is licensed to you
      8 # under the terms of the GNU General Public License version 2 (the "GPL"),
      9 # available at http://www.broadcom.com/licenses/GPLv2.php, with the
     10 # following added to such license:
     11 # 
     12 #      As a special exception, the copyright holders of this software give you
     13 # permission to link this software with independent modules, and to copy and
     14 # distribute the resulting executable under terms of your choice, provided that
     15 # you also meet, for each linked independent module, the terms and conditions of
     16 # the license of that module.  An independent module is a module which is not
     17 # derived from this software.  The special exception does not apply to any
     18 # modifications of the software.
     19 # 
     20 #      Notwithstanding the above, under no circumstances may you combine this
     21 # software in any way with any other Broadcom software provided under a license
     22 # other than the GPL, without Broadcom's express prior written consent.
     23 #
     24 # $Id: Makefile,v 1.55.2.6.2.10.6.42 2010/08/20 00:15:16 Exp $
     25 #
     26 
     27 # Try a couple of places for LINUXDIR if not specified
     28 ifeq ($(LINUXDIR),)
     29 ifeq ($(LINUXVER),)
     30 # Neither one is specified, use uname for version
     31 LINUXVER := $(shell uname -r)
     32 endif
     33 ifneq ($(wildcard /lib/modules/$(LINUXVER)/build/include/linux/version.h),)
     34 LINUXDIR := /lib/modules/$(LINUXVER)/build
     35 else
     36 ifneq ($(wildcard /tools/linux/src/linux-$(LINUXVER)/include/linux/version.h),)
     37 LINUXDIR := /tools/linux/src/linux-$(LINUXVER)
     38 else
     39 LINUXDIR := /usr/src/linux
     40 endif
     41 endif
     42 endif
     43 
     44 # Derive LINUXVER from LINUXDIR
     45 MYKERNEL_RELEASE_KEYWORD:="KERNELRELEASE[[:space:]]*=.*kernel.release"
     46 MYKERNEL_DEFINITION:=$(if \
     47   $(shell grep $(MYKERNEL_RELEASE_KEYWORD) $(LINUXDIR)/Makefile 2> /dev/null),\
     48   grep $(MYKERNEL_RELEASE_KEYWORD) $(LINUXDIR)/Makefile,\
     49   cat $(LINUXDIR)/Makefile)
     50 
     51 LINUXVER:=$(shell ($(MYKERNEL_DEFINITION); echo "show_kernel_version_number$$$$:;@echo \$$(KERNELRELEASE)") 2> /dev/null | $(MAKE) --no-print-directory -k -C $(LINUXDIR) MYUNAME="" -f - show_kernel_version_number$$$$ 2> /dev/null)
     52 
     53 ifeq ($(LINUXVER),)
     54      $(error LINUXVER=$(LINUXVER) is empty)
     55 endif # LINUXVER
     56 
     57 $(warning Found LINUXVER=$(LINUXVER))
     58 $(warning Found LINUXDIR=$(LINUXDIR))
     59 
     60 # check if 2.4 kernel or 2.5+ kernel
     61 BCM_KVER:=$(shell echo $(LINUXVER) | cut -c1-3 | sed 's/2\.[56]/2\.6/')
     62 
     63 # Allow CROSS_COMPILE to specify compiler base
     64 CC := $(CROSS_COMPILE)gcc
     65 LD := $(CROSS_COMPILE)ld
     66 NM := $(CROSS_COMPILE)nm
     67 OBJCOPY := $(CROSS_COMPILE)objcopy
     68 
     69 # driver source base and C file path
     70 ifeq ($(SRCBASE),)
     71 SRCBASE := $(shell /bin/pwd)/../..
     72 endif
     73 vpath %.c $(SRCBASE)/dhd/sys $(SRCBASE)/shared $(SRCBASE)/bcmsdio/sys $(SRCBASE)/wl/sys $(SRCBASE)/crypto
     74 
     75 ## Initialize DFLAGS
     76 DFLAGS :=
     77 
     78 
     79 # basic options (defines in DFLAGS, includes in IFLAGS)
     80 DFLAGS += -DLINUX -DSRCBASE=\"$(SRCBASE)\" -DBCMDRIVER -DBCMDONGLEHOST -DDHDTHREAD -DBCMWPA2 -DBCMWAPI_WPI
     81 DFLAGS += -DUNRELEASEDCHIP
     82 ifeq ($(BCMQT),1)
     83 	DFLAGS += -DBCMSLTGT -DBCMQT
     84 endif
     85 ifeq ($(WLTEST),1)
     86 	DFLAGS += -DWLTEST -DIOCTL_RESP_TIMEOUT=20000
     87 	DFLAGS += -DDHD_SPROM
     88 endif
     89 
     90 
     91 # Past 2.6.29 kernels, arch specific bits are re-organized in linux kernel. So
     92 # append new include paths to existing ones to get 2.6.29+ kernels compile
     93 
     94 # Default DHDARCH is x86
     95 ifdef ARCH
     96    DHDARCH ?= $(ARCH)
     97 else
     98    DHDARCH ?= x86
     99 endif
    100 
    101 ifneq ($(findstring native,$(TARGET)),)
    102    DHDARCH = x86
    103 endif
    104 ifneq ($(findstring mips,$(TARGET)),)
    105    DHDARCH = mips
    106 endif
    107 ifneq ($(findstring arm,$(TARGET)),)
    108    DHDARCH = arm
    109 endif
    110 
    111 # First include from linux kernel dirs
    112 IFLAGS := -I$(LINUXDIR)/include 
    113 IFLAGS += -I$(LINUXDIR)/include/asm/mach-default 
    114 # Followed by 2.6.29+ specific paths
    115 IFLAGS += -I$(LINUXDIR)/arch/$(DHDARCH)/include
    116 IFLAGS += -I$(LINUXDIR)/arch/$(DHDARCH)/include/asm/mach-default
    117 
    118 # From current workspace
    119 IFLAGS += -I. 
    120 IFLAGS += -I$(SRCBASE)/include 
    121 IFLAGS += -I$(SRCBASE)/shared 
    122 IFLAGS += -I$(SRCBASE)/dhd/sys 
    123 IFLAGS += -I$(SRCBASE)/dongle 
    124 IFLAGS += -I$(SRCBASE)/wl/sys
    125 
    126 ifneq ($(wildcard $(LINUXDIR)/.config),)
    127 include $(LINUXDIR)/.config
    128 else
    129 # This is dangerous, since we don't know if they are really configured.
    130 CONFIG_WIRELESS_EXT=y
    131 DFLAGS += -DCONFIG_WIRELESS_EXT
    132 endif
    133 
    134 ifeq ($(CONFIG_MMC_MSM7X00A),y)
    135 DFLAGS += -Dlinux
    136 DFLAGS += -DDHD_SDALIGN=64 -DMAX_HDR_READ=64 -DDHD_FIRSTREAD=64
    137 endif
    138 
    139 WFLAGS := -Wall -Wstrict-prototypes
    140 ifeq (,$(findstring 2.4.18,$(LINUXVER)))
    141 WFLAGS += -Werror
    142 endif
    143 
    144 CFILES:= dhd_linux.c linux_osl.c bcmutils.c dhd_common.c dhd_custom_gpio.c
    145 CFILES += siutils.c sbutils.c aiutils.c hndpmu.c
    146 
    147 # threading options
    148 ifneq ($(findstring -nothread-,-$(TARGET)-),)
    149 DFLAGS += -UDHDTHREAD
    150 endif
    151 
    152 # Building gpl provides thread prioritization
    153 ifneq ($(findstring -gpl-,-$(TARGET)-),)
    154 CFILES += dhd_linux_sched.c
    155 DFLAGS += -DDHD_GPL -DDHD_SCHED
    156 endif
    157 
    158 ifeq ($(WLTEST),1)
    159 	CFILES += bcmsrom.c bcmotp.c
    160 endif
    161 
    162 ifeq ($(CONFIG_NET_RADIO),y)
    163 CFILES +=  bcmwifi.c
    164 CFILES += wl_iw.c
    165 else
    166 	ifeq ($(CONFIG_WIRELESS_EXT),y)
    167 	CFILES += bcmwifi.c
    168 	CFILES += wl_iw.c
    169 	endif
    170 endif
    171 ifeq ($(BCM_KVER), 2.6)
    172 CFG80211_KVER:=$(shell echo $(LINUXVER) | cut -c5-6 | sed 's/3[1-9]/true/')
    173 ifeq ($(CFG80211_KVER), true)
    174 	ifeq ($(CONFIG_CFG80211),m)
    175 	DFLAGS += -DCONFIG_CFG80211
    176 	CFILES += wl_cfg80211.c
    177 	endif
    178 endif
    179 endif
    180 
    181 
    182 OFILES=$(CFILES:.c=.o)
    183 
    184 # Make debug a separate option
    185 ifneq ($(findstring -debug-,-$(TARGET)-),)
    186 DFLAGS += -DDHD_DEBUG -DSDTEST
    187 endif
    188 
    189 # Make big-endian a separate option
    190 ifneq ($(findstring -be-,-$(TARGET)-),)
    191 DFLAGS += -DIL_BIGENDIAN
    192 endif
    193 
    194 ifneq ($(findstring -dnglimage-,-$(TARGET)-),)
    195 ## Embeddable dongle image name
    196 DNGL_IMAGE_NAME ?= 4325b0/sdio-g-cdc-reclaim-idsup-wme
    197 DFLAGS += -DBCMEMBEDIMAGE -DIMAGE_NAME="$(DNGL_IMAGE_NAME)"
    198 IFLAGS += -I$(SRCBASE)/dongle/rte/wl/builds/$(DNGL_IMAGE_NAME)
    199 endif
    200 
    201 ifneq ($(findstring -cdc-,-$(TARGET)-),)
    202 DFLAGS += -DBDC -DTOE 
    203 DFLAGS += -DDHD_BCMEVENTS -DSHOW_EVENTS
    204 CFILES += dhd_cdc.c
    205 ifneq ($(findstring -apsta-,-$(TARGET)-),)
    206 DFLAGS += -DAP -DAPSTA_PINGTEST
    207 endif
    208 endif
    209 ifneq ($(findstring -rndis-,-$(TARGET)-),)
    210 DFLAGS += -DRNDIS
    211 CFILES += dhd_rndis.c
    212 endif
    213 		  
    214 ifneq ($(findstring -usb-,-$(TARGET)-),)
    215 DFLAGS += -DBCMDHDUSB
    216 CFILES += dhd_usb_linux.c
    217 endif
    218 ifneq ($(findstring -sdio-,-$(TARGET)-),)
    219 DFLAGS += -DBCMSDIO
    220 CFILES += dhd_sdio.c
    221 endif
    222 ifneq ($(findstring -sdstd-,$(TARGET)-),)
    223 DFLAGS += -DBCMSDIO -DBCMSDIOH_STD
    224 CFILES += dhd_sdio.c bcmsdh.c bcmsdstd.c bcmsdstd_linux.c bcmsdh_linux.c
    225 endif
    226 ifneq ($(findstring -softap-,-$(TARGET)-),)
    227 DFLAGS += -DSOFTAP
    228 CFILES += sha1.c md5.c
    229 endif
    230 ifneq ($(findstring -nexus-,-$(TARGET)-),)
    231 DFLAGS += -DOEM_ANDROID -DEMBEDDED_PLATFORM -DARP_OFFLOAD_SUPPORT -DPKT_FILTER_SUPPORT
    232 DFLAGS += -Dlinux
    233 DFLAGS += -DBCMDBG
    234 DFLAGS += -DDHD_USE_STATIC_BUF
    235 DFLAGS += -DCUSTOMER_HW2
    236 DFLAGS += -DCUSTOM_OOB_GPIO_NUM=152
    237 DFLAGS += -DOOB_INTR_ONLY
    238 DFLAGS += -DMMC_SDIO_ABORT
    239 DFLAGS += -DSOFTAP
    240 DFLAGS += -DPNO_SUPPORT
    241 else
    242 ifneq ($(findstring -oob-,-$(TARGET)-),)
    243 DFLAGS += -DOOB_INTR_ONLY
    244 DFLAGS += -DHW_OOB
    245 DFLAGS += -DMMC_SDIO_ABORT
    246 else
    247 ifneq ($(findstring -sdmmc-,-$(TARGET)-),)
    248 DFLAGS += -DSDIO_ISR_THREAD
    249 endif
    250 endif
    251 endif
    252 ifneq ($(findstring -sdmmc-,-$(TARGET)-),)
    253 DFLAGS += -DBCMSDIO -DDHD_GPL -DBCMLXSDMMC -DBCMPLATFORM_BUS 
    254 CFILES += dhd_sdio.c bcmsdh_sdmmc.c bcmsdh.c bcmsdh_linux.c bcmsdh_sdmmc_linux.c
    255 endif
    256 ifneq ($(findstring -sdspi-,$(TARGET)-),)
    257 DFLAGS += -DBCMSDIO -DBCMSDIOH_SPI -DTESTDONGLE # -DBCMSDYIELD
    258 CFILES += dhd_sdio.c bcmsdh.c bcmsdspi.c bcmsdspi_linux.c bcmsdh_linux.c 
    259 endif
    260 ifneq ($(findstring -pci,$(TARGET)-),)
    261 CFILES += bcmpcispi.c
    262 endif
    263 ifneq ($(findstring -sdext-,$(TARGET)-),)
    264 DFLAGS += -DBCMSDIO -DTESTDONGLE
    265 CFILES += dhd_sdio.c
    266 endif
    267 ifneq ($(findstring -intc1,$(shell echo $(LINUXVER))),)
    268 DFLAGS += -DSANDGATE2G
    269 endif
    270 
    271 ifeq ($(OEM_ANDROID),1)
    272 DFLAGS += -DOEM_ANDROID -DEMBEDDED_PLATFORM -DARP_OFFLOAD_SUPPORT -DPKT_FILTER_SUPPORT
    273 endif
    274 ifeq ($(OEM_CHROMIUMOS),1)
    275 DFLAGS += -DOEM_CHROMIUMOS -DEMBEDDED_PLATFORM -DARP_OFFLOAD_SUPPORT -DPKT_FILTER_SUPPORT
    276 endif
    277 
    278 CFLAGS += -fshort-wchar $(DFLAGS) $(WFLAGS) $(IFLAGS) $(CUSTOM_FLAGS)
    279 
    280 
    281 
    282 LDFLAGS := -r
    283 MODULES := dhd.o
    284 ifeq ($(BCM_KVER), 2.6)
    285   ##Kernel module names in 2.6 kernel have .ko suffix
    286   KMODULES:=dhd.ko
    287   ifneq ($(findstring -nexus-,$(TARGET)-),)
    288     KMODULES:=bcm4329.ko
    289   endif
    290 else
    291   KMODULES:=$(MODULES)
    292 endif
    293 
    294 
    295 # host options
    296 HOSTCC := $(CC)
    297 ifneq ($(BCM_KVER), 2.6)
    298   HOSTCFLAGS := $(CFLAGS) $(shell $(MAKE) --no-print-directory -s -C $(LINUXDIR) script 'SCRIPT=@echo $$(CFLAGS) $$(MODFLAGS)')
    299 else
    300   HOSTCFLAGS := $(CFLAGS) -D__KERNEL__
    301   DHDCFLAGS = $(HOSTCFLAGS) -I$(shell pwd)
    302   export DHDCFLAGS
    303   DHDOFILES = $(OFILES)
    304   export DHDOFILES
    305 endif
    306 
    307 TARGETS := \
    308 	dhd-cdc-usb dhd-cdc-sdstd \
    309 	dhd-cdc-sdspi-pci dhd-cdc-sdmmc-gpl dhd-cdc-sdmmc-oob-gpl dhd-cdc-sdmmc-nexus-gpl\
    310 	dhd-cdc-usb-apsta dhd-cdc-usb-gpl \
    311 	dhd-cdc-sdstd-apsta \
    312 	dhd-cdc-sdmmc-softap-gpl
    313 
    314 
    315 TARGETS += \
    316 	dhd-cdc-sdio-dnglimage dhd-cdc-sdspi-pci-dnglimage \
    317 	dhd-cdc-gspi-pci
    318 #ifdef RNDIS
    319 TARGETS += dhd-rndis-usb
    320 #endif
    321 TARGETS += dhd-cdc-sdext-be
    322 TARGETS += dhd-cdc-sdext-be-dnglimage
    323 ifneq ($(findstring -intc1,$(shell echo $(LINUXVER))),)
    324 TARGETS += dhd-cdc-sdio dhd-cdc-sdiofd # dhd-cdc-sdmmc
    325 endif
    326 TARGETS += $(foreach tgt, $(TARGETS), $(tgt)-debug)
    327 
    328 OBJDIR=$(TARGET)-$(LINUXVER)$(if $(BCMQT),-bcmqt)
    329 
    330 all: $(filter %-sdio %-sdbcm %-sdstd %-usb %sdspi-pci %-sdiofd %-sdmmc, $(TARGETS))
    331 sdio: $(filter %-sdio %-sdbcm %-sdstd, $(TARGETS))
    332 usb: $(filter %-usb, $(TARGETS))
    333 sdspi: $(filter %-sdspi-pci %-sdspi-cheetah, %-sdspi-u2c $(TARGETS))
    334 
    335 # Allow making target with the LINUXVER suffix already on it.
    336 # (Typical of command line tab completion; trailing slash still not allowed)
    337 %-$(LINUXVER): force
    338 	$(MAKE) $(@:%-$(LINUXVER)=%)
    339 
    340 $(TARGETS):
    341 	@echo "MAKING $@"
    342 	$(MAKE) TARGET=$@ objdir
    343 
    344 # Show compiler version, for the current target build
    345 showenv:
    346 	@echo "CC = $(CC) (ver=`$(CC) -dumpversion`; host=`hostname`; processor=`uname -m`)"
    347 
    348 objdir: showenv
    349 	@echo "Making objdir $(OBJDIR)"
    350 	@echo "TARGET is $(TARGET)"
    351 	mkdir -p $(OBJDIR)
    352 ifneq ($(BCM_KVER), 2.6)
    353 	$(MAKE) -C $(OBJDIR) -f $(SRCBASE)/dhd/linux/Makefile SRCBASE=$(SRCBASE) dep
    354 endif
    355 	$(MAKE) -C $(OBJDIR) -f $(SRCBASE)/dhd/linux/Makefile SRCBASE=$(SRCBASE) modules
    356 ifeq ($(BCM_KVER), 2.6)
    357 	$(OBJCOPY) --strip-unneeded $(OBJDIR)/$(KMODULES) $(OBJDIR)/$(KMODULES).stripped
    358 else
    359 	$(OBJCOPY) --strip-unneeded $(OBJDIR)/dhd.o $(OBJDIR)/dhd.o.stripped
    360 endif
    361 
    362 dep: $(foreach file,$(CFILES),.$(file).depend)
    363 .%.c.depend: %.c
    364 	$(HOSTCC) $(HOSTCFLAGS) -M $< > $@ || (rm -f $@; exit 1)
    365 .%.c.depend::
    366 	touch $@
    367 
    368 ifeq ($(BCM_KVER), 2.6)
    369 modules: $(OFILES)
    370 	test -r ./Makefile || ln -s $(SRCBASE)/dhd/linux/makefile.26 ./Makefile
    371 	$(MAKE) -C $(LINUXDIR) M=$(shell pwd) $(if $(VERBOSE),V=1) modules
    372 else
    373 modules: $(MODULES)
    374 endif
    375 
    376 $(MODULES): $(OFILES)
    377 	$(LD) $(LDFLAGS) -o $@ $^
    378 
    379 ifeq ($(BCM_KVER), 2.6)
    380 %.o: %.c
    381   # when make is called from 2.6, vpath doesn't work so we need to link the files.
    382 	test -r ./$< || ln -s $< .
    383 else
    384 %.o: %.c
    385 	$(HOSTCC) $(HOSTCFLAGS) -c -o $@ $<
    386 	@( \
    387 	echo 'ifneq ($$(HOSTCFLAGS),$(HOSTCFLAGS))' ; \
    388 	echo '$@: force' ; \
    389 	echo 'endif' ; \
    390 	) > .$*.c.flags
    391 endif
    392 
    393 force:
    394 
    395 clean:
    396 	rm -rf dhd-*
    397 
    398 ifneq ($(wildcard .*.depend),)
    399 include $(wildcard .*.depend)
    400 endif
    401 ifneq ($(wildcard .*.flags),)
    402 include $(wildcard .*.flags)
    403 endif
    404