####################### configurable stuff ###########################

######################################################################
# cqcam = the command-line version (outputs PPM graphics on stdout)
# xcqcam = the X11 version w/ or w/o the remote control
# Compile both, or just one?
PROGRAMS = cqcam xcqcam
#PROGRAMS = cqcam
######################################################################

######################################################################
# Remote control
#   There are two versions of the remote control, one using xview and olgx,
#   and the other using Tcl/Tk.
#   I recommend the using the xview remote (the default) when possible, just
#   because that's the one I can support best if you have problems.
#   Uncomment the lines corresponding to the version of the remote that
#   you want to use (if any).
#   If you're not compiling xcqcam, this section is irrelevant

# xview remote
#REMOTE_OBJS = xqcctl.o               # code module for the remote
#REMOTE_DEFS = -DREMOTE
#REMOTE_LIBS = -lxview -lolgx         # libraries necessary for the remote
#REMOTE_LDFLAGS = -L/usr/openwin/lib  # where to find libxview and libolgx
#REMOTE_CFLAGS = -I/usr/openwin/include

# Tk remote
REMOTE_OBJS = xqcctl-tk.o            # code module for the remote
REMOTE_DEFS = -DREMOTE
REMOTE_LIBS = -lm -ldl -ltk -ltcl    # libraries necessary for the remote
REMOTE_LDFLAGS =
REMOTE_CFLAGS =
######################################################################

######################################################################
# OS-specific stuff: uncomment all of the lines for your OS of choice

# Linux
CFLAGS = -O2
LDFLAGS = -s
DEFS += -DLINUX

# QNX
#CFLAGS = -O2 -T1
#LDFLAGS = -T1
#DEFS += -DQNX

# FreeBSD
#CFLAGS = -O2 -I/usr/X11R6/include -I/usr/local/include
#LDFLAGS = -L/usr/local/lib -L/usr/X11R6/lib
#DEFS += -DFREEBSD

# BSDI 3.0
#CFLAGS = -O2 -I/usr/X11R6/include -I/usr/local/include
#LDFLAGS = -L/usr/local/lib -L/usr/X11R6/lib
#DEFS += -DBSDI

# LynxOS
#CFLAGS = -O2
#LDFLAGS =
#DEFS += -DLYNX
#OBJ_CQCAM += lynx-io.o lynx-ioaccess.o
#OBJ_XCQCAM += lynx-io.o lynx-ioaccess.o
######################################################################

######################################################################
# X11 stuff: where are your X11 .h and .a files?

LDFLAGS_X = -L/usr/X11R6/lib $(REMOTE_LDFLAGS)
LIBS_X = -lX11 -lXext $(REMOTE_LIBS)
######################################################################

######################################################################
# Installation information
BINDIR = /usr/local/bin
BINMODE = 4711
BINUSER = root
BINGROUP = bin
MANDIR = /usr/local/man/man1
######################################################################

######################################################################
# Compiler information: where are CC and LD?
#CC = cc
CC = g++
#CC = gcc
LD = g++
#LD = cc
#LD = gcc
######################################################################

######################################################################
# Developer debugging stuff
#CFLAGS += -Wall
#CFLAGS += -g
#DEFS += -DDEBUG
######################################################################


##################### non-configurable stuff #########################
##### most users will not need to bother editing below this line #####

#LDLIBS += -lm
DEFS += $(REMOTE_DEFS)
MANPAGES = cqcam.1
OBJ_CQCAM += port.o camera.o cqcam.o imager.o rcfile.o
OBJ_XCQCAM += port.o camera.o xcqcam.o xscan.o imager.o rcfile.o \
	$(REMOTE_OBJS)

all: message $(PROGRAMS) $(MANPAGES)

message:
	@echo "Have you read INSTALL?  How about config.h?" ; \
	echo ; \
	echo "If things don't work, see the man page for how to submit a useful bug report." ; \
	echo

install: bininstall maninstall rcinstall
	@echo;\
	echo "You will probably want to copy \".cqcrc\" to your home directory";\
	echo "and edit it for your system."

bininstall: all
	@echo -n Installing binaries...
	@install -o $(BINUSER) -g $(BINGROUP) -m $(BINMODE) $(PROGRAMS) $(BINDIR)
	@echo " done"

maninstall: cqcam.1
	@echo -n Installing man pages...
	@install -o root -g root -m 644 cqcam.1 $(MANDIR)
	@ln -sf cqcam.1 $(MANDIR)/xcqcam.1
	@echo " done"

rcinstall: .cqcrc
	@echo -n Installing configuration file...
	@cp .cqcrc ~
	@echo " done"

clean:
	rm -f *.o $(PROGRAMS)

cqcam: $(OBJ_CQCAM)
	@echo -n Linking $@...
	@$(LD) $(LDFLAGS) $(LDLIBS) $(OBJ_CQCAM) -o $@
	@echo " done"

xcqcam: $(OBJ_XCQCAM)
	@echo -n Linking $@...
	@$(LD) $(LDFLAGS) $(LDLIBS) $(LDFLAGS_X) $(OBJ_XCQCAM) -o $@ $(LIBS_X)
	@echo " done"

cqcsrv: cqcsrv.o camera.o port.o
	@echo -n Linking $@...
	@$(LD) $(LDLIBS) $(LDFLAGS) cqcsrv.o camera.o port.o imager.o -o $@
	@echo " done"

.C.o: $*.C
	@echo -n Compiling $*.C...
	$(CC) $(DEFS) $(CFLAGS) $(REMOTE_CFLAGS) -c $< -o $@
	@echo " done"

.s.o: $*.s
	@echo -n Assembling $*.s...
	@$(AS) -o $@ $<
	@echo " done"
