# Copyright 1989-93 GROUPE BULL -- See license conditions in file COPYRIGHT
#
#			      #####################
#                             ## KLONE  makefile ##
#			      #####################

OBJS =  kly.tab.o kllex.yy.o klone.o klparseutils.o \
	kl_atom.o kl_coll.o kl_func.o kl_link.o kl_list.o kl_hash.o \
	kl_number.o kl_string.o kl_stream.o kl_struct.o klnet.o \
	klmalloc.o klmachine.o klreference.o klgeneric.o klerror.o \
	klregexp.o klos.o klmalloc2.o kldload.o klmath.o klko.o \
	klclean.o klend.o klerrorh.o klstp.o kltoplevel.o kldebug.o \
        $(EXTRA_OBJS)

SRCS = 	klone.c klparseutils.c \
	kl_atom.c kl_coll.c kl_func.c kl_link.c kl_list.c kl_hash.c \
	kl_number.c kl_string.c kl_stream.c kl_struct.c klnet.c \
	klmalloc.c klmachine.c klreference.c klgeneric.c klerror.c \
	klregexp.c klos.c klmalloc2.c kldload.c klmath.c klko.c \
	klclean.c klend.c klerrorh.c klstp.c kltoplevel.c kldebug.c \
	$(EXTRA_SRCS)

OBJ = main.o
SRC = main.c

LIBKLONE = libklone.a

INCLUDE	= -I.
LIBDIR	= 
KLONECFLAGS = $(DEFINES) $(INCLUDE) -DKLPATH=$(KLONEPATH) -DLOCATORS -DKLONE -DMACHINE_TYPE=\"$(MACHINE_TYPE)\"
CFLAGS=
REV=
CC=./klone_cc

all	: makefile klone

ses: ses_ndbm ses_calc ses_draw                 #make all ses sample modules

sun4 sgi aix alpha dec mips solaris sony linux win32 : # Config for a SUNOS 4.x sparc
	cp Configs/$@ Config.$@;echo "$@">.dir;rm -f makefile;make -f Makefile.dist

$(LIBKLONE) : $(OBJS) makefile
	rm -f $@
	ar cq $@ $(OBJS)
	-ranlib $@

klone 	: $(CC) $(LIBKLONE) $(OBJ)
	rm -f klone
	$(CC) $(LFLAGS) $(LIBDIR) $(OBJ) -o klone $(LIBKLONE) $(LIBS) -lm
	@-if test -n "$(POSTPROCESSING)" -o "$(POSTPROCESSING)" = ":"; \
            then $(POSTPROCESSING) klone;fi

klone-exp 	: $(CC) $(LIBKLONE) $(OBJ) exp.o
	rm -f klone
	$(CC) $(CFLAGS) -c -o main-exp.o -DKLONE_ADDINIT='expmain()' main.c
	$(CC) $(CFLAGS) -c -o kltoplevel.o -DEXP kltoplevel.c
	rm -f libkloneexp.a;ar cq libklonexp.a $(OBJS)
	-ranlib libklonexp.a
	$(CC) $(LFLAGS) $(LIBDIR) main-exp.o -I/usr/X11R6/include exp.c\
	 -o klone-exp libklonexp.a -L/usr/X11R6/lib -lX11 $(LIBS) -lm
	@-if test -n "$(POSTPROCESSING)" -o "$(POSTPROCESSING)" = ":"; \
            then $(POSTPROCESSING) klone;fi
	rm -f kltoplevel.o

# globally optimized version
kloneo	: $(CC) $(SRCS)
	$(CC) $(GLOBOPT) $(LFLAGS) $(LIBDIR) kllex.yy.c kly.tab.c $(SRCS) \
	      -o kloneo $(LIBS) -lm

# link in one pass, dont use the library
nolib : $(CC)  $(OBJ) $(OBJS)
	rm -f klone
	@-if test -n "$(POSTPROCESSING)" -o "$(POSTPROCESSING)" = ":"; \
            then $(POSTPROCESSING) klone;fi

# PURIFY-ed version
$(CC)_pf : makefile
	echo '#!/bin/sh' > $(CC)_pf
	/bin/echo -n "purify " >> $(CC)_pf
	echo purify $(C_COMPILER) '$(FLAGS) $(GWMCFLAGS)' '$$*' > $(CC)_pf
	- chmod a+x $(CC)_pf

klonep	: $(CC) $(LIBKLONE) $(OBJ) $(CC)_pf
	rm -f klonep
	$(CC)_pf $(LFLAGS) $(LIBDIR) $(OBJ) -o klonep $(LIBKLONE) $(LIBS) -lm

$(CC)_qf : makefile
	echo '#!/bin/sh' > $(CC)_qf
	/bin/echo -n "quantify " >> $(CC)_qf
	echo quantify $(C_COMPILER) '$(FLAGS) $(GWMCFLAGS)' '$$*' > $(CC)_qf
	- chmod a+x $(CC)_qf

kloneqf  : $(CC) $(LIBKLONE) $(OBJ) $(CC)_qf
	rm -f kloneqf
	$(CC)_qf $(LFLAGS) $(LIBDIR) $(OBJ) -o kloneqf $(LIBKLONE) $(LIBS) -lm

$(CC)	: makefile
	echo '#!/bin/sh' > $(CC)
	echo $(C_COMPILER) '$(FLAGS) $(KLONECFLAGS)' '$$*' >> $(CC)
	-chmod a+x $(CC)
	-if test -z "$(C_COMPILER)";then rm -f $(CC);make -f makefile $(CC);fi

#profiled version
profiler : makefile.profiler
	rm -f klone_p
	-if test ! -d NONPROFILED;then mkdir NONPROFILED;fi
	-mv *.o klone NONPROFILED
	-if test -d PROFILED;then mv PROFILED/* .;rm -rf PROFILED; fi	 
	-make -f makefile.profiler klone
	-mv klone klone_p
	-mkdir PROFILED;mv *.o $(CC) PROFILED
	-mv NONPROFILED/* .;rmdir NONPROFILED

makefile.profiler: Makefile.dist .dir $(LOCAL_MAKE) Makefile.profiler
	sed -e 's/^DEFINES/DEFINES2/' \
             -e 's/EXTRA_OBJS/EXTRA_OBJS2/' <Makefile.first>.mpf
	sed -e 's/^DEFINES/DEFINES2/' \
             -e 's/EXTRA_OBJS/EXTRA_OBJS2/' <Config.`cat .dir`>.ccd
	echo 'LOCAL_MAKE=Config.'`cat .dir`|\
             cat .mpf .ccd - Makefile.profiler Makefile.dist > makefile.profiler
	@echo "makefile.profiler created, re-running make on it"
	-if test ! -d NONPROFILED;then mkdir NONPROFILED;fi
	-mv $(CC) NONPROFILED
	$(MAKE) -f makefile.profiler $(MFLAGS)


klone2ic: klone2ic.c
	$(CC) klone2ic.c -o klone2ic

klone-ic.h : klone2ic klstartup.kl
	./klone2ic KlStartupCode klstartup.kl > klone-ic.h

kl_evalorder: kl_evalorder.c
	$(CC) kl_evalorder.c -o kl_evalorder

kl_evalorder.h : kl_evalorder $(CC)
	./kl_evalorder>kl_evalorder.h

klconfig.h : 
	-if test ! -f klconfig.h;then touch klconfig.h;fi 


kly.tab.c : klparser.y klparser.h
	byacc -l -d -b kly -p Klyy klparser.y         # ==> kly.tab.c & kly.tab.h

kllex.yy.c : klparser.l klparser.h
	(echo '#include "klparser.h"'; flex -L -t klparser.l) > kllex.yy.c

kly.tab.o : kly.tab.c kly.tab.h klconfig.h
kllex.yy.o : kllex.yy.c kly.tab.h klconfig.h

bg	: 
	trap "" 1;make -k >LOG 2>&1&

depend: 
	-if test ! -f kl_evalorder.h;then >kl_evalorder.h;>kl_evalorder.d;fi
	-if test ! -f klconfig.h;then >klconfig.h;>klconfig.d;fi
	makedep -s "# DO NOT DELETE" $(KLONECFLAGS) $(SRCS)
	-if test -f kl_evalorder.d; then rm -f kl_evalorder.d kl_evalorder.h;fi
	-if test -f klconfig.d; then rm -f klconfig.d klconfig.h;fi

Makefile.dist: 
	ln -s Makefile 	    Makefile.dist  

makefile: Makefile.dist .dir $(LOCAL_MAKE)
	echo 'LOCAL_MAKE=Config.'`cat .dir`|cat Makefile.first Config.`cat .dir` - Makefile.dist \
	     > makefile
	-if grep '^ ' $(CC);then rm -f $(CC);make $(MAKE) $(MFLAGS);fi
#	@echo "makefile re-created, re-running make"
#	$(MAKE) $(MFLAGS)
	     
.dir	:
	@echo "For a quick install, you can type \"make config\" here,"
	@echo "where config is one of:"
	@grep '^#: ' Configs/*|grep -v TEMPLATE|sed 's/^Configs\//    /'|sed 's/#: /	/'
	@echo "if you cannot create a /usr/local/lib/klone directory, please"
	@echo "edit the KLONEPATH line in the relevant file in Configs/"
	@echo "If your config \"foo\" is not listed: "
	@echo "    cp Configs/TEMPLATE Configs/foo"
	@echo "    emacs Configs/foo          # or your favorite editor"
	@echo "       ... set the defines accordingly, see klmachine.h"
	@echo "    make foo"
	@exit 1

doc	:
	cd doc; make

lint	: $(SRCS) makefile # was: -axz
	lint -hz -DLINT $(KLONECFLAGS) $(SRCS)  2>&1 |\
fgrep -v ': warning: long assignment may lose accuracy' |\
fgrep -v ': warning: questionable conversion of function pointer' \
>lint
	-grep 'variable [#number]* of arg' lint

LINT	: $(SRCS) makefile 
	lint -hvz $(KLONECFLAGS) $(SRCS)  2>&1 |\
fgrep -v ': warning: long assignment may lose accuracy' |\
fgrep -v ': warning: questionable conversion of function pointer' \
>lint

clean:
	rm -f *.o makefile $(CC) kl_evalorder kl_evalorder.h
	-if test ! -r SRC; then rm -f .dir; fi   # removes .dir if compil in src

dir:
	./klone\_util dir ${DIR}

sdir:
	./klone\_util sdir ${DIR}

install:libklone.a klone
	-mkdir $(KLONEDIR)
	-mv $(KLONEBINDIR)/klone $(KLONEBINDIR)/klone.old
	cp klone $(KLONEBINDIR)
	cp -r kl/* $(KLONEDIR)

ses_ndbm:   kclist.h  
	$(CC) -o ses_ndbm   -L. -L/usr/lib -lgdbm

ses_calc:   kclist.h  
	$(CC) -o ses_calc  

ses_draw:   kclist.h  
	$(CC) -o ses_draw  -I/usr/X11R6/include  \
	-L/usr/X11R6/lib -lXt -lSM -lICE -lX11 $(LIBS)

klonesesdraw: main.c  libklone.a
	 $(CC) -DKLONE_EXTENSIONS="DrawInit()" -I/usr/X11R6/include \
	-L/usr/X11R6/lib  -o klonesesdraw main.c  \
	-lXt -lSM -lICE -lX11 libklone.a -lm $(LIBS)

.SUFFIXES: .i
.c.i: ; $(CC) -E $(CFLAGS) $*.c > $*.i

# DO NOT DELETE

klone.o: INTERN.h klone.h klconfig.h klmachine.h EXTERN.h kl_atom.h kl_coll.h
klone.o: kl_list.h kl_func.h kl_evalorder.h kl_number.h kl_string.h kl_hash.h
klone.o: kl_stream.h kl_struct.h
klparseutils.o: klparser.h EXTERN.h klone.h klconfig.h klmachine.h kl_atom.h
klparseutils.o: kl_string.h kl_list.h kl_coll.h klko.h kly.tab.h
kl_atom.o: EXTERN.h klone.h klconfig.h klmachine.h kl_coll.h kl_number.h
kl_atom.o: kl_list.h kl_string.h kl_stream.h INTERN.h kl_atom.h kl_func.h
kl_atom.o: kl_evalorder.h klversion.h
kl_coll.o: EXTERN.h klone.h klconfig.h klmachine.h kl_number.h kl_atom.h
kl_coll.o: kl_list.h kl_string.h kl_stream.h kl_func.h kl_evalorder.h
kl_coll.o: INTERN.h kl_coll.h
kl_func.o: EXTERN.h klone.h klconfig.h klmachine.h kl_atom.h kl_string.h
kl_func.o: kl_number.h kl_list.h kl_hash.h kl_stream.h kl_coll.h INTERN.h
kl_func.o: kl_func.h kl_evalorder.h
kl_link.o: EXTERN.h klone.h klconfig.h klmachine.h kl_number.h kl_atom.h
kl_link.o: INTERN.h kl_link.h
kl_list.o: EXTERN.h klone.h klconfig.h klmachine.h kl_number.h kl_atom.h
kl_list.o: kl_coll.h kl_func.h kl_evalorder.h kl_string.h kl_hash.h
kl_list.o: klgeneric.h kl_stream.h INTERN.h kl_list.h
kl_hash.o: EXTERN.h klone.h klconfig.h klmachine.h kl_number.h kl_atom.h
kl_hash.o: kl_list.h kl_func.h kl_evalorder.h INTERN.h kl_hash.h
kl_number.o: EXTERN.h klone.h klconfig.h klmachine.h kl_atom.h kl_string.h
kl_number.o: kl_list.h INTERN.h kl_number.h
kl_string.o: EXTERN.h klone.h klconfig.h klmachine.h kl_number.h kl_atom.h
kl_string.o: kl_list.h klgeneric.h INTERN.h kl_string.h klregexp.h
kl_stream.o: EXTERN.h klone.h klconfig.h klmachine.h kl_number.h kl_atom.h
kl_stream.o: kl_list.h kl_string.h kl_func.h kl_evalorder.h klgeneric.h
kl_stream.o: klnet.h klparser.h kl_coll.h klko.h INTERN.h kl_stream.h
kl_struct.o: EXTERN.h klone.h klconfig.h klmachine.h kl_number.h kl_atom.h
kl_struct.o: kl_string.h kl_list.h kl_hash.h kl_stream.h INTERN.h kl_struct.h
klnet.o: EXTERN.h klone.h klconfig.h klmachine.h kl_number.h kl_atom.h
klnet.o: kl_string.h klregexp.h kl_list.h kl_stream.h INTERN.h klnet.h
klmalloc.o: EXTERN.h klone.h klconfig.h klmachine.h kl_list.h
klmachine.o: klmachine.h
klreference.o: EXTERN.h klone.h klconfig.h klmachine.h
klgeneric.o: EXTERN.h klone.h klconfig.h klmachine.h kl_atom.h kl_number.h
klgeneric.o: kl_list.h kl_func.h kl_evalorder.h kl_hash.h kl_string.h
klgeneric.o: INTERN.h klgeneric.h
klerror.o: EXTERN.h klone.h klconfig.h klmachine.h kl_atom.h kl_string.h
klerror.o: kl_stream.h kl_number.h kl_list.h kl_func.h kl_evalorder.h
klerror.o: kl_hash.h
klregexp.o: klregexp.h klmachine.h
klos.o: EXTERN.h klone.h klconfig.h klmachine.h kl_atom.h kl_number.h
klos.o: kl_list.h kl_func.h kl_evalorder.h kl_string.h kl_hash.h kl_stream.h
klos.o: kl_struct.h klregexp.h INTERN.h
klmath.o: klone.h klconfig.h klmachine.h kl_atom.h kl_string.h kl_list.h
klmath.o: kl_number.h
klko.o: EXTERN.h klone.h klconfig.h klmachine.h kl_number.h kl_atom.h
klko.o: kl_list.h kl_coll.h kl_string.h kl_stream.h INTERN.h klko.h
kltoplevel.o: EXTERN.h klone.h klconfig.h klmachine.h kl_atom.h kl_coll.h
kltoplevel.o: kl_func.h kl_evalorder.h kl_list.h kl_number.h kl_string.h
kltoplevel.o: kl_stream.h
kldebug.o: EXTERN.h klone.h klconfig.h klmachine.h kl_atom.h kl_coll.h
kldebug.o: kl_list.h kl_func.h kl_evalorder.h kl_number.h kl_string.h
kldebug.o: kl_hash.h kl_stream.h kl_struct.h
