1 2# GNU Makefile for Broadcom Dongle Host Driver 3# 4# Copyright (C) 1999-2009, 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.24 2009/10/22 18:40:45 Exp $ 25# 26 27# Try a couple of places for LINUXDIR if not specified 28ifeq ($(LINUXDIR),) 29ifeq ($(LINUXVER),) 30# Neither one is specified, use uname for version 31LINUXVER := $(shell uname -r) 32endif 33ifneq ($(wildcard /lib/modules/$(LINUXVER)/build/include/linux/version.h),) 34LINUXDIR := /lib/modules/$(LINUXVER)/build 35else 36ifneq ($(wildcard /tools/linux/src/linux-$(LINUXVER)/include/linux/version.h),) 37LINUXDIR := /tools/linux/src/linux-$(LINUXVER) 38else 39LINUXDIR := /usr/src/linux 40endif 41endif 42endif 43 44# Derive LINUXVER from LINUXDIR 45MYKERNEL_RELEASE_KEYWORD:="KERNELRELEASE[[:space:]]*=.*kernel.release" 46MYKERNEL_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 51LINUXVER:=$(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 53ifeq ($(LINUXVER),) 54 $(error LINUXVER=$(LINUXVER) is empty) 55endif # LINUXVER 56 57$(warning Found LINUXVER=$(LINUXVER)) 58$(warning Found LINUXDIR=$(LINUXDIR)) 59 60# check if 2.4 kernel or 2.5+ kernel 61BCM_KVER:=$(shell echo $(LINUXVER) | cut -c1-3 | sed 's/2\.[56]/2\.6/') 62 63# Allow CROSS_COMPILE to specify compiler base 64CC := $(CROSS_COMPILE)gcc 65LD := $(CROSS_COMPILE)ld 66NM := $(CROSS_COMPILE)nm 67OBJCOPY := $(CROSS_COMPILE)objcopy 68 69# driver source base and C file path 70ifeq ($(SRCBASE),) 71SRCBASE := $(shell /bin/pwd)/../.. 72endif 73vpath %.c $(SRCBASE)/dhd/sys $(SRCBASE)/shared $(SRCBASE)/bcmsdio/sys $(SRCBASE)/wl/sys 74 75## Initialize DFLAGS 76DFLAGS := 77 78 79# basic options (defines in DFLAGS, includes in IFLAGS) 80DFLAGS += -DLINUX -DSRCBASE=\"$(SRCBASE)\" -DBCMDRIVER -DBCMDONGLEHOST -DDHDTHREAD -DBCMWPA2 -DBCMWAPI_WPI 81DFLAGS += -DUNRELEASEDCHIP 82ifeq ($(BCMQT),1) 83 DFLAGS += -DBCMSLTGT -DBCMQT 84endif 85ifeq ($(WLTEST),1) 86 DFLAGS += -DWLTEST -DIOCTL_RESP_TIMEOUT=20000 87 DFLAGS += -DDHD_SPROM 88endif 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 95ifdef ARCH 96 DHDARCH ?= $(ARCH) 97else 98 DHDARCH ?= x86 99endif 100 101ifneq ($(findstring native,$(TARGET)),) 102 DHDARCH = x86 103endif 104ifneq ($(findstring mips,$(TARGET)),) 105 DHDARCH = mips 106endif 107ifneq ($(findstring arm,$(TARGET)),) 108 DHDARCH = arm 109endif 110 111# First include from linux kernel dirs 112IFLAGS := -I$(LINUXDIR)/include 113IFLAGS += -I$(LINUXDIR)/include/asm/mach-default 114# Followed by 2.6.29+ specific paths 115IFLAGS += -I$(LINUXDIR)/arch/$(DHDARCH)/include 116IFLAGS += -I$(LINUXDIR)/arch/$(DHDARCH)/include/asm/mach-default 117 118# From current workspace 119IFLAGS += -I. 120IFLAGS += -I$(SRCBASE)/include 121IFLAGS += -I$(SRCBASE)/shared 122IFLAGS += -I$(SRCBASE)/dhd/sys 123IFLAGS += -I$(SRCBASE)/dongle 124IFLAGS += -I$(SRCBASE)/wl/sys 125 126ifneq ($(wildcard $(LINUXDIR)/.config),) 127include $(LINUXDIR)/.config 128else 129# This is dangerous, since we don't know if they are really configured. 130CONFIG_WIRELESS_EXT=y 131DFLAGS += -DCONFIG_WIRELESS_EXT 132endif 133 134ifeq ($(CONFIG_MMC_MSM7X00A),y) 135DFLAGS += -Dlinux 136DFLAGS += -DDHD_SDALIGN=64 -DMAX_HDR_READ=64 -DDHD_FIRSTREAD=64 137endif 138 139WFLAGS := -Wall -Wstrict-prototypes 140ifeq (,$(findstring 2.4.18,$(LINUXVER))) 141WFLAGS += -Werror 142endif 143 144CFILES:= dhd_linux.c linux_osl.c bcmutils.c dhd_common.c dhd_custom_gpio.c 145CFILES += siutils.c sbutils.c aiutils.c hndpmu.c 146 147# threading options 148ifneq ($(findstring -nothread-,-$(TARGET)-),) 149DFLAGS += -UDHDTHREAD 150endif 151 152# Building gpl provides thread prioritization 153ifneq ($(findstring -gpl-,-$(TARGET)-),) 154CFILES += dhd_linux_sched.c 155DFLAGS += -DDHD_GPL -DDHD_SCHED 156endif 157 158ifeq ($(WLTEST),1) 159 CFILES += bcmsrom.c bcmotp.c 160endif 161 162ifeq ($(CONFIG_NET_RADIO),y) 163CFILES += wl_iw.c bcmwifi.c 164else 165 ifeq ($(CONFIG_WIRELESS_EXT),y) 166 CFILES += wl_iw.c bcmwifi.c 167 endif 168endif 169 170OFILES=$(CFILES:.c=.o) 171 172# Make debug a separate option 173ifneq ($(findstring -debug-,-$(TARGET)-),) 174DFLAGS += -DDHD_DEBUG -DSDTEST 175endif 176 177# Make big-endian a separate option 178ifneq ($(findstring -be-,-$(TARGET)-),) 179DFLAGS += -DIL_BIGENDIAN 180endif 181 182ifneq ($(findstring -dnglimage-,-$(TARGET)-),) 183## Embeddable dongle image name 184DNGL_IMAGE_NAME ?= 4325b0/sdio-g-cdc-reclaim-idsup-wme 185DFLAGS += -DBCMEMBEDIMAGE -DIMAGE_NAME="$(DNGL_IMAGE_NAME)" 186IFLAGS += -I$(SRCBASE)/dongle/rte/wl/builds/$(DNGL_IMAGE_NAME) 187endif 188 189ifneq ($(findstring -cdc-,-$(TARGET)-),) 190DFLAGS += -DBDC -DTOE 191DFLAGS += -DDHD_BCMEVENTS -DSHOW_EVENTS 192CFILES += dhd_cdc.c 193ifneq ($(findstring -apsta-,-$(TARGET)-),) 194DFLAGS += -DAP -DAPSTA_PINGTEST 195endif 196endif 197ifneq ($(findstring -rndis-,-$(TARGET)-),) 198DFLAGS += -DRNDIS 199CFILES += dhd_rndis.c 200endif 201 202ifneq ($(findstring -usb-,-$(TARGET)-),) 203DFLAGS += -DBCMDHDUSB 204CFILES += dhd_usb_linux.c 205endif 206ifneq ($(findstring -sdio-,-$(TARGET)-),) 207DFLAGS += -DBCMSDIO 208CFILES += dhd_sdio.c 209endif 210ifneq ($(findstring -sdstd-,$(TARGET)-),) 211DFLAGS += -DBCMSDIO -DBCMSDIOH_STD 212CFILES += dhd_sdio.c bcmsdh.c bcmsdstd.c bcmsdstd_linux.c bcmsdh_linux.c 213endif 214ifneq ($(findstring -oob-,-$(TARGET)-),) 215DFLAGS += -DOOB_INTR_ONLY 216else 217ifneq ($(findstring -sdmmc-,-$(TARGET)-),) 218DFLAGS += -DSDIO_ISR_THREAD 219endif 220endif 221ifneq ($(findstring -sdmmc-,-$(TARGET)-),) 222DFLAGS += -DBCMSDIO -DDHD_GPL -DBCMLXSDMMC -DBCMPLATFORM_BUS 223CFILES += dhd_sdio.c bcmsdh_sdmmc.c bcmsdh.c bcmsdh_linux.c bcmsdh_sdmmc_linux.c 224endif 225ifneq ($(findstring -sdspi-,$(TARGET)-),) 226DFLAGS += -DBCMSDIO -DBCMSDIOH_SPI -DTESTDONGLE # -DBCMSDYIELD 227CFILES += dhd_sdio.c bcmsdh.c bcmsdspi.c bcmsdspi_linux.c bcmsdh_linux.c 228endif 229ifneq ($(findstring -pci,$(TARGET)-),) 230CFILES += bcmpcispi.c 231endif 232ifneq ($(findstring -sdext-,$(TARGET)-),) 233DFLAGS += -DBCMSDIO -DTESTDONGLE 234CFILES += dhd_sdio.c 235endif 236ifneq ($(findstring -intc1,$(shell echo $(LINUXVER))),) 237DFLAGS += -DSANDGATE2G 238endif 239 240CFLAGS += -fshort-wchar $(DFLAGS) $(WFLAGS) $(IFLAGS) $(CUSTOM_FLAGS) 241 242 243 244LDFLAGS := -r 245MODULES := dhd.o 246ifeq ($(BCM_KVER), 2.6) 247 ##Kernel module names in 2.6 kernel have .ko suffix 248 KMODULES:=dhd.ko 249else 250 KMODULES:=$(MODULES) 251endif 252 253# host options 254HOSTCC := $(CC) 255ifneq ($(BCM_KVER), 2.6) 256 HOSTCFLAGS := $(CFLAGS) $(shell $(MAKE) --no-print-directory -s -C $(LINUXDIR) script 'SCRIPT=@echo $$(CFLAGS) $$(MODFLAGS)') 257else 258 HOSTCFLAGS := $(CFLAGS) -D__KERNEL__ 259 DHDCFLAGS = $(HOSTCFLAGS) -I$(shell pwd) 260 export DHDCFLAGS 261 DHDOFILES = $(OFILES) 262 export DHDOFILES 263endif 264 265TARGETS := \ 266 dhd-cdc-usb dhd-cdc-sdstd \ 267 dhd-cdc-sdspi-pci dhd-cdc-sdmmc-gpl dhd-cdc-sdmmc-oob-gpl \ 268 dhd-cdc-usb-apsta dhd-cdc-usb-gpl \ 269 dhd-cdc-sdstd-apsta 270 271 272TARGETS += \ 273 dhd-cdc-sdio-dnglimage dhd-cdc-sdspi-pci-dnglimage \ 274 dhd-cdc-gspi-pci 275#ifdef RNDIS 276TARGETS += dhd-rndis-usb 277#endif 278TARGETS += dhd-cdc-sdext-be 279TARGETS += dhd-cdc-sdext-be-dnglimage 280ifneq ($(findstring -intc1,$(shell echo $(LINUXVER))),) 281TARGETS += dhd-cdc-sdio dhd-cdc-sdiofd # dhd-cdc-sdmmc 282endif 283TARGETS += $(foreach tgt, $(TARGETS), $(tgt)-debug) 284 285OBJDIR=$(TARGET)-$(LINUXVER)$(if $(BCMQT),-bcmqt) 286 287all: $(filter %-sdio %-sdbcm %-sdstd %-usb %sdspi-pci %-sdiofd %-sdmmc, $(TARGETS)) 288sdio: $(filter %-sdio %-sdbcm %-sdstd, $(TARGETS)) 289usb: $(filter %-usb, $(TARGETS)) 290sdspi: $(filter %-sdspi-pci %-sdspi-cheetah, %-sdspi-u2c $(TARGETS)) 291 292# Allow making target with the LINUXVER suffix already on it. 293# (Typical of command line tab completion; trailing slash still not allowed) 294%-$(LINUXVER): force 295 $(MAKE) $(@:%-$(LINUXVER)=%) 296 297$(TARGETS): 298 @echo "MAKING $@" 299 $(MAKE) TARGET=$@ objdir 300 301# Show compiler version, for the current target build 302showenv: 303 @echo "CC = $(CC) (ver=`$(CC) -dumpversion`; host=`hostname`; processor=`uname -m`)" 304 305objdir: showenv 306 @echo "Making objdir $(OBJDIR)" 307 @echo "TARGET is $(TARGET)" 308 mkdir -p $(OBJDIR) 309ifneq ($(BCM_KVER), 2.6) 310 $(MAKE) -C $(OBJDIR) -f $(SRCBASE)/dhd/linux/Makefile SRCBASE=$(SRCBASE) dep 311endif 312 $(MAKE) -C $(OBJDIR) -f $(SRCBASE)/dhd/linux/Makefile SRCBASE=$(SRCBASE) modules 313ifeq ($(BCM_KVER), 2.6) 314 $(OBJCOPY) --strip-unneeded $(OBJDIR)/dhd.ko $(OBJDIR)/dhd.ko.stripped 315else 316 $(OBJCOPY) --strip-unneeded $(OBJDIR)/dhd.o $(OBJDIR)/dhd.o.stripped 317endif 318 319dep: $(foreach file,$(CFILES),.$(file).depend) 320.%.c.depend: %.c 321 $(HOSTCC) $(HOSTCFLAGS) -M $< > $@ || (rm -f $@; exit 1) 322.%.c.depend:: 323 touch $@ 324 325ifeq ($(BCM_KVER), 2.6) 326modules: $(OFILES) 327 test -r ./Makefile || ln -s $(SRCBASE)/dhd/linux/makefile.26 ./Makefile 328 $(MAKE) -C $(LINUXDIR) M=$(shell pwd) $(if $(VERBOSE),V=1) modules 329else 330modules: $(MODULES) 331endif 332 333dhd.o: $(OFILES) 334 $(LD) $(LDFLAGS) -o $@ $^ 335 336ifeq ($(BCM_KVER), 2.6) 337%.o: %.c 338 # when make is called from 2.6, vpath doesn't work so we need to link the files. 339 test -r ./$< || ln -s $< . 340else 341%.o: %.c 342 $(HOSTCC) $(HOSTCFLAGS) -c -o $@ $< 343 @( \ 344 echo 'ifneq ($$(HOSTCFLAGS),$(HOSTCFLAGS))' ; \ 345 echo '$@: force' ; \ 346 echo 'endif' ; \ 347 ) > .$*.c.flags 348endif 349 350force: 351 352clean: 353 rm -rf dhd-* 354 355ifneq ($(wildcard .*.depend),) 356include $(wildcard .*.depend) 357endif 358ifneq ($(wildcard .*.flags),) 359include $(wildcard .*.flags) 360endif 361