#----------------------------------------
# makefile for GSC-16AO Linux driver
#----------------------------------------
# List of source files
#

TARGET= gsc_16ao4mf
OBJS= init.o main.o ioctl.o proc.o read.o write.o hardware.o 

#
# The following is used for development - this helps keep the
# driver from being released with debug active.
#

ifdef GSC_DEV
 CFLAGS+= -DDEBUG  #-print-search-dirs -v
endif

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 #-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 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 driver for 2.6 kernel.'
	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

clean:
	-rm -f *.o *.ko .*.cmd .*.flags *.mod.c .tmp_versions/* core 


