# Makefile for Portable CLU

# Before using this Makefile:
#   (a) edit the definition of PLATFORM
#   (b) setenv CLUHOME <name-of-this-directory>
#   (c) setenv TMPDIR /usr/tmp
#       (or some other directory with a lot of space if /tmp doesn't have much)
#   (d) if using "make install", edit the definition of INSTALL_DIR and
#			create INSTALL_DIR
#   (e) if you will be building large programs on the mips or alpha platforms
#		type "make configure_G0" to get -G 0 libraries
#		for debugging
#   (f) if you want smaller executables (at the cost of some speed),
#		 add #define athena to CLUHOME/include/pclu_sys.h

PLATFORM = win32

PLATFORMS = mips sparc sony-news rs6k alpha hp linux linux-5 win32 bsd

EXEDIR = exe

MAKEDIRS = code/sysasm code/cmp code/cmpasm code/gc code/libasm code/libclu \
           code/sysclu debug example example-debug example-prof cludent util \
	   driver \
	   code/compat/src

G0_DIRS = code/sysasm code/libasm code/libclu code/sysclu debug

CFGDIRS = code/cmp

INSTALL_DIR 	= /usr/local
INSTALL_FILES	= ./include ./lib/*.lib ./lib/*.spc ./lib/short.help \
		  ./code/libpclu.a ./code/libpclu_debug.a \
		  ./code/libpclu_opt.a \
		  ./cmp ./code/cmp/basic.types \
		  ./code/cmp/ccdbg.cmd* ./code/cmp/ccopt.cmd* \
		  ./clu.order ./doc ./exe \
                  ./example ./example-debug ./driver ./elisp \
                  ./code/gc/gc.h ./code/include

INSTALL_TAR_FILE = ../pclu-install.tar.Z
INSTALL_TARGZ_FILE = ../pclu-install.tar.gz

LN = ln -s
MV = mv -f
RM = rm -f
CP = cp

all: configure gc compat libpclu compiler clulibs debugger cludent PCLU

## easier for testing (MSch)

makelinks:
	(cd code; ${RM} Makefile; ${LN} Makefile.${PLATFORM} Makefile);\
	for i in ${MAKEDIRS};				  		     \
	   do (cd $$i; ${RM} Makefile; ${LN} Makefile.${PLATFORM} Makefile); \
	   done; \
	
configure:
	for i in ${MAKEDIRS};				  		     \
	   do (cd $$i; ${RM} Makefile; ${LN} Makefile.${PLATFORM} Makefile); \
	   done; \
	for i in ${CFGDIRS};				  		     \
	   do (cd $$i; make config); \
	   done

configure_G0:
	for i in ${G0_DIRS}; \
	   do (cd $$i; ${RM} Makefile.${PLATFORM}.G0; \
           	sed -e '/DEBUG/s/-G 4/-G 0/' Makefile.${PLATFORM} > Makefile.${PLATFORM}.G0; \
		${MV} Makefile.${PLATFORM}.G0 Makefile.${PLATFORM}) \
	   done; \
      	cd cmp ; sed -e 's/-G 4/-G 0/' ccdbg.cmd.${PLATFORM} > ccdbg.cmd.${PLATFORM}.G0; \
		${MV} ccdbg.cmd.${PLATFORM}.G0 ccdbg.cmd.${PLATFORM}

configure_G4:
	for i in ${G0_DIRS}; \
	   do (cd $$i; ${RM} Makefile.${PLATFORM}.G4; \
           	sed -e '/DEBUG/s/-G 0/-G 4/' Makefile.${PLATFORM} > Makefile.${PLATFORM}.G4; \
		${MV} Makefile.${PLATFORM}.G4 Makefile.${PLATFORM}) \
	   done; \
      	cd cmp ; sed -e 's/-G 0/-G 4/' ccdbg.cmd.${PLATFORM} > ccdbg.cmd.${PLATFORM}.G4; \
		${MV} ccdbg.cmd.${PLATFORM}.G4 ccdbg.cmd.${PLATFORM}

compat:
	cd code/compat/src; make

gc:
	cd code/gc; make test

libpclu:
	cd code; make optlib

compiler:
	cd code/cmp; make
	if [ -e code/cmp/pclu.exe ]; then mv code/cmp/pclu.exe $(EXEDIR)/pclu.exe; \
	else mv code/cmp/pclu $(EXEDIR)/pclu; \
	fi

clulibs:
	cd lib; make

debugger:
	cd code; make debuglib

PCLU:
	cd driver; make PCLU
	if [ -e driver/pclu.exe ]; then mv driver/pclu.exe $(EXEDIR)/pclu-driver.exe; \
	else mv driver/PCLU $(EXEDIR)/PCLU; \
	fi

install:
	tar cf -  ${INSTALL_FILES} | (cd ${INSTALL_DIR}; tar xf -)

install-tar-z:
	tar cfv - ${INSTALL_FILES} | compress > ${INSTALL_TAR_FILE}

install-tar-gz:
	tar cfv - ${INSTALL_FILES} | gzip -c > ${INSTALL_TARGZ_FILE}

example: fictitious_file
	cd example; make

example-debug: fictitious_file
	cd example-debug; make

example-prof: fictitious_file
	cd example-prof; make

cludent: fictitious_file
	cd cludent; make
	if [ -e cludent/cludent.exe ]; then mv cludent/cludent.exe $(EXEDIR)/cludent.exe; \
	else mv cludent/cludent $(EXEDIR)/cludent; \
	fi

liblst: fictitious_file
	cd util; make
	if [ -e util/liblst.exe ]; then mv util/liblst.exe $(EXEDIR)/liblst.exe; \
	else mv util/liblst $(EXEDIR)/liblst; \
	fi


newcompiler:
	cd cmpclu; make
	make compiler

cdebugger:
	cd code; make cdebuglib

fictitious_file:

clean:
	for i in ${MAKEDIRS} doc; do (cd $$i; make clean); done

veryclean: clean
	cd lib; $(RM) *.lib
	cd code; $(RM) libpclu_g.a libpclu_debug.a libpclu_opt.a
	cd code/gc; $(RM) gc.a
	cd code/cmp; $(RM) pclu npclu basic.junk
	cd cludent; $(RM) cludent
	cd debug; make veryclean
	cd util; $(RM) liblst gcdprt
	cd exe; $(RM) pclu cludent liblst PCLU
