Use Linux 3.17 4-argument alloc_netdev(), provide compatibility code
[madwifi/.git] / Makefile.inc
index f23c406129599c47492278f6217655bee7b24113..9741cce20e79cb6137697de2b872c25e4f86be4c 100644 (file)
@@ -49,88 +49,66 @@ endif
 # DESTDIR is used as path prefix during installation.
 DESTDIR ?=
 
-# KERNELPATH is the path to the Linux kernel build tree.  Unless a
-# separate build directory was used for the kernel build, it's the same
-# as the kernel source tree.  KERNELPATH is used to access the kernel
-# configuration, include files and the build system.  To build for
-# another kernel, set KERNELPATH manually, for example with:
-# make KERNELPATH=/path/to/kernel/source
-
-# The default KERNELPATH points to the directory where the currently
-# running kernel was compiled.  Note that the configuration and the
-# version of the kernel tree might have changed since then.
-ifeq ($(wildcard $(KERNELPATH)),)
-KERNELPATH = /lib/modules/$(shell uname -r)/build
-# sanity check: does KERNELPATH exist?
-ifeq ($(shell cd $(KERNELPATH) && pwd),)
-$(error $(KERNELPATH) is missing, please set KERNELPATH)
+# By default, we try to compile the modules for the currently running
+# kernel.  But it's the first approximation, as we will re-read the
+# version from the kernel sources.
+KVERS_UNAME ?= $(shell uname -r)
+
+# KERNELPATH is the path to the Linux kernel build tree.  It is usually the
+# same as the kernel source tree, except when the kernel was compiled in
+# a separate directory.
+KERNELPATH ?= $(shell readlink -f /lib/modules/$(KVERS_UNAME)/build)
+
+ifeq (,$(KERNELPATH))
+$(error Kernel build tree not found - please set KERNELPATH to configured kernel)
 endif
-export KERNELPATH
+
+KERNELCONF := $(KERNELPATH)/.config
+ifeq (,$(wildcard $(KERNELCONF)))
+$(error No .config found in $(KERNELPATH), please set KERNELPATH to configured kernel)
 endif
 
-# KERNELRELEASE is the target kernel's version.  It's always taken from
-# the kernel build tree.  Kernel Makefile doesn't always know the exact
-# kernel version (especially for vendor stock kernels), so we get it
-# from <linux/version.h> instead. But simply grepping it from version.h
-# doesn't work, since some distributions have multiple UTS_RELEASE
-# in that file.
-# This trick has been inspired by the lm_sensors project.
-ifndef KERNELRELEASE
-KERNELRELEASE := $(shell $(CC) -I $(KERNELPATH)/include -E $(TOP)/kernelversion.c | grep uts_release | cut -f2 -d'"')
-ifeq (,$(KERNELRELEASE))
-$(error Cannot detect kernel version - please check compiler and KERNELPATH)
+ifneq (,$(wildcard $(KERNELPATH)/include/linux/version.h))
+ifneq (,$(wildcard $(KERNELPATH)/include/generated/uapi/linux/version.h))
+$(error Multiple copies of version.h found, please clean your build tree)
 endif
 endif
 
-# KERNELCONF is the name of the file that holds the configuration
-# of the target kernel.
-KERNELCONF ?=  $(KERNELPATH)/.config
-
-# sanity check: does KERNELCONF exist?
-ifeq ($(wildcard $(KERNELCONF)),)
-$(error KERNELCONF: $(KERNELCONF) does not exist.)
+# Kernel Makefile doesn't always know the exact kernel version, so we
+# get it from the kernel headers instead and pass it to make.
+VERSION_H := $(KERNELPATH)/include/generated/utsrelease.h
+ifeq (,$(wildcard $(VERSION_H)))
+VERSION_H := $(KERNELPATH)/include/linux/utsrelease.h
+endif
+ifeq (,$(wildcard $(VERSION_H)))
+VERSION_H := $(KERNELPATH)/include/linux/version.h
+endif
+ifeq (,$(wildcard $(VERSION_H)))
+$(error Please run 'make modules_prepare' in $(KERNELPATH))
 endif
-include $(KERNELCONF)
 
-# Determine architecture of the kernel.
-include $(TOP)/scripts/get_arch.mk
-export ARCH
+KERNELRELEASE := $(shell sed -ne 's/"//g;s/^\#define UTS_RELEASE //p' $(VERSION_H))
 
-# Determine TARGET
-include $(TOP)/ath_hal/ah_target.inc
-export TARGET
-COPTS += -DTARGET='"$(TARGET)"'
+ifeq (,$(KERNELRELEASE))
+$(error Cannot find UTS_RELEASE in $(VERSION_H), please report)
+endif
+
+include $(KERNELCONF)
 
 # KMODPATH nominates the directory where the modules will be
 # installed to
 KMODPATH :=    /lib/modules/$(KERNELRELEASE)/net
 
-# Recognize 2.4.x kernels to support the old build system
-ifeq ($(filter-out 2.4%,$(KERNELRELEASE)),)
-LINUX24 = y
-endif
-
-ifndef LINUX24
 KMODSUF                := ko
-else
-export-objs    = $(foreach m, $(obj-m), $($(m:.o=-objs)))
-list-multi     = $(obj-m)
-KMODSUF                := o
-endif
-
 NM=            nm
 
 #
 # Path to the HAL source code.
 #
 ifeq ($(HAL),)
-HAL=   $(TOP)/hal
+HAL=   $(TOP)/ath_hal
 endif
 #
-# Path to HAL/OS interface code
-#
-ATH_HAL= $(TOP)/ath_hal
-#
 # Path to the 802.11 include files.
 #
 WLAN=  $(TOP)/net80211
@@ -145,22 +123,12 @@ ATH_RATE= $(TOP)/ath_rate
 #
 # Path to the userspace utilities. 
 # 
-TOOLS=  $(TOP)/tools 
+TOOLS=  $(TOP)/tools
 
-WARNINGS = -Werror -Wall
+WARNINGS = -Wall
 COPTS+= $(WARNINGS)
 INCS=  -include $(TOP)/include/compat.h -I$(TOP)/include
 
-# TARGET defines the target platform architecture. It must match one of
-# the target platforms supported by the HAL. The default target is the
-# host machine architecture. You can override TARGET on the make command
-# line or in the environment. See hal/linux/*.inc for the list of
-# supported targets.
-ifeq (,$(wildcard $(HAL)/public/$(TARGET).inc))
-TARGETS=$(basename $(notdir $(wildcard $(HAL)/public/*.inc)))
-$(error TARGET $(TARGET) is invalid, valid targets are: $(TARGETS))
-endif
-
 ifndef ATH_DEBUG_SPINLOCKS
 export ATH_DEBUG_SPINLOCKS=0
 endif
@@ -173,22 +141,10 @@ ifndef HAL_DEBUG
 export HAL_DEBUG=0
 endif
 
-ifndef ALQ
-export ALQ=0
-endif
-
 ifndef ATH_DEBUG
 export ATH_DEBUG=1
 endif
 
-ifndef MMIOTRACE
-export MMIOTRACE=0
-endif
-
-ifeq ($(strip $(MMIOTRACE)),1)
-EXTRA_CFLAGS += -DMMIOTRACE=1
-endif
-
 ifeq ($(strip $(ATH_DEBUG_SPINLOCKS)),1)
 COPTS+= -DATH_DEBUG_SPINLOCKS=1
 endif
@@ -204,28 +160,6 @@ ifeq ($(strip $(HAL_DEBUG)),1)
 COPTS+= -fno-inline -DAH_DEBUG=1
 endif
 
-ifeq ($(strip $(ALQ)),1)
-obj-m += alq.o
-alq-objs := kern_alq.o
-EXTRA_CFLAGS += -DAH_DEBUG_ALQ -DAH_DEBUG
-endif
-
-# Don't let HAL mess with the toolchain - save toolchain variables
-save_CC := $(CC)
-save_LD := $(LD)
-save_STRIP := $(STRIP)
-save_OBJCOPY := $(OBJCOPY)
-save_NM := $(NM)
-
-include $(HAL)/public/$(TARGET).inc
-
-# Restore toolchain variables
-CC := $(save_CC)
-LD := $(save_LD)
-STRIP := $(save_STRIP)
-OBJCOPY := $(save_OBJCOPY)
-NM := $(save_NM)
-
 include $(TOP)/BuildCaps.inc
 
 ifeq ($(strip $(ATH_DEBUG)),1)