#
# Makefile for DigiTemp
#
# Copyright 1996-2003 by Brian C. Lane <bcl@brianlane.com>
# See COPYING for GNU Public License
#

VERSION = 3.1.0

CC	= gcc
CFLAGS	= -I./src -I./userial -O2  -g -Wall
LIBS	= -lm

OBJS		=	src/digitemp.o src/device_name.o
HDRS		= 	src/digitemp.h src/device_name.h

# Common userial header/source
HDRS		+=	userial/ownet.h userial/owproto.h
OBJS		+=	userial/crcutil.o userial/ioutil.o userial/swt1f.o \
			userial/owerr.o userial/cnt1d.o

# DS9097 passive adapter support source
DS9097OBJS	=	userial/ds9097/ownet.o userial/ds9097/linuxlnk.o \
			userial/ds9097/linuxses.o userial/ds9097/owtran.o

# DS9097-U adapter support source
DS9097UOBJS	=	userial/ds9097u/ds2480ut.o userial/ds9097u/ownetu.o \
			userial/ds9097u/owllu.o userial/ds9097u/owsesu.o \
			userial/ds9097u/owtrnu.o userial/ds9097u/linuxlnk.o

# -----------------------------------------------------------------------
# Sort out what operating system is being run and modify CFLAGS and LIBS
#
# If you add a new OSTYPE here please email it to me so that I can add
# it to the distribution in the next release
# -----------------------------------------------------------------------
SYSTYPE := $(shell uname -s)

ifeq ($(SYSTYPE), Linux)
  CFLAGS += -DLINUX
endif

ifeq ($(SYSTYPE), SunOS)
  CFLAGS += -DSOLARIS
  LIBS   += -lposix4
endif

ifeq ($(SYSTYPE), FreeBSD)
  CFLAGS += -DFREEBSD
endif

ifeq ($(SYSTYPE), AIX)
  CFLAGS += -DAIX
endif

help:
	@echo "  SYSTYPE = $(SYSTYPE)"
	@echo "  CFLAGS = $(CFLAGS)"
	@echo "  LIBS   = $(LIBS)"
	@echo ""
	@echo "Pick one of the following targets:"
	@echo -e "\tmake ds9097\t- Build version for DS9097 (passive)"
	@echo -e "\tmake ds9097u\t- Build version for DS9097U"
	@echo " "

all:		help


# Build the Linux executable
ds9097:		$(OBJS) $(HDRS) $(ONEWIREOBJS) $(ONEWIREHDRS) $(DS9097OBJS)
		$(CC) $(OBJS) $(ONEWIREOBJS) $(DS9097OBJS) -o digitemp $(LIBS)

ds9097u:	$(OBJS) $(HDRS) $(ONEWIREOBJS) $(ONEWIREHDRS) $(DS9097UOBJS)
		$(CC) $(OBJS) $(ONEWIREOBJS) $(DS9097UOBJS) -o digitemp $(LIBS)


# Clean up the object files and the sub-directory for distributions
clean:
		rm -f *~ src/*~ userial/*~ userial/ds9097/*~ userial/ds9097u/*~
		rm -f $(OBJS) $(ONEWIREOBJS) $(DS9097OBJS) $(DS9097UOBJS)
		rm -f core *.asc 
		rm -f perl/*~ rrdb/*~ .digitemprc digitemp-$(VERSION)-1.spec
		rm -rf digitemp-$(VERSION)

# Sign the binaries using gpg (www.gnupg.org)
# My key is available from www.brianlane.com
sign:
		gpg -ba digitemp
		echo

# Install digitemp into /usr/local/bin
install:	digitemp
		install -b -o root -g bin digitemp /usr/local/bin

# Build the archive of everything
archive:	digitemp clean sign
		cd .. && tar cvzf digitemp-$(VERSION).tar.gz digitemp-$(VERSION)/* --exclude *.o

# Build the source distribution
source:		archive

dist:		archive

# Build RedHat binary and source RPMs
rpm_ds9097:	ds9097 dist
	su -c "cp ../digitemp-$(VERSION).tar.gz /usr/src/redhat/SOURCES"
	rm -f digitemp-$(VERSION)-1.spec
	ln -s digitemp_9097.spec digitemp-$(VERSION)-1.spec
	su -c "rpmbuild -ba -vv digitemp-$(VERSION)-1.spec"

rpm_ds9097u:	ds9097u dist
	su -c "cp ../digitemp-$(VERSION).tar.gz /usr/src/redhat/SOURCES"
	rm -f digitemp-$(VERSION)-1.spec
	ln -s digitemp_9097u.spec digitemp-$(VERSION)-1.spec
	su -c "rpmbuild -ba -vv digitemp-$(VERSION)-1.spec"

