# --------------------------------------------------------------------------
#
# Makefile for xwatch
#
# --------------------------------------------------------------------------

# Note: you will need the XForms library to get things compiled. You can
# obtain the library at one of the Linux ftp sites (sunsite.unc.edu,
# tsx-11.mit.edu) or at the primary sites: bloch.phys.uwm.edu:/pub/xforms
# and ftp.cs.ruu.nl:/pub/XFORMS. This XWatch will compile with version 0.81 
# of XForms. If you can't access the primary sites, get bxform-081.tar.gz 
# (or similar) from ftp.icce.rug.nl/pub/unix. That's the Linux ELF version. 
# For other platforms you're on your own, but XForms is available for _lots_
# of systems.

# If you have installed XForms as the Makefile of the package does, you won't
# have any problems compiling all. Otherwise, set XFLIBDIR to "-L..." (the
# directory where the library lives) and XFLIBINC to "-I..." (the directory
# where the include file forms.h lives).
# XFLIBDIR = -L/usr/local/lib
# XFINCDIR = -I/usr/local/inc

# A `make install' will create a stripped version of xwatch and install it
# to BINDIR. Define that directory here. If you want to make the program first
# to check it out, before installing it, must do a `make final' and test the
# program. Then do the "make install" when you're satisfied.
BINDIR = /usr/local/X11/bin
MANDIR = /usr/local/man/man1

# X barfs on too long commandlines (X11R6 does at least). Comment this out
# if you don't want commandline length checks. XWatch might get too long
# commandlines if you do something like "xwatch /var/adm/*".
CMDLINEFLAG = -DMAXCMDLINE=1024

# Where is the with the rgb values. The default is "/usr/lib/X11/rgb.txt".
# Modify the following RGB_FILEFLAG if your file is named differently.
# Thanks, Christian Motschke, motschke@first.gmd.de.
# RGB_FILEFLAG = -DRGB_FILE=\\\"/usr/lib/X11/rgb.txt\\\"

# If you're on a Sun, you might not have the function strerror().
# If the linkage phase barfs about a missing symbol _strerror or something 
# similar, undefine the following:
# STRERROR = strerror.o

# I've seen a report from someone who needed a "-lXpm" flag in the linkage
# phase. I never needed that, but you might, who knows.
# If the linkage fails, try adding the -lXpm to the below STDLFLAGS and
# DEBUGLFLAGS definitions. 

# Standard compilation flags. You probably won't have to change these, if
# you are using gcc.
STDCFLAGS = -c -O2 -Wall $(CMDLINEFLAG) $(RGB_FILEFLAG) $(XFINCDIR)
STDLFLAGS = -s -L/usr/X11R6/lib

# Compilation flags for `make debug'. Again, OK for gcc. Probably only relevant
# for me, the developer. The DEBUGLFLAGS may need -static, depends on your
# compiler and stuff.
DEBUGCFLAGS = -g
DEBUGLFLAGS =

# You have edited enough. Now run `make'.
# 
# --------------------------------------------------------------------------

# Version of this XWatch.
VER = 2.11

# How to get to an object file.
.c.o:
	$(CC) $(CFLAGS) -DVER=\"$(VER)\" $<

# objects we need for the program
OBJ =  xwatch.o usage.o ui.o parsegag.o xmalloc.o xrealloc.o xstrdup.o \
       alarmhandler.o addfile.o scanfile.o parsecolorstring.o \
       warning.o addline.o error.o checksetting.o getcolorindex.o \
       parsegeometry.o parseignore.o colorname2rgb.o parsecolors.o \
       colorname2index.o \
       $(STRERROR)

foobar:
	@echo 'Make what? Choose one of:'
	@echo 'make final : make final version of xwatch'
	@echo 'make debug : make debugging version of xwatch'
	@echo 'make clean : remove objects and binary'
	@echo 'make install : make final version and install to' $(BINDIR)
	@echo 'make dist : make distribution (for me, Karel, only)'
	exit 1

final:
	make xwatch CFLAGS="$(STDCFLAGS)" LFLAGS="$(STDLFLAGS)"

debug:
	make xwatch CFLAGS="$(STDCFLAGS) $(DEBUGCFLAGS)" \
	    LFLAGS="$(DEBUGLFLAGS)"

clean:
	rm -f xwatch $(OBJ) core

install: final
	install -m 755 xwatch $(BINDIR)/xwatch
	install -m 644 ../doc/xwatch.man $(MANDIR)/xwatch.1

xwatch: $(OBJ)
	$(CC) -o xwatch $(OBJ) $(XFLIBDIR) -lforms -lX11 -lm $(LFLAGS)

dist: clean
	header -0ak *.c *.h
	header -rk *.c *.h
	./.makedist $(BINDIR) $(VER)

# extra deps
xwatch.o: xwatch.c Makefile flres.h settings.h data.inc
usage.o: usage.c Makefile
colorname2rgb.o: colorname2rgb.c Makefile
