#=========================================================
# Makefile for the Lucent modem driver ltmodem.o
#    for service with Linux kernels 2.2.nn and 2.4.nn
#=========================================================
#
#      with symbolic link:  linux --> kernel-sources 
#         after make clean, config sources with MODVERSIONS=yes , and make dep
# SYSTEM = PATHto/kernel-headers-version/
#      has served equally well in trials 
# KCFLAGS_EXTRA allows extra gcc options to be specified on the `make' line
#
# Warning - TAB ins  rather than SPACES must be used in Makefile editing,
#  or their will be a "missing separator" complaint
#
LT_VERSION = 5.78e
ifneq (,$(findstring RELEASE,$(LT_VERSION)))
LT_VERSION = 5.78-test
endif

SYSTEM = /usr/src/linux/

KCFLAGS = -D__KERNEL__ -I$(SYSTEM)include \
	-Wall -Wstrict-prototypes -O2 \
	-fomit-frame-pointer -fno-strict-aliasing -pipe \
	-fno-strength-reduce -m486 -malign-loops=2 \
	-malign-jumps=2 -malign-functions=2 -DCPU=586 \
	-DMODULE \
	-DLT_VERSION=$(LT_VERSION)

KCFLAGS3 = $(KCFLAGS) \
	-DMODVERSIONS \
	-include $(SYSTEM)include/linux/modversions.h


#CC=gcc -D__KERNEL__ -DMODULE -w -O2 -fomit-frame-pointer 
#CC=gcc $(KCFLAGS2) -D__KERNEL__ -DMODULE -w -O2 -fomit-frame-pointer -I$(SYSTEM)include
CC = gcc $(KCFLAGS) $(KCFLAGS_EXTRA)
#CC = gcc $(KCFLAGS_EXTRA) $(KCFLAGS) 

KVERSION := $(shell uname -r)
KMODE := $(findstring 2.4, $(KVERSION))
ifeq ($(KMODE),)
KMODE := $(findstring 2.2, $(KVERSION))
endif

ifeq ($(KMODE),)
all install :
	@echo "error: Cant determine kernel version with uname -r"
endif

ifeq ($(KMODE),2.4)

#SERIALC := $(SYSTEM)drivers/char/serial.c
#SERIALC1 := $(shell ls $(SERIALC))
#ifneq ($(SERIALC),$(SERIALC1))
#SERIALC := serial.c.240test11
SERIALC := serial.c.240
#endif


LINUXOBJS := \
        serial-lt-2.4.a \
        ltmodem-2.4.a	\
 
all: $(LINUXOBJS) ltmodem.o
install: install1

serial-lt-2.4.c : $(SERIALC) serial-2.4.patch ltmodem-2.4.c
	-cp -f $(SERIALC) $@
	patch -N -b -p0 < serial-2.4.patch

ltmodem-2.4.c : ltmodem.c linuxif-2.4.h
	-cp -f $< $@
	patch -N -b -p0 < ltmodem-2.4.patch

linuxif-2.4.h : linuxif.h
	-cp -f $< $@

clean::
	-rm -f serial-lt-2.4.c ltmodem-2.4.c linuxif-2.4.h

endif

ifeq ($(KMODE),2.2)

LINUXOBJS := \
        serial.a \
        ltmodem.a
 
all: $(LINUXOBJS) ltmodem.o
install: install1

endif

ltmodem.o: $(LINUXOBJS) ltmdmobj.a
	ld -r -o ltmodem.o $(LINUXOBJS) ltmdmobj.a

ltmdmobj.a: ltmdmobj.o
	objcopy --redefine-sym=rs_interrupt_single=rs_interrupt_lucent $< $@

install1:
	make all
	./ltinst

%.a: %.c
	$(CC) -c -o $@ $<


clean::
	-rm -f *.orig
	-rm -f *.a
	-rm -f *.rej
	-rm -f ltmodem-*.tar.gz
	-rm -f *~ *.bak
	-rm -f ltmodem.o
	-rm -f serial-lt-2.4.c linuxif-2.4.h ltmodem-2.4.c
 
