1 2# GNU Makefile for Broadcom BCMSDH Lower-level 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.5.8.4.6.1 2009/01/26 20:28:33 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 44LINUXVER := $(shell { cat $(LINUXDIR)/Makefile; \ 45 echo "bcm$$$$:;@echo \$$(KERNELRELEASE)"; } | \ 46 $(MAKE) --no-print-directory $(if $(ARCH),ARCH=$(ARCH),) -C $(LINUXDIR) -f - bcm$$$$) 47 48# check if 2.4 kernel or 2.5+ kernel 49BCM_KVER:=$(shell echo $(LINUXVER) | cut -c1-3 | sed 's/2\.[56]/2\.6/') 50 51# Allow CROSS_COMPILE to specify compiler base 52CC := $(CROSS_COMPILE)gcc 53LD := $(CROSS_COMPILE)ld 54NM := $(CROSS_COMPILE)nm 55OBJCOPY := $(CROSS_COMPILE)objcopy 56 57# driver source base and C file path 58ifeq ($(SRCBASE),) 59SRCBASE := $(shell /bin/pwd)/../.. 60endif 61vpath %.c $(SRCBASE)/shared $(SRCBASE)/bcmsdio/sys $(SRCBASE)/wl/sys 62 63## Initialize DFLAGS 64DFLAGS := 65 66 67# basic options (defines in DFLAGS, includes in IFLAGS) 68DFLAGS += -DLINUX -DSRCBASE=\"$(SRCBASE)\" -DBCMDRIVER -DBCMSDH_MODULE 69DFLAGS += -DBCMDONGLEHOST 70DFLAGS += -DBCM4325 71 72IFLAGS := -I$(LINUXDIR)/include -I$(LINUXDIR)/include/asm/mach-default -I. -I$(SRCBASE)/include -I$(SRCBASE)/shared -I$(SRCBASE)/dongle -I$(SRCBASE)/wl/sys 73 74WFLAGS := -Wall -Wstrict-prototypes 75ifeq (,$(findstring 2.4.18,$(LINUXVER))) 76WFLAGS += -Werror 77endif 78 79CFILES:= bcmsdh_linux.c linux_osl.c bcmsdh.c 80CFILES += siutils.c sbutils.c aiutils.c bcmutils.c hndpmu.c 81 82OFILES=$(CFILES:.c=.o) 83 84# Make debug a separate option 85ifneq ($(findstring -debug-,-$(TARGET)-),) 86DFLAGS += -DBCMDBG -DSDTEST 87endif 88 89# Make big-endian a separate option 90ifneq ($(findstring -be-,-$(TARGET)-),) 91DFLAGS += -DIL_BIGENDIAN 92endif 93 94ifneq ($(findstring -sdstd,$(TARGET)-),) 95DFLAGS += -DBCMSDIO -DBCMSDIOH_STD 96CFILES += bcmsdstd.c bcmsdstd_linux.c 97endif 98ifneq ($(findstring -intc1,$(shell echo $(LINUXVER))),) 99DFLAGS += -DSANDGATE2G 100endif 101ifneq ($(findstring -sdspi-,$(TARGET)-),) 102DFLAGS += -DBCMSDIO -DBCMSDIOH_SPI -DTESTDONGLE 103CFILES += bcmsdspi.c bcmsdspi_linux.c 104endif 105 106CFLAGS += -fshort-wchar $(DFLAGS) $(WFLAGS) $(IFLAGS) 107 108LDFLAGS := -r 109MODULES := bcmsdh_driver.o 110ifeq ($(BCM_KVER), 2.6) 111 ##Kernel module names in 2.6 kernel have .ko suffix 112 KMODULES:=bcmsdh_driver.ko 113else 114 KMODULES:=$(MODULES) 115endif 116 117# host options 118HOSTCC := $(CC) 119ifneq ($(BCM_KVER), 2.6) 120 HOSTCFLAGS := $(CFLAGS) $(shell $(MAKE) --no-print-directory -s -C $(LINUXDIR) script 'SCRIPT=@echo $$(CFLAGS) $$(MODFLAGS)') 121else 122 HOSTCFLAGS := $(CFLAGS) -D__KERNEL__ 123 BCMSDHCFLAGS = $(HOSTCFLAGS) -I$(shell pwd) 124 export BCMSDHCFLAGS 125 BCMSDHOFILES = $(OFILES) 126 export BCMSDHOFILES 127endif 128 129TARGETS := \ 130 bcmsdh-sdstd 131ifneq ($(findstring -intc1,$(shell echo $(LINUXVER))),) 132TARGETS := bcmsdh-sdiofd 133endif 134TARGETS += $(foreach tgt, $(TARGETS), $(tgt)-debug) 135 136OBJDIR=$(TARGET)-$(LINUXVER)$(if $(BCMQT),-bcmqt) 137 138all: $(TARGETS) 139sdspi: $(filter %-sdspi-pci %-sdspi-cheetah, %-sdspi-u2c $(TARGETS)) 140 141# Allow making target with the LINUXVER suffix already on it. 142# (Typical of command line tab completion; trailing slash still not allowed) 143%-$(LINUXVER): force 144 $(MAKE) $(@:%-$(LINUXVER)=%) 145 146$(TARGETS): 147 @echo "MAKING $@" 148 $(MAKE) TARGET=$@ objdir 149 150objdir: 151 @echo "Making objdir $(OBJDIR)" 152 @echo "TARGET is $(TARGET)" 153 mkdir -p $(OBJDIR) 154 $(MAKE) -C $(OBJDIR) -f ../Makefile SRCBASE=$(SRCBASE) dep 155 $(MAKE) -C $(OBJDIR) -f ../Makefile SRCBASE=$(SRCBASE) modules 156ifeq ($(BCM_KVER), 2.6) 157 $(OBJCOPY) --strip-unneeded $(OBJDIR)/bcmsdh_driver.ko $(OBJDIR)/bcmsdh_driver.ko.stripped 158else 159 $(OBJCOPY) --strip-unneeded $(OBJDIR)/bcmsdh_driver.o $(OBJDIR)/bcmsdh_driver.o.stripped 160endif 161 162dep: $(foreach file,$(CFILES),.$(file).depend) 163.%.c.depend: %.c 164 $(HOSTCC) $(HOSTCFLAGS) -M $< > $@ 165.%.c.depend:: 166 touch $@ 167 168ifeq ($(BCM_KVER), 2.6) 169modules: $(OFILES) 170 test -r ./Makefile || ln -s ../makefile.26 ./Makefile 171 $(MAKE) -C $(LINUXDIR) M=$(shell pwd) $(if $(VERBOSE),V=1) modules 172else 173modules: $(MODULES) 174endif 175 176bcmsdh_driver.o: $(OFILES) 177 $(LD) $(LDFLAGS) -o $@ $^ 178 179ifeq ($(BCM_KVER), 2.6) 180%.o: %.c 181 # when make is called from 2.6, vpath doesn't work so we need to link the files. 182 test -r ./$< || ln -s $< . 183else 184%.o: %.c 185 $(HOSTCC) $(HOSTCFLAGS) -c -o $@ $< 186 @( \ 187 echo 'ifneq ($$(HOSTCFLAGS),$(HOSTCFLAGS))' ; \ 188 echo '$@: force' ; \ 189 echo 'endif' ; \ 190 ) > .$*.c.flags 191endif 192 193force: 194 195clean: 196 rm -rf bcmsdh-* 197 198ifneq ($(wildcard .*.depend),) 199include $(wildcard .*.depend) 200endif 201ifneq ($(wildcard .*.flags),) 202include $(wildcard .*.flags) 203endif 204