###          ###
### MAKEFILE ###
###          ###

#
# -- Options
#
# If you have a spaceball, remove the '#' at the beginning of
# the two following line
SBOPTION = -DSPACEBALL
SB	 = -lspaceball

# Choose your library option, depending on your system version
#
# System 3.X
#
#OLD	= -DOLDSYS
#CCKR	=
#SYSLIB	= -limage -ll -lfm_s -lgl_s -lcps -lbsd -lfastm -lmalloc -lm
#
# System 4.X
#
OLD	=
CCKR	= -cckr
SYSLIB	= -limage -ll -lfm_s -lgl_s -lfastm -lm -lmalloc -lc_s

# 
# -- Path for include files
#
IPATH  = -I.

#
# -- Compilation Macros
#

CC     = cc
LD     = cc
LINT   = lint
YACC   = yacc
LEX    = lex
LFLAGS = -u  
CFLAGS = -O2 -prototypes $(CCKR) $(SBOPTION) $(OLD)
LIBS   = libforms.a \
	 $(SB) \
	 $(SYSLIB)

#
# -- Files to be updated
#
OFILES = y.tab.o misc.o radio.o ray.o walkthru.o display.o select.o \
	 modif.o rinit.o iosave.o ioload.o free.o iowrite.o ioread.o \
	 load_image.o soft_zoom.o panels.o interface.o sbinteg.o \
	 forms.o picture.o
CFILES = lex.yy.c y.tab.c misc.c radio.c ray.c walkthru.c display.c select.c \
	 modif.c rinit.c iosave.c ioload.c free.c iowrite.c ioread.c \
	 load_image.c soft_zoom.c panels.c interface.c sbinteg.c \
	 forms.c picture.c
XFILES = rad

#
# -- Dependency rules
#
WHAT_I_WANT: FIRST_ACTION $(XFILES)
	@echo ""
	@echo " *************"
	@echo " *** DONE. ***"
	@echo " *************"
	@echo ""

FIRST_ACTION:
	@echo ""
	@echo " *******************"
	@echo " *** UPDATING... ***"
	@echo " *******************"

$(XFILES): $(OFILES) Makefile

depend:
	@echo ""
	@echo " *** UPDATING DEPENDENCIES... ***"
	@(sed '/^# DO NOT DELETE THIS LINE/q' Makefile && \
	  $(CC) -M $(CFLAGS) $(IPATH) $(CFILES) | \
          egrep -v "/usr/include" | sort -u |\
          sed 's/\.\///; /\//d' \
	 ) >Makefile.new
	@cp Makefile Makefile.BAK
	@cp Makefile.new Makefile
	@rm -f Makefile.new

clean:
	@echo ""
	@echo " *** CLEANING UP... ***"
	-rm -f *.BAK *.CKP .emacs* a.out core

cleanall:
	@echo ""
	@echo " *** CLEANING UP... EVERYTHING... ***"
	-rm -f *.BAK *.CKP .emacs* a.out core
	-rm -f $(OFILES) $(XFILES)
	-make depend

#
# -- Default Rules and Suffixes
#
.SUFFIXES:
.SUFFIXES: .x .o .c .y .l

.c:
	@echo ""
	@echo " *** COMPILING AND LINKING $<... ***"
#	$(LINT) $(LFLAGS) $(IPATH) $<
	$(CC) $(CFLAGS) $(IPATH) $< -o $@ $(OFILES) $(LIBS)

.c.o:
	@echo ""
	@echo " *** COMPILING $<... ***"
#	$(LINT) $(LFLAGS) $(IPATH) $<
	$(CC) $(CFLAGS) $(IPATH) -c $<

#
# -- Non Automatic dependencies
#

y.tab.c:    gram.y lex.yy.c
	@echo ""
	@echo " *** YACCING gram.y... ***"
	$(YACC) gram.y 

lex.yy.c:   lex.l
	@echo ""
	@echo " *** LEXING lex.l... ***"
	$(LEX) lex.l

#
# -- Automatic dependencies
#
# DO NOT DELETE THIS LINE
display.o: constants.h
display.o: display.h
display.o: interface.h
display.o: macros.h
display.o: misc.h
display.o: rad.h
display.o: types.h
display.o: display.c
forms.o: forms.h
forms.o: forms.c
free.o: constants.h
free.o: macros.h
free.o: types.h
free.o: free.c
interface.o: constants.h
interface.o: display.h
interface.o: forms.h
interface.o: interface.h
interface.o: ioload.h
interface.o: iosave.h
interface.o: load_image.h
interface.o: macros.h
interface.o: misc.h
interface.o: modif.h
interface.o: panels.h
interface.o: picture.h
interface.o: rad.h
interface.o: radio.h
interface.o: sbinteg.h
interface.o: select.h
interface.o: types.h
interface.o: walkthru.h
interface.o: interface.c
ioload.o: constants.h
ioload.o: free.h
ioload.o: io.h
ioload.o: ioload.h
ioload.o: load_image.h
ioload.o: macros.h
ioload.o: misc.h
ioload.o: parse.h
ioload.o: rad.h
ioload.o: ray.h
ioload.o: rinit.h
ioload.o: types.h
ioload.o: ioload.c
ioread.o: constants.h
ioread.o: ioread.h
ioread.o: macros.h
ioread.o: misc.h
ioread.o: rad.h
ioread.o: types.h
ioread.o: ioread.c
iosave.o: constants.h
iosave.o: io.h
iosave.o: iosave.h
iosave.o: macros.h
iosave.o: rad.h
iosave.o: types.h
iosave.o: iosave.c
iowrite.o: constants.h
iowrite.o: iowrite.h
iowrite.o: macros.h
iowrite.o: misc.h
iowrite.o: types.h
iowrite.o: iowrite.c
lex.yy.o: lex.yy.c
load_image.o: constants.h
load_image.o: macros.h
load_image.o: types.h
load_image.o: load_image.c
misc.o: constants.h
misc.o: load_image.h
misc.o: macros.h
misc.o: misc.h
misc.o: rad.h
misc.o: types.h
misc.o: misc.c
modif.o: constants.h
modif.o: macros.h
modif.o: modif.h
modif.o: types.h
modif.o: modif.c
panels.o: forms.h
panels.o: panels.h
panels.o: picture.h
panels.o: panels.c
picture.o: constants.h
picture.o: forms.h
picture.o: macros.h
picture.o: picture.h
picture.o: types.h
picture.o: picture.c
radio.o: constants.h
radio.o: macros.h
radio.o: misc.h
radio.o: rad.h
radio.o: radio.h
radio.o: ray.h
radio.o: types.h
radio.o: radio.c
ray.o: constants.h
ray.o: macros.h
ray.o: rad.h
ray.o: radio.h
ray.o: ray.h
ray.o: types.h
ray.o: ray.c
rinit.o: constants.h
rinit.o: macros.h
rinit.o: misc.h
rinit.o: rad.h
rinit.o: radio.h
rinit.o: ray.h
rinit.o: rinit.h
rinit.o: types.h
rinit.o: rinit.c
sbinteg.o: constants.h
sbinteg.o: types.h
sbinteg.o: sbinteg.c
select.o: constants.h
select.o: macros.h
select.o: misc.h
select.o: ray.h
select.o: select.h
select.o: types.h
select.o: select.c
soft_zoom.o: soft_zoom.h
soft_zoom.o: soft_zoom.c
walkthru.o: constants.h
walkthru.o: interface.h
walkthru.o: macros.h
walkthru.o: misc.h
walkthru.o: types.h
walkthru.o: walkthru.h
walkthru.o: walkthru.c
y.tab.o: constants.h
y.tab.o: ioread.h
y.tab.o: lex.yy.c
y.tab.o: macros.h
y.tab.o: misc.h
y.tab.o: rad.h
y.tab.o: types.h
y.tab.o: y.tab.c
