Home | History | Annotate | Download | only in linux
      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
     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 LINUXVER := $(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
     49 BCM_KVER:=$(shell echo $(LINUXVER) | cut -c1-3 | sed 's/2\.[56]/2\.6/')
     50 
     51 # Allow CROSS_COMPILE to specify compiler base
     52 CC := $(CROSS_COMPILE)gcc
     53 LD := $(CROSS_COMPILE)ld
     54 NM := $(CROSS_COMPILE)nm
     55 OBJCOPY := $(CROSS_COMPILE)objcopy
     56 
     57 # driver source base and C file path
     58 ifeq ($(SRCBASE),)
     59 SRCBASE := $(shell /bin/pwd)/../..
     60 endif
     61 vpath %.c $(SRCBASE)/shared $(SRCBASE)/bcmsdio/sys $(SRCBASE)/wl/sys
     62 
     63 ## Initialize DFLAGS
     64 DFLAGS :=
     65 
     66 
     67 # basic options (defines in DFLAGS, includes in IFLAGS)
     68 DFLAGS += -DLINUX -DSRCBASE=\"$(SRCBASE)\" -DBCMDRIVER -DBCMSDH_MODULE
     69 DFLAGS += -DBCMDONGLEHOST
     70 DFLAGS += -DBCM4325
     71 
     72 IFLAGS := -I$(LINUXDIR)/include -I$(LINUXDIR)/include/asm/mach-default -I. -I$(SRCBASE)/include -I$(SRCBASE)/shared -I$(SRCBASE)/dongle -I$(SRCBASE)/wl/sys
     73 
     74 WFLAGS := -Wall -Wstrict-prototypes
     75 ifeq (,$(findstring 2.4.18,$(LINUXVER)))
     76 WFLAGS += -Werror
     77 endif
     78 
     79 CFILES:= bcmsdh_linux.c linux_osl.c bcmsdh.c
     80 CFILES += siutils.c sbutils.c aiutils.c bcmutils.c hndpmu.c
     81 
     82 OFILES=$(CFILES:.c=.o)
     83 
     84 # Make debug a separate option
     85 ifneq ($(findstring -debug-,-$(TARGET)-),)
     86 DFLAGS += -DBCMDBG -DSDTEST
     87 endif
     88 
     89 # Make big-endian a separate option
     90 ifneq ($(findstring -be-,-$(TARGET)-),)
     91 DFLAGS += -DIL_BIGENDIAN
     92 endif
     93 
     94 ifneq ($(findstring -sdstd,$(TARGET)-),)
     95 DFLAGS += -DBCMSDIO -DBCMSDIOH_STD
     96 CFILES += bcmsdstd.c bcmsdstd_linux.c
     97 endif
     98 ifneq ($(findstring -intc1,$(shell echo $(LINUXVER))),)
     99 DFLAGS += -DSANDGATE2G
    100 endif
    101 ifneq ($(findstring -sdspi-,$(TARGET)-),)
    102 DFLAGS += -DBCMSDIO -DBCMSDIOH_SPI -DTESTDONGLE
    103 CFILES += bcmsdspi.c bcmsdspi_linux.c 
    104 endif
    105 
    106 CFLAGS += -fshort-wchar $(DFLAGS) $(WFLAGS) $(IFLAGS)
    107 
    108 LDFLAGS := -r
    109 MODULES := bcmsdh_driver.o
    110 ifeq ($(BCM_KVER), 2.6)
    111   ##Kernel module names in 2.6 kernel have .ko suffix
    112   KMODULES:=bcmsdh_driver.ko
    113 else
    114   KMODULES:=$(MODULES)
    115 endif
    116 
    117 # host options
    118 HOSTCC := $(CC)
    119 ifneq ($(BCM_KVER), 2.6)
    120   HOSTCFLAGS := $(CFLAGS) $(shell $(MAKE) --no-print-directory -s -C $(LINUXDIR) script 'SCRIPT=@echo $$(CFLAGS) $$(MODFLAGS)')
    121 else
    122   HOSTCFLAGS := $(CFLAGS) -D__KERNEL__
    123   BCMSDHCFLAGS = $(HOSTCFLAGS) -I$(shell pwd)
    124   export BCMSDHCFLAGS
    125   BCMSDHOFILES = $(OFILES)
    126   export BCMSDHOFILES
    127 endif
    128 
    129 TARGETS := \
    130 	bcmsdh-sdstd
    131 ifneq ($(findstring -intc1,$(shell echo $(LINUXVER))),)
    132 TARGETS := bcmsdh-sdiofd
    133 endif
    134 TARGETS += $(foreach tgt, $(TARGETS), $(tgt)-debug)
    135 
    136 OBJDIR=$(TARGET)-$(LINUXVER)$(if $(BCMQT),-bcmqt)
    137 
    138 all: $(TARGETS)
    139 sdspi: $(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 
    150 objdir:
    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
    156 ifeq ($(BCM_KVER), 2.6)
    157 	$(OBJCOPY) --strip-unneeded $(OBJDIR)/bcmsdh_driver.ko $(OBJDIR)/bcmsdh_driver.ko.stripped
    158 else
    159 	$(OBJCOPY) --strip-unneeded $(OBJDIR)/bcmsdh_driver.o $(OBJDIR)/bcmsdh_driver.o.stripped
    160 endif
    161 
    162 dep: $(foreach file,$(CFILES),.$(file).depend)
    163 .%.c.depend: %.c
    164 	$(HOSTCC) $(HOSTCFLAGS) -M $< > $@
    165 .%.c.depend::
    166 	touch $@
    167 
    168 ifeq ($(BCM_KVER), 2.6)
    169 modules: $(OFILES)
    170 	test -r ./Makefile || ln -s ../makefile.26 ./Makefile
    171 	$(MAKE) -C $(LINUXDIR) M=$(shell pwd) $(if $(VERBOSE),V=1) modules
    172 else
    173 modules: $(MODULES)
    174 endif
    175 
    176 bcmsdh_driver.o: $(OFILES)
    177 	$(LD) $(LDFLAGS) -o $@ $^
    178 
    179 ifeq ($(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 $< .
    183 else
    184 %.o: %.c
    185 	$(HOSTCC) $(HOSTCFLAGS) -c -o $@ $<
    186 	@( \
    187 	echo 'ifneq ($$(HOSTCFLAGS),$(HOSTCFLAGS))' ; \
    188 	echo '$@: force' ; \
    189 	echo 'endif' ; \
    190 	) > .$*.c.flags
    191 endif
    192 
    193 force:
    194 
    195 clean:
    196 	rm -rf bcmsdh-*
    197 
    198 ifneq ($(wildcard .*.depend),)
    199 include $(wildcard .*.depend)
    200 endif
    201 ifneq ($(wildcard .*.flags),)
    202 include $(wildcard .*.flags)
    203 endif
    204