#****************************************************************#
#                             NOTICE                             #
#                                                                #
#    This source code contains proprietary and confidential      #
#    information, and is the property of Ncast Corporation.      #
#                                                                #
#    This program has been distributed under license agreement   #
#    and any unauthorized use or distribution is prohibited.     #
#                                                                #
#    Copyright (c) 2005-2006 by Ncast Corporation.               #
#                                                                #
#    All rights reserved.                                        #
#****************************************************************#

MODULE  := digiupdate
DRVOBJS := digi.o digiupdatefunc.o FPGAcode.o
DRVOBJS += ../fpgaprog/FPGAupdate.o ../fpgaprog/decompress.o ../fpgaprog/iobase.o ../fpgaprog/jtag.o ../fpgaprog/progalgxc3s.o 
INSTALL_DIR := /lib/modules/$(shell uname -r)/kernel/drivers/media/video

KERNEL_SOURCES := /lib/modules/$(shell uname -r)/build


#test for kernel 2.6.x

ifeq (1,1) 

ifneq ($(KERNELRELEASE),)

obj-m += $(MODULE).o
$(MODULE)-objs := $(DRVOBJS)

else

all:
	$(MAKE) -C $(KERNEL_SOURCES) SUBDIRS=$(PWD) modules

clean:
	$(MAKE) -C $(KERNEL_SOURCES) SUBDIRS=$(PWD) clean

endif


install:
	install -m 744 -o root $(MODULE).ko $(INSTALL_DIR)
	/sbin/depmod -a

uninstall:
	@if [ -f $(INSTALL_DIR)/$(MODULE).ko ]; then \
		rm -f $(INSTALL_DIR)/$(MODULE).ko; \
		/sbin/depmod -a; \
	fi;



else

KERNEL_HEADERS= $(KERNEL_SOURCES)/include
CC=gcc


CFLAGS = -D__KERNEL__ -DMODULE 
CFLAGS += -I$(KERNEL_HEADERS) -I$(KERNEL_HEADERS)/linux -I. 
CFLAGS += -Wall -O2 -pipe -fomit-frame-pointer
CFLAGS += -DMODVERSIONS -include $(KERNEL_HEADERS)/linux/modversions.h

# remap_page_range
REMAP_PAGE_RANGE := $(shell sh ./remaptest.sh "$(CC)" "$(KERNEL_SOURCES)")
ifeq ($(REMAP_PAGE_RANGE), 5)
CFLAGS += -DREMAP_REDHAT
endif

all: $(MODULE).o

$(MODULE).o: $(DRVOBJS)
	$(LD) -r $^ -o $@

clean:
	rm -f *.o *~ fpgaprog/*.o fpgaprog/*~


install:
	install -m 644 -o root $(MODULE).o $(INSTALL_DIR)
	/sbin/depmod -a

uninstall:
	@if [ -f $(INSTALL_DIR)/$(MODULE).o ]; then \
		rm -f $(INSTALL_DIR)/$(MODULE).o; \
		/sbin/depmod -a; \
	fi;



endif
