#------------------------------------------------------------------------------
# makefile for General Standards Linux drivers
#------------------------------------------------------------------------------
#
TARGET:=gsc24dsi32pll
#
DRIVER_VERSION:="1.0.6"
#
#==============================================================================
# Revision History
#
# Version 1.0.6 - Released 3/23/2006
#  - Enabled demand-mode DMA.
#
# Version 1.0.5 - Released 3/19/2006 
#  - Added support for using the system timer instead of local
#    interrupts.
#  - Added preliminary support for RTLinux.
#
# Version 1.0.4 - Fixed a bug where "wait for channels ready" was causing
#   an error message in the system log.
#
# Version 1.0.3 - Released 1/19/2007
# - Added code to demonstrate voltage conversion to the test application.
#
# Version 1.0.2 - Released 1/10/2007
#   - Cleaned up build process.
#   - Cleaned up test application.
#	- Moved the revision history to the makefile.
#
# Version 1.0.1 - Released 11/29/2006
#   - New release to support the 24DSI32PLL.
#
#==============================================================================
#
# List of source files
#
OBJS= hardware.o main.o ioctl.o proc.o init.o read.o write.o mmap.o dma.o local_hw.o
#
# The following is used for development - this helps keep the
# driver from being released with debug active.  Comment the 
# '#ifdef GSC_DEV' and 'endif' to enable full debugging.
#
ifdef GSC_DEV
 CFLAGS+= -DDEBUG #-print-search-dirs -v 
endif
#
# pass the driver version to the build
#
	CFLAGS+=-DDRIVER_VERSION='$(DRIVER_VERSION)'
	CFLAGS+=-DGSC_TARGET=\"$(TARGET)\"
#
# below here is mostly generic
#
MDIR:= drivers/misc
#EXTRA_CFLAGS= -DEXPORT_SYMTAB
CURRENT= $(shell uname -r)
KDIR= /lib/modules/$(CURRENT)/build
PWD= $(shell pwd)
DEST= /lib/modules/$(CURRENT)/kernel/$(MDIR)

#
################################################
# build for 2.2 kernel
################################################
#ifeq ($(shell uname -r | cut -d . -f 1-2),2.2)
#
# not tested...
#
#endif
################################################
# build for 2.4 kernel
################################################
ifeq ($(shell uname -r | cut -d . -f 1-2),2.4)

# Edit the following line to point to the top
# of the kernel source tree.
#
KERNELDIR = /usr/src/linux-2.4
#
# below here should not require modification
#

CFLAGS+= -I$(KERNELDIR)/include \
		-I$(KERNELDIR)/include/linux \
		-I$(KERNELDIR)/include/asm \
		-O2 -Wall -Wstrict-prototypes -D__KERNEL__ -DMODULE \
		-Winline -finline-functions \
		#-DDEBUG #-print-search-dirs -v


ifdef CONFIG_SMP
 CFLAGS+= -D__SMP__ -DSMP
endif

# Prepend modversions.h if we're running with versioning.
ifdef CONFIG_MODVERSIONS
	CFLAGS += -DMODVERSIONS -include $(KERNELDIR)/include/linux/modversions.h
endif

all: 	$(TARGET).o

$(TARGET).o: $(OBJS)
	ld -r -o $@ $^

endif  # End kernel version 2.4

################################################
# build for rtl kernel
################################################
ifeq ($(shell uname -r | cut -d - -f 2),rtl)
include /opt/rtldk-2.2/rtlinuxpro/rtl.mk

CFLAGS += -D__KERNEL__ -I../../include
	CFLAGS+=-DDRIVER_VERSION='$(DRIVER_VERSION)'
	CFLAGS+=-DGSC_TARGET=\"$(TARGET)\"
	CFLAGS+=-DRTL

TARGET= gs_ad
#OBJS= init.o main.o hardware.o ioctl.o read.o write.o

default: $(TARGET).rtl $(TARGET)_test.rtl 

$(TARGET).o: $(OBJS)
	@echo $(TARGET) > gsc_target
	@echo $(DRIVER_VERSION) > gsc_version
	$(LD) -r -o $@ $(OBJS)

include $(RTL_DIR)/Rules.make

else

################################################
# build for 2.6 kernel
################################################

ifeq ($(shell uname -r | cut -d . -f 1-2),2.6)


$(TARGET)-objs := $(OBJS)
 obj-m := $(TARGET).o

default:
	@echo '    Building General Standards $(TARGET) driver version $(DRIVER_VERSION) for 2.6 kernel.'
	@echo $(TARGET) > gsc_target
	@echo $(DRIVER_VERSION) > gsc_version
	make -C $(KDIR) SUBDIRS=$(PWD) modules

$(TARGET).o: $(OBJS)
	$(LD) $(LD_RFLAG) -r -o $@ $(OBJS)

ifneq (,$(findstring 2.4.,$(CURRENT)))
install:
	su -c "cp -v $(TARGET).o $(DEST) && /sbin/depmod -a"
else
install:
	su -c "cp -v $(TARGET).ko $(DEST) && /sbin/depmod -a"
endif

-include $(KDIR)/Rules.make
endif  # End kernel version 2.6
endif
clean:
	-rm -f *.o .*.cmd .*.flags *.mod.c .tmp_versions/* core .temp_versions *.bak *~ *.rtl



