#
#  Copyright(c) 2009 NEC Corporation. All rights reserved.
#
#  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., 59
#  Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
#  The full GNU General Public License is included in this distribution in the
#  file called COPYING.
#

# Makefile for the bios flash rom device driver.
# 2008/01/31

CC      = gcc
MODNAME := OnlineBIOSUpdate
KDIR	:= /lib/modules/$(shell uname -r)/build
PWD	:= $(shell pwd)
MAJOR	= $(shell cat /proc/devices | awk '$$2=="OnlineBIOSUpdate" {print $$1}')
DEVFILE = $(wildcard /dev/$(MODNAME))

.PHONY:	all build install uninstall node clean allclean

all: build

ifeq ($(shell uname -r | cut -d . -f 1-2),2.6)
TARGET	:= $(MODNAME).ko
obj-m	:= $(MODNAME).o

clean:
	-make -C $(KDIR) SUBDIRS=$(PWD) clean
	@rm -f Module*.symvers
endif
ifeq ($(shell uname -r | cut -d . -f 1-2),2.4)
TARGET	:= $(MODNAME).o
ARCH	:= $(shell uname -m | sed -e s/i.86/i386/ -e s/x86_64/x86_64/)
CPU	:= $(shell uname -r | sed -e 's/.*smp/smp/' -e 's/.*[^smp].*/up/')
INCLUDE	:= -I$(KDIR)/include

CFLAGS	= -D__KERNEL__ -DMODULE
CFLAGS	+= -Wall -Wstrict-prototypes -Wno-trigraphs -O2 -fomit-frame-pointer -fno-strict-aliasing -fno-common

ifeq ($(ARCH),x86_64)
CFLAGS	+= -mcmodel=kernel -mno-red-zone -D__x86_64__
endif

ifeq ($(CPU),smp)
CFLAGS  += -DCONFIG_SMP
endif

clean:
	-rm -f $(TARGET)
endif

build: $(TARGET)

$(MODNAME).o: $(MODNAME).c
	@gcc $(HOSTCFLAGS) $(CFLAGS) $(INCLUDE) -c $< -o $@
$(MODNAME).o: $(MODNAME).h

$(MODNAME).ko: $(MODNAME).c
	@make -C $(KDIR) SUBDIRS=$(PWD) modules
$(MODNAME).ko: $(MODNAME).h

install: $(TARGET)
	@/sbin/insmod $(TARGET)

uninstall:
	@/sbin/rmmod  $(MODNAME)
ifneq ($(strip $(DEVFILE)), )
	@rm -f /dev/$(MODNAME)
endif

node:
ifeq ($(strip $(DEVFILE)), )
	@mknod /dev/$(MODNAME) c $(MAJOR) 0
endif

allclean: uninstall clean
