###############################################################################
#
# Makefile
#
# Make program to build subordinate programs for the Aldor compiler
#
# Copyright (c) 1990-2007 Aldor Software Organization Ltd (Aldor.org).
#
###############################################################################
#
# Targets: all, junk, 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
#
###############################################################################
#
#  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

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

LN	= ln
RM      = rm -f
CC      = docc

CCINCS = -I$$SRC -I$$SRC/$(ALDORSRC)
CCFLAGS = $(CCINCS) -DSTO_CAN_BLACKLIST -DSTO_DEBUG_DISPLAY -g

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 = cp

#
# 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.o  $(I)/fname.o  $(I)/opsys.o  $(I)/store.o  $(I)/memclim.o \
	   $(I)/fluid.o $(I)/btree.o  $(I)/stdc.o   $(I)/strops.o \
           $(I)/debug.o $(I)/xfloat.o $(I)/buffer.o $(I)/timer.o \
	   $(I)/util.o  $(I)/list.o   $(I)/format.o $(I)/cfgfile.o

UCLOBJS = $(I)/unicl2.o 

ALLOBJS= $(ALDORINT) $(ALDORSUBCMD)/unicl $(ALDORSUBCMD)/platform \
	$(ALDORSUBCMD)/uniar

all: .cvsignore $(ALLOBJS)
	@ echon

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

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

.cvsignore: Makefile
	echo $(LINKC) $(LINKH) .cvsignore > .cvsignore

clean-links:
	rm $(LINKC) $(LINKH)
	@ rm -f 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: $(UCLOBJS) $(LINKOBJS)
	docc -o $(ALDORSUBCMD)/unicl $(UCLOBJS) $(LINKOBJS) $(LIBS)
	$(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: uniar2.c platform.h
	(SRC=`pwd` ; cd $(ALDORSUBCMD) ; rm -f uniar ; ln -s `which ar` uniar)
# sh $$SRC/doccjr -I$(ALDORINC) $(CCFLAGS) $$SRC/uniar2.c -o uniar ; rm -f uniar ; ln -s `which ar` uniar )

# platform: display CONFIG and CONFIGSYS
$(ALDORSUBCMD)/platform: platform.c platform.h
	(SRC=`pwd` ; cd $(ALDORSUBCMD) ; \
	 sh $$SRC/doccjr -I$(ALDORINC) $(CCFLAGS) $$SRC/platform.c -o platform )

$(ALDORINT):
	mkdir $(ALDORINT)

# Everything depends on everything else
$(UCLOBJS): $(OTHERINCS) $(UCLHFILES)
$(LINKOBJS): $(LINKH)

platform.h: $(ALDORSRC)/platform.h ; ( $(RM) $@; ln $? $@ )

editlevels.h: $(ALDORSRC)/editlevels.h ; ( $(RM) $@; ln $? $@ )

file.h: $(ALDORSRC)/file.h ; ( $(RM) $@; ln $? $@ )
fname.h: $(ALDORSRC)/fname.h ; ( $(RM) $@; ln $? $@ )
opsys.h: $(ALDORSRC)/opsys.h ; ( $(RM) $@; ln $? $@ )
store.h: $(ALDORSRC)/store.h ; ( $(RM) $@; ln $? $@ )
memclim.h: $(ALDORSRC)/memclim.h ; ( $(RM) $@; ln $? $@ )
fluid.h: $(ALDORSRC)/fluid.h ; ( $(RM) $@; ln $? $@ )
btree.h: $(ALDORSRC)/btree.h ; ( $(RM) $@; ln $? $@ )
stdc.h: $(ALDORSRC)/stdc.h ; ( $(RM) $@; ln $? $@ )
strops.h: $(ALDORSRC)/strops.h ; ( $(RM) $@; ln $? $@ )
debug.h: $(ALDORSRC)/debug.h ; ( $(RM) $@; ln $? $@ )
xfloat.h: $(ALDORSRC)/btree.h ; ( $(RM) $@; ln $? $@ )
buffer.h: $(ALDORSRC)/buffer.h ; ( $(RM) $@; ln $? $@ )
timer.h: $(ALDORSRC)/timer.h ; ( $(RM) $@; ln $? $@ )
util.h: $(ALDORSRC)/util.h ; ( $(RM) $@; ln $? $@ )
list.h: $(ALDORSRC)/list.h ; ( $(RM) $@; ln $? $@ )
format.h: $(ALDORSRC)/format.h ; ( $(RM) $@; ln $? $@ )

file.c: $(ALDORSRC)/file.c ; ( $(RM) $@; ln $? $@ )
fname.c: $(ALDORSRC)/fname.c ; ( $(RM) $@; ln $? $@ )
opsys.c: $(ALDORSRC)/opsys.c ; ( $(RM) $@; ln $? $@ )
store.c: $(ALDORSRC)/store.c ; ( $(RM) $@; ln $? $@ )
memclim.c: $(ALDORSRC)/memclim.c ; ( $(RM) $@; ln $? $@ )
fluid.c: $(ALDORSRC)/fluid.c ; ( $(RM) $@; ln $? $@ )
btree.c: $(ALDORSRC)/btree.c ; ( $(RM) $@; ln $? $@ )
strops.c: $(ALDORSRC)/strops.c ; ( $(RM) $@; ln $? $@ )
stdc.c: $(ALDORSRC)/stdc.c ; ( $(RM) $@; ln $? $@ )
debug.c: $(ALDORSRC)/debug.c ; ( $(RM) $@; ln $? $@ )
xfloat.c: $(ALDORSRC)/xfloat.c ; ( $(RM) $@; ln $? $@ )
buffer.c: $(ALDORSRC)/buffer.c ; ( $(RM) $@; ln $? $@ )
timer.c: $(ALDORSRC)/timer.c ; ( $(RM) $@; ln $? $@ )
util.c: $(ALDORSRC)/util.c ; ( $(RM) $@; ln $? $@ )
list.c: $(ALDORSRC)/list.c ; ( $(RM) $@; ln $? $@ )
format.c: $(ALDORSRC)/format.c ; ( $(RM) $@; ln $? $@ )
cfgfile.c: $(ALDORSRC)/cfgfile.c ; ( $(RM) $@; ln $? $@ )
cfgfile.h: $(ALDORSRC)/cfgfile.h ; ( $(RM) $@; ln $? $@ )

$(ALDORINT)/file.o:  file.c 
	(SRC=`pwd`; cd $(ALDORINT); $(CC) -c  $(CCFLAGS) $$SRC/file.c)
$(ALDORINT)/fluid.o:  fluid.c 
	(SRC=`pwd`; cd $(ALDORINT); $(CC) -c  $(CCFLAGS) $$SRC/fluid.c)
$(ALDORINT)/fname.o:  fname.c 
	(SRC=`pwd`; cd $(ALDORINT); $(CC) -c  $(CCFLAGS) $$SRC/fname.c)
$(ALDORINT)/opsys.o:  opsys.c 
	(SRC=`pwd`; cd $(ALDORINT); $(CC) -c  $(CCFLAGS) $$SRC/opsys.c)
$(ALDORINT)/strops.o:  strops.c 
	(SRC=`pwd`; cd $(ALDORINT); $(CC) -c  $(CCFLAGS) $$SRC/strops.c)
$(ALDORINT)/store.o:  store.c 
	(SRC=`pwd`; cd $(ALDORINT); $(CC) -c  $(CCFLAGS) $$SRC/store.c)
$(ALDORINT)/memclim.o:  memclim.c 
	(SRC=`pwd`; cd $(ALDORINT); $(CC) -c  $(CCFLAGS) $$SRC/memclim.c)
$(ALDORINT)/btree.o:  btree.c 
	(SRC=`pwd`; cd $(ALDORINT); $(CC) -c  $(CCFLAGS) $$SRC/btree.c)
$(ALDORINT)/stdc.o:  stdc.c 
	(SRC=`pwd`; cd $(ALDORINT); $(CC) -c  $(CCFLAGS) $$SRC/stdc.c)
$(ALDORINT)/debug.o:  debug.c 
	(SRC=`pwd`; cd $(ALDORINT); $(CC) -c  $(CCFLAGS) $$SRC/debug.c)
$(ALDORINT)/xfloat.o:  xfloat.c 
	(SRC=`pwd`; cd $(ALDORINT); $(CC) -c  $(CCFLAGS) $$SRC/xfloat.c)
$(ALDORINT)/buffer.o:  buffer.c 
	(SRC=`pwd`; cd $(ALDORINT); $(CC) -c  $(CCFLAGS) $$SRC/buffer.c)
$(ALDORINT)/timer.o:  timer.c 
	(SRC=`pwd`; cd $(ALDORINT); $(CC) -c  $(CCFLAGS) $$SRC/timer.c)
$(ALDORINT)/util.o:  util.c 
	(SRC=`pwd`; cd $(ALDORINT); $(CC) -c  $(CCFLAGS) $$SRC/util.c)
$(ALDORINT)/list.o:  list.c 
	(SRC=`pwd`; cd $(ALDORINT); $(CC) -c  $(CCFLAGS) $$SRC/list.c)
$(ALDORINT)/format.o:  format.c 
	(SRC=`pwd`; cd $(ALDORINT); $(CC) -c  $(CCFLAGS) $$SRC/format.c)
$(ALDORINT)/cfgfile.o:  cfgfile.c 
	(SRC=`pwd`; cd $(ALDORINT); $(CC) -c  $(CCFLAGS) $$SRC/cfgfile.c)

$(ALDORINT)/unicl2.o:  unicl2.c 
	(SRC=`pwd`; cd $(ALDORINT); $(CC) -c  $(CCFLAGS) $$SRC/unicl2.c)


