#
# Copyright (C) 2007 Ubiquiti Networks, Inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#

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= .

O_TARGET		:= gpio.o
obj-y			:= ar531xgpio.o
obj-m			:= gpio.o

INCS += -I. -I${KERNELPATH}/arch/mips/ar531x/

EXTRA_CFLAGS+=$(INCS) ${COPTS}

-include $(TOPDIR)/Rules.make

STRIP=	${TOOLPREFIX}strip

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

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

install: all
		$(STRIP) -S $(O_TARGET)
		cp -f $(O_TARGET) ${build_install_directory}/lib/modules/

