## Define the appropriate configuration variables.

PACKAGE = /fsys2/u2/usystem/software/u++-5.3.0

## Include the architecture dependent definitions.

include $(PACKAGE)/CONFIG

## Define the path names of important directories.

SRCDIR = $(PACKAGE)/src/translator

## Define some of the tools.

include ../MakeTools

## Do not use the u++ compiler to build the u++ compiler.

CC := $(CCBUILD)

CCFLAGS := -I. -D__$(VENDOR)__ -D__$(OS)__ -D__$(CPU)__ -DPACKAGE=\"$(PACKAGE)\" -DVERSION=\"$(VERSION)\" -DTVENDOR=\"$(TVENDOR)\" -DTCPU=\"$(TCPU)\" -DTOS=\"$(TOS)\" -DINSTALLBINDIR=\"$(INSTALLBINDIR)\" -DINSTALLLIBDIR=\"$(INSTALLLIBDIR)\" -DINSTALLINCDIR=\"$(INSTALLINCDIR)\" -DTMPDIR=\"$(TMPDIR)\" -DMULTI=\"$(MULTI)\" -DCCAPP=\"$(CCAPP)\" -D__U_MAXENTRYBITS__=$(MAXENTRYBITS)

ifeq ($(TLS),TRUE)
	CCFLAGS += -DTLS
endif

ifeq ($(ONETIMER),TRUE)
	CCFLAGS += -DONETIMER
endif

#PURIFY = purify --cache-dir=$(HOME)/tmp

ifeq ($(findstring icpc,$(CCAPP)),)
	GCCVERSION = $(shell $(CCAPP) --version)
	ifeq ($(findstring (GCC) 3.2,$(GCCVERSION)),(GCC) 3.2)
		CPPNAME = cpp0
	else
		CPPNAME = cc1plus
	endif
else
	CPPNAME = mcpcom
endif

HOSTNAME = $(shell hostname)
ifeq ($(HOSTNAME),plg2.math)
	CCFLAGS += -g -O2 -Wall #
else
	CCFLAGS += -O2 # -DNDEBUG
endif

ifeq ($(TOS),irix)
	PTHREAD = -lpthread
else
	PTHREAD =
endif

## Define the C++ source files.

#SRC = $(SRCDIR)/(\
#).cc

#OBJ = $(OBJDIR)/($(SRC:b)).o

## Define the source and object files for the driver.

DSRC = $(addprefix $(SRCDIR)/, $(addsuffix .cc, \
u++ \
) )

DOBJ = $(addprefix $(OBJDIR)/, $(addsuffix .o, $(basename $(notdir $(DSRC) ) ) ) )

## Define the source and object files for the replacement preprocessor.

PSRC = $(addprefix $(SRCDIR)/, $(addsuffix .cc, \
$(CPPNAME) \
) )

POBJ = $(addprefix $(OBJDIR)/, $(addsuffix .o, $(basename $(notdir $(PSRC) ) ) ) )

## Define the source and object files for the translator.

TSRC = $(addprefix $(SRCDIR)/, $(addsuffix .cc, \
attribute \
gen \
hash \
input \
key \
main \
output \
parse \
scan \
structor \
symbol \
table \
token \
) )

TOBJ = $(addprefix $(OBJDIR)/, $(addsuffix .o, $(basename $(notdir $(TSRC) ) ) ) )

## Use the host information

TVENDOR := $(VENDOR)
TOS := $(OS)
TCPU := $(CPU)

## Define the things that can be defined based upon previous definitions.

include ../MakeDefinitions

## Define which dependencies should be built.

DEPENDS = $(OBJDIR)/depend.mk

## Define which executables should be built.

BINS = u++
LIBS = $(CPPNAME) u++-cpp

## Define the specific recipes.

all : $(addprefix $(BINDIR)/, $(BINS)) $(addprefix $(LIBDIR)/, $(LIBS))

install : all $(addprefix $(INSTALLLIBDIR)/, $(LIBS)) $(addprefix $(INSTALLBINDIR)/, $(BINS))

test : 
	set -x ; \
	for filename in Operators AcceptStmt BreakStmt Resumption Exception Termination Event MutexTaskParms Constructor \
			Lookup InheritanceException Template Friend Inheritance STL Types ; do \
		$(INSTALLBINDIR)/u++ $(CCFLAGS) -Wno-unused-label -c test$${filename}.cc ; \
	done ; \
	"rm" -f ./a.out test*.o ;

## Everything depends on the make file.

$(OBJ) $(DOBJ) $(POBJ) $(TOBJ) : Makefile

## Define default dependencies and recipes for making object files.

$(OBJDIR)/%.o : $(SRCDIR)/%.cc
	$(PURIFY) $(CC) $(CCFLAGS) -MD $< -c -o $@

## Dependencies and recipes for the driver.

$(BINDIR)/u++ : $(OBJ) $(DOBJ)
	$(CC) $(CCFLAGS) $(OBJ) $(DOBJ) -o $@ $(PTHREAD)

## Dependencies and recipes for the preprocessor.

$(LIBDIR)/$(CPPNAME) : $(OBJ) $(POBJ)
	$(CC) $(CCFLAGS) $(OBJ) $(POBJ) -o $@ $(PTHREAD)

## Dependencies: and recipes for the translator.

$(LIBDIR)/u++-cpp : $(OBJ) $(TOBJ)
	$(PURIFY) $(CC) $(CCFLAGS) $(OBJ) $(TOBJ) -o $@ $(PTHREAD)

#ifdef INSTALLBINDIR
$(INSTALLBINDIR)/% : $(BINDIR)/%
	$(INSTALL) $< $@
	$(CHMODEXEC) $@
#endif

#ifdef INSTALLLIBDIR
$(INSTALLLIBDIR)/% : $(LIBDIR)/%
	$(INSTALL) $< $@
	$(CHMODEXEC) $@
#endif

## Constructed dependencies for object files.

DDEPEND = $(addprefix $(OBJDIR)/, $(addsuffix .d, $(basename $(notdir $(DSRC)))))
PDEPEND = $(addprefix $(OBJDIR)/, $(addsuffix .d, $(basename $(notdir $(PSRC)))))
TDEPEND = $(addprefix $(OBJDIR)/, $(addsuffix .d, $(basename $(notdir $(TSRC)))))
-include $(DEPENDS) $(DDEPEND) $(PDEPEND) $(TDEPEND)

## Create directories (TEMPORARY: fixed in gmake 3.80)

_xxx1 := $(shell mkdir -p $(LIBDIR) $(OBJDIR) $(BINDIR))

ifeq ($(MAKECMDGOALS),install)
_xxx2 := $(shell mkdir -p $(INSTALLLIBDIR) $(INSTALLBINDIR))
endif

## Local Variables: ##
## compile-command: "gmake install" ##
## End: ##
