# ------------------------------------------------------------
# RCSID: $Id: Makefile,v 1.5 1999/05/14 21:52:06 cmalek Exp $
# ------------------------------------------------------------

UNAME	:=	$(shell uname)
DIR	:=	$(shell basename `pwd`)

VERSION = 1.5.0

# ------------------------------------------------------------
# Useful programs
# ------------------------------------------------------------
CC 				= gcc -Wall -g
LD 				= gcc 
CDEBUG			= -g
CCOPTIONS = -pipe

INSTALL 		= install
AR 				= ar clq
RANLIB 			= ranlib

LN 				= ln -s
MAKE 			= make
MV 				= mv
CP 				= cp
RM 				= rm -f
TAGS 			= ctags

ifeq "$(UNAME)" "Linux"
MKDIRHIER 		= /bin/sh mkdirhier
else
MKDIRHIER 		= /bin/sh /usr/bin/X11/mkdirhier
endif
DEPEND 			= makedepend

# ------------------------------------------------------------
# Install stuff
# ------------------------------------------------------------
INSTALL_LIBDIR = /usr/local/lib
INSTALL_INCDIR = /usr/local/include

# ------------------------------------------------------------
# Include directories
# ------------------------------------------------------------
INCLUDES = -I.

# ------------------------------------------------------------
# Libraries
# ------------------------------------------------------------
XLIBS = -L/usr/X11R6/lib -lXt -lXmu -lX11 -lXext -lm
LIBATPLOTTER = -L./$(UNAME) -lAtPlotter
PSDRIVER = -L/usr/local/lib -lpsdriver

LIBS = $(LIBATPLOTTER) $(PSDRIVER) $(XLIBS)

# ------------------------------------------------------------
# Defines
# ------------------------------------------------------------
DEFINES = -DUSE_SMALLER_FONTS -DDFLT_FONTFAMILY=\"helvetica\"

# ------------------------------------------------------------
# CFLAGS
# ------------------------------------------------------------
ifeq "$(UNAME)" "Linux"
CFLAGS  = 	-Wall -m486 -D_GNU_SOURCE $(CDEBUG) $(INCLUDES) $(DEFINES)
else
ifeq "$(UNAME)" "SunOS"
CFLAGS     = -Wall $(CDEBUG) -D_GNU_SOURCE $(INCLUDES) $(DEFINES)
endif
endif

#-------------------------------------------------------------------------

HEADERS = \
        At.h\
        AxisCore.h\
        AxisCoreP.h\
        QuadAxis.h\
        QuadAxisP.h\
        QuadLabelAxis.h\
        QuadLabelAxisP.h\
        Plot.h\
        PlotP.h\
        QuadPlot.h\
        QuadPlotP.h\
        QuadLinePlot.h\
        QuadLinePlotP.h\
        QuadBarPlot.h\
        QuadBarPlotP.h\
        TextPlot.h\
        TextPlotP.h\
        Plotter.h\
        PlotterP.h\
        Scale.h\
        Shading.h\
        FontFamily.h\
        FontFamilyP.h\
        Text.h\
        AtConverters.h\
        patchlevel.h

SRCS = \
        AtConverters.c\
        AxisCore.c\
        QuadAxis.c\
        QuadLabelAxis.c\
        Plot.c\
        QuadPlot.c\
        QuadLinePlot.c\
        QuadBarPlot.c\
        TextPlot.c\
        Plotter.c\
        Scale.c\
        Shading.c\
        FontFamily.c\
        Text.c\
        $(STRCASECMP_C)

OBJS = \
        AtConverters.o\
        AxisCore.o\
        QuadAxis.o\
        QuadLabelAxis.o\
        Plot.o\
        QuadPlot.o\
        QuadLinePlot.o\
        QuadBarPlot.o\
        TextPlot.o\
        Plotter.o\
        Scale.o\
        Shading.o\
        FontFamily.o\
        Text.o\
        $(STRCASECMP_O)
ATPLOTTER_OBJS = atplotter.o

ARCHOBJS = $(addprefix $(UNAME)/,$(OBJS)) 
ATPLOTTER_ARCHOBJS = $(addprefix $(UNAME)/,$(ATPLOTTER_OBJS)) 

# -----------------------------------------------------------
# Targets
# -----------------------------------------------------------

all: libAtPlotter.a atplotter

atplotter: $(UNAME)/atplotter
.PHONY: atplotter

libAtPlotter.a: $(UNAME)/libAtPlotter.a
.PHONY: libAtPlotter.a

$(UNAME)/libAtPlotter.a: $(ARCHOBJS)
	$(RM) $@
	$(AR) $@ $(ARCHOBJS)
	$(RANLIB) $@

$(UNAME)/atplotter: $(ATPLOTTER_ARCHOBJS)
	$(RM) $@
	$(LD) $(CDEBUG) $(ATPLOTTER_ARCHOBJS) $(LIBS) -o $@


clean:
	$(RM) $(UNAME)/*.o 

binclean:
	$(RM) $(UNAME)/*.a $(UNAME)/atplotter

distclean: clean binclean

dist: distclean
	(cd ..; tar zcv -X $(DIR)/.exclude -f $(DIR)-$(VERSION).tar.gz $(DIR); mv $(DIR)-$(VERSION).tar.gz $(DIR))

rpm:
	cp $(DIR)-$(VERSION).tar.gz /usr/src/redhat/SOURCES
	rpm -ba --clean atplotter.spec

install:: $(UNAME)/libAtPlotter.a
	@if [ -d $(INSTALL_LIBDIR) ]; then set +x; \
	else (set -x; $(MKDIRHIER) $(INSTALL_LIBDIR)); fi
	$(INSTALL) -c -m 0644 $(UNAME)/libAtPlotter.a $(INSTALL_LIBDIR)
	$(RANLIB) $(INSTALL_LIBDIR)/libAtPlotter.a

includes:
	@if [ -d ./X11/AtPlotter ]; then set +x; \
	else (set -x; $(MKDIRHIER) ./X11/AtPlotter); fi
	@(set -x; cd ./X11/AtPlotter; for i in $(HEADERS); do \
	$(RM) $$i; \
	$(LN) ../../$$i .; \
	done)

install:: $(HEADERS)
	@if [ -d $(INSTALL_INCDIR)/AtPlotter ]; then set +x; \
	else (set -x; $(MKDIRHIER) $(INSTALL_INCDIR)/AtPlotter); fi
	for i in $(HEADERS); do \
	(set -x; $(INSTALL) -c -m 0444 $$i $(INSTALL_INCDIR)/AtPlotter); \
	done

depend:
	$(DEPEND) -s "# DO NOT DELETE" -- $(DEFINES) $(INCLUDES) -- $(SRCS)

tags:
	$(TAGS) -w *.[ch]
	$(TAGS) -xw *.[ch] > TAGS


# ----------------------------------------------------------------------
# Implicit rules
# ----------------------------------------------------------------------
$(UNAME)/%.o: %.c
	$(CC) $(CFLAGS) -c $< -o $@
	chmod g+w $@

$(UNAME)/atplotter: $(UNAME)/libAtPlotter.a
