###############################################################################
#
# Makefile
#
# Make program to build portable tools for the Aldor compiler
#
# Copyright (c) 1990-2007 Aldor Software Organization Ltd (Aldor.org).
#
###############################################################################
#
# These tools can built on various platforms and
# can be used to help build and test a compiler.
#
###############################################################################
#
#  2006/Dec/22
#
#  On Solaris, the value of PWD does not change when make is invoked
#  recursively.  Consequently, it is necessary to explicitly set it
#  at the start of the makefile.
#
PWD = $(shell pwd)

SHELL	= /bin/sh
LN	= ln
RM	= rm -f
CFLAGS	= -O
CC      = docc

# $(ALDORROOT) is retrieved from the environment
SRC   = ../../src
BIN   = $(ALDORROOT)/bin
TOOLS = $(ALDORROOT)/toolbin

COMMONFILES	= platform.h cconfig.h signal.h0 stdarg.h0 \
		  stddef.h0 stdio.h0 string.h0

OSFILES		= tx_opsys.c tx_unix.c tx_win32.c

OKFILES		= Makefile testaldor.c testaldor.h stat.h0\
		  $(COMMONFILES) $(OSFILES)

all:	$(COMMONFILES)		\
	$(TOOLS)/testaldor
	@ echon

clean:
	@ $(RM) *~

junk:
	@ ls -d $(OKFILES) * | sort | grep -v CVS | uniq -u

links:	$(COMMONFILES)

##############################################################################
#
# :: Portable tools
#
##############################################################################

#
# Rules to get the common source files (as links or copies)
#
platform.h:	$(SRC)/platform.h ;	( $(RM) $@ ; $(LN) $? $@ )
cconfig.h:	$(SRC)/cconfig.h ;	( $(RM) $@ ; $(LN) $? $@ )
signal.h0:	$(SRC)/signal.h0 ;	( $(RM) $@ ; $(LN) $? $@ )
stdarg.h0:	$(SRC)/stdarg.h0 ;	( $(RM) $@ ; $(LN) $? $@ )
stddef.h0:	$(SRC)/stddef.h0 ;	( $(RM) $@ ; $(LN) $? $@ )
stdio.h0:	$(SRC)/stdio.h0 ;	( $(RM) $@ ; $(LN) $? $@ )
string.h0:	$(SRC)/string.h0 ;	( $(RM) $@ ; $(LN) $? $@ )

# testaldor: Run axiomxl compiler test suite.
$(TOOLS)/testaldor: testaldor.c platform.h testaldor.h $(OSFILES)
	@ (SRC=`pwd` ; cd $(TOOLS) ; \
		echo "$(CC) $(CFLAGS) $$SRC/testaldor.c -o testaldor" ; \
		$(CC) $(CFLAGS) $$SRC/testaldor.c -o testaldor \
	)

