# 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 = linux-5

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

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
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 = /bin/ln -s
MV = /bin/mv -f
RM = /bin/rm -f
CP = /bin/cp

all: configure gc libpclu compiler clulibs debugger cludent PCLU

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}

#gc:
#	cd code/gc; ./configure; make
#

# REALLY do not want to run configure on leopard
gc:
	cd code/gc; make

libpclu:
	cd code; make optlib

compiler:
	cd code/cmp; make
	mv code/cmp/pclu $(EXEDIR)/pclu

clulibs:
	cd lib; make

debugger:
	cd code; make debuglib

PCLU:
	cd driver; make PCLU.driver
	mv driver/PCLU.driver $(EXEDIR)/PCLU.driver

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

cludent: fictitious_file
	cd cludent; make
	mv cludent/cludent $(EXEDIR)/cludent

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; /bin/rm -f *.lib
	cd code; /bin/rm -f libpclu_g.a libpclu_debug.a libpclu_opt.a
	cd code/gc; /bin/rm -f gc.a
	cd code/cmp; /bin/rm -f pclu npclu basic.junk
	cd cludent; /bin/rm -f cludent
	cd debug; make veryclean
	cd util; /bin/rm -f liblst gcdprt
	cd exe; /bin/rm -f pclu cludent liblst PCLU
