###############################################################################
#
# Makefile
#
# Make program to build subordinate programs for the Aldor compiler
#
# Copyright Aldor.org 1990-2007.
#
###############################################################################
#
# Targets: all, clean
#
#    make all	-- make the various tools for the Aldor compiler
#    make junk	-- list files which are not part of the tools
#    make clean -- remove generated files  (e.g. foo.c~)
#
# Parameters:  ALDORROOT
#
#    To override defaults do, e.g.,
#	 make -e ALDORROOT=/spad/local/axiomxl/rs all
#    or
#	 setenv ALDORROOT /spad/local/axiomxl/rs; setenv MAKEFLAGS e; make all
#
###############################################################################

# $(ALDORROOT) is retrieved from the environment
ALDORSUBCMD = $(ALDORROOT)\bin
ALDORINC    = $(ALDORROOT)\include
ALDORSRC    = ..\..\src
ALDORINT    = $(ALDORROOT)\srclib\unitools

SRC = $(MAKEDIR)

CCINCS = -I$(SRC) -I$(SRC)\$(ALDORSRC)
CCFLAGS = -nologo -Zi $(CCINCS) -DSTO_CAN_BLACKLIST -DSTO_DEBUG_DISPLAY

LINKC = file.c fname.c opsys.c store.c memclim.c \
	fluid.c btree.c stdc.c strops.c \
	debug.c xfloat.c buffer.c timer.c \
	util.c list.c format.c cfgfile.c
LINKH = $(LINKC:.c=.h) 

UCLCFILES = unicl2.c 
UCLHFILES = $(UCLCFILES:.c=.h)

UARCFILES = uniar.c uniar2.c
UARHFILES = platform.h

CFILES = $(LINKC) $(UCLCFILES) $(UARCFILES) 
HFILES = $(LINKH) $(UCLHFILES) $(UARHFILES) 

MISCFILES = doccjr Makefile Makefile.win32 

# This is a bit of a hack, but I'm not going to link to the aldor.conf
# file.  We should probably fix this dependency in some way.  It was added
# to facilitate building the aldor compiler with unicl.  (August, 2004)
UNICLCONF = ..\..\src\aldor.conf
CP = copy

#
# Level 0: Portability
#
PORTH0        = axlport.h platform.h cconfig.h editlevels.h
STDCH0        = assert.h0 ctype.h0 errno.h0 float.h0 limits.h0	\
		locale.h0 math.h0 setjmp.h0 signal.h0 stdarg.h0 \
		stddef.h0 stdio.h0 stdlib.h0 string.h0 time.h0
OPSYSH0       = os_cms.c os_dos.c os_os2.c os_unix.c os_vms.c \
		os_macs7.c os_win32.c

OKFILES = $(CFILES) $(HFILES) $(MISCFILES)

# Object Lists
I = $(ALDORINT)
LINKOBJS = $(I)\file.obj  $(I)\fname.obj  $(I)\opsys.obj  $(I)\store.obj  $(I)\memclim.obj \
	   $(I)\fluid.obj $(I)\btree.obj  $(I)\stdc.obj   $(I)\strops.obj \
           $(I)\debug.obj $(I)\xfloat.obj $(I)\buffer.obj $(I)\timer.obj \
	   $(I)\util.obj  $(I)\list.obj   $(I)\format.obj $(I)\cfgfile.obj

UCLOBJS = $(I)\unicl2.obj 

ALLOBJS= $(ALDORINT) $(ALDORINC)\aldor.conf $(ALDORSUBCMD)\unicl.exe \
	$(ALDORSUBCMD)\platform.exe $(ALDORSUBCMD)\uniar.exe

all: $(ALLOBJS)

clean::
	@ if [ -d $(ALDORSUBCMD) ] ; then ( \
		cd $(ALDORSUBCMD) ; \
		del y.tab.h y.tab.c lex.yy.c *.o *~ ) ; \
	fi

clean-links:
	del $(LINKC) $(LINKH)
	@ del platform.h

# unicl: CC-like C compiler 
# The copy command was added in August, 2004 to facilitate building the
# aldor compiler with unicl. 
$(ALDORSUBCMD)\unicl.exe: $(UCLOBJS) $(LINKOBJS)
	$(CC) $(CCFLAGS) -Fe$(ALDORSUBCMD)\unicl.exe $(UCLOBJS) $(LINKOBJS) $(LIBS)
	
$(ALDORINC)\aldor.conf: $(UNICLCONF)
	$(CP) $(UNICLCONF) $(ALDORINC)

# uniar: UCB-like file archiver
#$(ALDORSUBCMD)\uniar: uniar.c platform.h
#	(SRC=`pwd` ; cd $(ALDORSUBCMD) ; \
#	 sh $$SRC\doccjr -I$(ALDORINC) $$SRC\uniar.c -o uniar )

# uniar: UCB\AIX\CMS file archiver
$(ALDORSUBCMD)\uniar.exe: uniar2.c platform.h
	$(CC) -I$(ALDORINC) $(CCFLAGS) uniar2.c -Fe$(ALDORSUBCMD)\uniar.exe

# platform: display CONFIG and CONFIGSYS
$(ALDORSUBCMD)\platform.exe: platform.c platform.h
	$(CC) $(CCFLAGS) -I$(ALDORINC) platform.c -Fe$(ALDORSUBCMD)\platform.exe

$(ALDORINT):
	mkdir $(ALDORINT)

$(ALDORINT)\file.obj:  $(SRC)\$(ALDORSRC)\file.c
	cd $(ALDORINT)
	$(CC) -c  $(CCFLAGS) $(SRC)\$(ALDORSRC)\file.c
	cd $(SRC)
$(ALDORINT)\fluid.obj:  $(SRC)\$(ALDORSRC)\fluid.c
	cd $(ALDORINT)
	$(CC) -c  $(CCFLAGS) $(SRC)\$(ALDORSRC)\fluid.c
	cd $(SRC)
$(ALDORINT)\fname.obj:  $(SRC)\$(ALDORSRC)\fname.c
	cd $(ALDORINT)
	$(CC) -c  $(CCFLAGS) $(SRC)\$(ALDORSRC)\fname.c
	cd $(SRC)
$(ALDORINT)\opsys.obj:  $(SRC)\$(ALDORSRC)\opsys.c
	cd $(ALDORINT)
	$(CC) -c  $(CCFLAGS) $(SRC)\$(ALDORSRC)\opsys.c
	cd $(SRC)
$(ALDORINT)\strops.obj:  $(SRC)\$(ALDORSRC)\strops.c
	cd $(ALDORINT)
	$(CC) -c  $(CCFLAGS) $(SRC)\$(ALDORSRC)\strops.c
	cd $(SRC)
$(ALDORINT)\store.obj:  $(SRC)\$(ALDORSRC)\store.c
	cd $(ALDORINT)
	$(CC) -c  $(CCFLAGS) $(SRC)\$(ALDORSRC)\store.c
	cd $(SRC)
$(ALDORINT)\memclim.obj:  $(SRC)\$(ALDORSRC)\memclim.c
	cd $(ALDORINT)
	$(CC) -c  $(CCFLAGS) $(SRC)\$(ALDORSRC)\memclim.c
	cd $(SRC)
$(ALDORINT)\btree.obj:  $(SRC)\$(ALDORSRC)\btree.c
	cd $(ALDORINT)
	$(CC) -c  $(CCFLAGS) $(SRC)\$(ALDORSRC)\btree.c
	cd $(SRC)
$(ALDORINT)\stdc.obj:  $(SRC)\$(ALDORSRC)\stdc.c
	cd $(ALDORINT)
	$(CC) -c  $(CCFLAGS) $(SRC)\$(ALDORSRC)\stdc.c
	cd $(SRC)
$(ALDORINT)\debug.obj:  $(SRC)\$(ALDORSRC)\debug.c
	cd $(ALDORINT)
	$(CC) -c  $(CCFLAGS) $(SRC)\$(ALDORSRC)\debug.c
	cd $(SRC)
$(ALDORINT)\xfloat.obj:  $(SRC)\$(ALDORSRC)\xfloat.c
	cd $(ALDORINT)
	$(CC) -c  $(CCFLAGS) $(SRC)\$(ALDORSRC)\xfloat.c
	cd $(SRC)
$(ALDORINT)\buffer.obj:  $(SRC)\$(ALDORSRC)\buffer.c
	cd $(ALDORINT)
	$(CC) -c  $(CCFLAGS) $(SRC)\$(ALDORSRC)\buffer.c
	cd $(SRC)
$(ALDORINT)\timer.obj:  $(SRC)\$(ALDORSRC)\timer.c
	cd $(ALDORINT)
	$(CC) -c  $(CCFLAGS) $(SRC)\$(ALDORSRC)\timer.c
	cd $(SRC)
$(ALDORINT)\util.obj:  $(SRC)\$(ALDORSRC)\util.c
	cd $(ALDORINT)
	$(CC) -c  $(CCFLAGS) $(SRC)\$(ALDORSRC)\util.c
	cd $(SRC)
$(ALDORINT)\list.obj:  $(SRC)\$(ALDORSRC)\list.c
	cd $(ALDORINT)
	$(CC) -c  $(CCFLAGS) $(SRC)\$(ALDORSRC)\list.c
	cd $(SRC)
$(ALDORINT)\format.obj:  $(SRC)\$(ALDORSRC)\format.c
	cd $(ALDORINT)
	$(CC) -c  $(CCFLAGS) $(SRC)\$(ALDORSRC)\format.c
	cd $(SRC)
$(ALDORINT)\cfgfile.obj:  $(SRC)\$(ALDORSRC)\cfgfile.c
	cd $(ALDORINT)
	$(CC) -c  $(CCFLAGS) $(SRC)\$(ALDORSRC)\cfgfile.c
	cd $(SRC)

$(ALDORINT)\unicl2.obj:  unicl2.c
	cd $(ALDORINT)
	$(CC) -c  $(CCFLAGS) $(SRC)\unicl2.c
	cd $(SRC)


