# vi: ts=8 sw=8
#
# TI USB 3410/5052 Driver Makefile
#
# Copyright (C) 2004 Texas Instruments
#
# 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.
#
# For questions or problems with this driver, contact Texas Instruments
# technical support, or Al Borchers <alborchers@steinerpoint.com>, or
# Peter Berger <pberger@brimson.com>.
# 
# $Id: Makefile.in,v 1.1.1.1 2007-02-26 20:34:32 dwm Exp $
#

K_CC = gcc
K_CFLAGS = -march=i686 -mpreferred-stack-boundary=2
K_SOURCE_DIR = /usr/src/linux-2.4.21-50.EL
K_MODULE_DIR = /lib/modules/2.4.21-50.EL

include $(K_SOURCE_DIR)/.config

INCLUDES = -I$(K_SOURCE_DIR)/include

K_CFLAGS += -D__KERNEL__ -DMODULE $(INCLUDES) \
	-Wall -Wstrict-prototypes -Wno-trigraphs -O2 \
	-fno-strict-aliasing -fno-common -pipe
ifndef CONFIG_FRAME_POINTER
	K_CFLAGS += -fomit-frame-pointer
endif
ifdef CONFIG_SMP
	K_CFLAGS += -D__SMP__
endif
ifdef CONFIG_MODVERSIONS
	K_CFLAGS += -DMODVERSIONS -include $(K_SOURCE_DIR)/include/linux/modversions.h
endif
#	K_CFLAGS += -DALLOW_USB_SERIAL

MODULES = ti_usb.o
MODULE_DIR = $(K_MODULE_DIR)/misc

DEVICE_NAME=/dev/ttyTIUSB
DEVICE_COUNT=16
DEVICE_GROUP=
DEVICE_PERMISSIONS=0600

.PHONY: build clean clobber install uninstall ti_usb_devices


build:	$(MODULES)


clean: 
	rm -f *.o


clobber: clean
	rm -f Makefile


install: build
	-rm -f $(MODULE_DIR)/ti_3410_5052.o
	-rm -f /etc/hotplug/usb/ti_usb
	install -m 0755 -d $(MODULE_DIR)
	install -m 0644 $(MODULES) $(MODULE_DIR)
	install -m 0755 -d /etc/ti_usb
	install -m 0755 make_devices /etc/ti_usb
	if ! grep "^post-install ti_usb /etc/ti_usb/make_devices" /etc/modules.conf > /dev/null 2>&1; \
	then \
		echo "post-install ti_usb /etc/ti_usb/make_devices" >> /etc/modules.conf; \
	fi
	-rmmod ti_usb > /dev/null 2>&1
	/sbin/depmod -ae
	/sbin/modprobe ti_usb


install_rpm: 
	install -m 0755 -d $(TI_USB_BUILDROOT)/etc/ti_usb
	install -m 0644 $(MODULES) $(TI_USB_BUILDROOT)/etc/ti_usb
	install -m 0755 make_devices $(TI_USB_BUILDROOT)/etc/ti_usb


uninstall:
	-/etc/ti_usb/make_devices remove

	rm -f /etc/modules.conf.tmp
	grep -v "^post-install ti_usb /etc/ti_usb/make_devices" /etc/modules.conf > /etc/modules.conf.tmp
	mv -f /etc/modules.conf.tmp /etc/modules.conf

	(cd $(MODULE_DIR); rm -f $(MODULES))
	rm -rf /etc/ti_usb
	-rmmod ti_usb > /dev/null 2>&1
	/sbin/depmod -ae


ti_usb.o: ti_usb_3410_5052.o ti_usb_serial.o
	$(LD) -r $^ -o $@


ti_usb_3410_5052.o: ti_usb_3410_5052.c ti_usb_3410_5052.h ti_usb_serial.h usb-serial.h ti_fw_3410.h ti_fw_5052.h mts_fw_cdma.h mts_fw_gsm.h mts_fw_edge.h mts_usb.h
	$(K_CC) $(K_CFLAGS) -c ti_usb_3410_5052.c -o ti_usb_3410_5052.o


ti_usb_serial.o: ti_usb_serial.c ti_usb_serial.h usb-serial.h
	$(K_CC) $(K_CFLAGS) -c ti_usb_serial.c -o ti_usb_serial.o


ti_usb_devices:
	/etc/ti_usb/make_devices remove
	sed \
	-e "s!^DEVICE_NAME=.*!DEVICE_NAME=$(DEVICE_NAME)!" \
	-e "s/^DEVICE_COUNT=.*/DEVICE_COUNT=$(DEVICE_COUNT)/" \
	-e "s/^DEVICE_GROUP=.*/DEVICE_GROUP=$(DEVICE_GROUP)/" \
	-e "s/^DEVICE_PERMISSIONS=.*/DEVICE_PERMISSIONS=$(DEVICE_PERMISSIONS)/" \
	/etc/ti_usb/make_devices > /etc/ti_usb/make_devices.new
	mv /etc/ti_usb/make_devices.new /etc/ti_usb/make_devices
	chmod +x /etc/ti_usb/make_devices
	/etc/ti_usb/make_devices
