#
# Makefile for PEX Toolkit library, for X11 R4
#
# Copyright (C) 1990, Evans & Sutherland
#
# Rich Thomson, May 4th, 1990
#

# LIBRARIES is where cc(1) should look for the PEX/X libraries
LIBRARIES =

# INCLUDES is where cc(1) should look for PEX/X include files
INCLUDES = -I/arch3/prelim/usr/include -I..

# SYS tells RISC/OS the kind of system we are on
SYS = -systype bsd43

# DEBUG compiling options; use ``make DEBUG=-O'' for optimized code
DEBUG = -g

# Flags to cc(1) for compiling .c files
CC_ENVIRON = -Wf,-XNp50000 -Wf,-XNd50000
CFLAGS = $(SYS) $(DEBUG) $(CC_ENVIRON) $(INCLUDES) $(TARGET_ARCH)

# DESTDIR is the place where the library will be installed
DESTDIR = /usr1/ias_soft/rthomson/lib

# Main Program target
TARGETS = libPEXt.a 
all: $(TARGETS)

# Remove all targets and *.o files
clean:
	@echo Removing $(TARGETS) and .o files, if present
	@rm -f $(TARGETS)
	@find . -name '*.o' -exec rm '{}' \;
	@rm dump_names.c

# Remove all GNU backup files *{~,.BAK}
pristine: clean
	@echo Removing all GNU backup files
	@find . \( -name '*~' -o -name '*.BAK' \) -exec rm '{}' \;

# Install the library
install: libPEXt.a
	cp libPEXt.a $(DESTDIR)

# The PEX Toolkit library
PEXt_INCS = Open.h Primitive.h Sphere.h PEXNames.h PEXt.h Structure.h \
	StringDefs.h Quarks.h Converters.h
PEXt_STUBS = dump_start.c dump_middle.c dump_end.c
PEXt_SRCS = Open.c Primitive.c Structure.c Converters.c Workstation.c
PEXt_OBJS = $(PEXt_SRCS:.c=.o) dump_names.o
PEXt_DOCS = man/man3/PtCircle.3 man/man3/PtOpenPEX.3 \
	man/man3/PtSimpleDrawingArea.3 man/man3/PtOpenWorkstation.3 \
	man/man3/PtSphere.3 man/man3/PtInitialize.3.tbl \
	man/man3/PtRotateX.3 man/man3/PtTranslate.3 \
	man/man3/PtNonUniformScale.3 man/man3/PtSanityCheck.3

ALL_FILES = Makefile $(PEXt_INCS) $(PEXt_SRCS) $(PEXt_DOCS) $(PEXt_STUBS)

libPEXt.a: $(PEXt_OBJS)
	ar uvr libPEXt.a $(PEXt_OBJS)

pt.tar: $(ALL_FILES)
	tar cvf pt.tar $(ALL_FILES)

pt.tar.Z: $(ALL_FILES)
	tar cvf - $(ALL_FILES) | compress > pt.tar.Z

ERR_FILE = /usr/include/X11/extensions/phigserr.h
FUN_FILE = /usr/include/X11/extensions/phigscfunc.h
dump_names.o: dump_start.c dump_middle.c dump_end.c $(ERR_FILE) $(FUN_FILE)
	cp dump_start.c dump_names.c
	sed -n 's/^.*#define.*Pfn_\([a-zA-Z0-9_]*\).*$$/case Pfn_\1: function_name = "\1"; break;/p' $(FUN_FILE) >> dump_names.c
	cat dump_middle.c >> dump_names.c
	sed -n 's/^.*#define[ \t]*P\([a-zA-Z0-9_]*\).*$$/case P\1: error_name = "\1"; break;/p' $(ERR_FILE) >> dump_names.c
	cat dump_end.c >> dump_names.c
	$(CC) -c $(CFLAGS) dump_names.c
