#
# Makefile for the Atheros ar531x ethernet driver
#


ifndef BUILDDIR
BUILDDIR=$(realpath ../..)
endif

ifndef build_kernel_version
include $(BUILDDIR)/common.mk
endif

TOOLPREFIX=${build_toolchain_prefix}
MODPATH=$(instdir)
KERNELPATH=$(realpath $(BUILDDIR))/kernel/${build_kernel_version}
KERNELRELEASE=$(shell grep UTS_RELEASE $(KERNELPATH)/include/linux/version.h | \
sed -e 's/\(.*\) "\(.*\)"/\2/')


obj= .

obj-m		 += ae531x.o
ae531x-objs	 := ar2313.o
export-objs	 := ar2313.o.o
list-multi	 := ae531x.o

INCS += -I. -I${KERNELPATH}/arch/mips/ar531x/
ARCH_FLAGS = -mabi=32 -march=r4600 -Wa,-32 -Wa,-march=r4600 -Wa,-mips3 -Wa,--trap

#
# If building directly into kernel
#
ifneq ($(MAKING_MODULES),1)
obj-$(CONFIG_NET_ATHEROS_ETHER) := ae531x.o $(ae531x-objs)
O_TARGET := ae531x.o
endif

INCS += -I.

EXTRA_CFLAGS+=$(INCS) ${COPTS} ${ARCH_FLAGS}
ifeq ($(DEBUG_BUILD),1)
EXTRA_CFLAGS+=-DDEBUG
endif

# release tag versioning
-include $(KERNELPATH)/ath_version.mk

-include $(TOPDIR)/Rules.make
STRIP=	${TOOLPREFIX}strip

ifndef MODPATH
MODPATH = ${KERNELPATH}/arch/mips/ar531x/ROOTDISK/rootdir/lib/modules/${KERNELRELEASE}/
endif

all:
	$(MAKE)	-C ${KERNELPATH} SUBDIRS=$(shell pwd) modules

install: all
	$(STRIP) -S ae531x.o
	cp ae531x.o ${build_install_directory}/lib/modules/

clean:
	-rm -f *~ *.o *.ko *.mod.c
	-rm -f .version .*.o.flags .*.o.d .*.o.cmd .*.ko.cmd

ae531x.o : $(ae531x-objs)
	$(LD) -o ae531x.o -r $(ae531x-objs)

