#
# Makefile for ivscan
#
# 6.837 scan converter based on OpenInventor
#

default: thedefault

rm_athena:
	@echo "Removing old athena package."
	-rm -fr athena

#  Call this to make athena package.
athena: rm_athena	
	mkdir -p athena/ivscan
	@echo "Copying over .C, .h, Makefile, and .iv files."
	cp *.[Ch] athena/ivscan
	cp README athena/ivscan
	cp *.iv athena/ivscan
	@echo "Fixing #includes"
	sed -e 's/..\/..\/..\//\/mit\/6.837\/as2_ivscan\//g' < Makefile > tmp
	mv tmp athena/ivscan/Makefile
	@echo "Making solution files"
	grep -v SOLN Scan.C > athena/ivscan/Scan.C
	grep -v SOLN EdgeRec.C > athena/ivscan/EdgeRec.C
	grep -v SOLN EdgeRecList.C > athena/ivscan/EdgeRecList.C
	@echo "Tarring into athena/ivscan.tar"
	cd athena ; tar cvf ../ivscan.tar ivscan

#
#  The following is the developer's Makefile (for course staff).
#

# C++ sources
C++SRCS=\
    Main.C\
    Utils.C\
    Interface.C\
    ScanWrap.C\
    EdgeRec.C\
    EdgeRecList.C\
    List.C \
    Scan.C

# header files
HDRS= Utils.h Interface.h \
      EdgeRec.h EdgeRecList.h \
      List.h Scan.h \
      Edge.h SCtypes.h \
      Polygon.h

# objects
OBJS=${C++SRCS:.C=.o}

# app
TARGET=ivscan

# debugging
DEBUG=-g
CCDEBUG=-g

# Final-stage application compiler 
# (or linker) name (cc, cs, cmf, f77, ...)
TARGET_COMPILER=$(CC)
TARGET_COMPILER_FLAGS=$(DEBUG)

# Put any libs you use here.  These will be included on the link line.
LIBS=-nostdlib -L/mit/6.837/ivscan/ivwraplib -livwrap\
    -L/mit/6.837/ivscan/ivwidgets -lInventorWidget\
    -L/usr/lib -lGLw -lGL -lInventorXt -lXt -lXm -lX11 -lm

NEWLIBS=-nostdlib -L/mit/6.837/ivscan/ivwraplib -livwrap\
    -L/mit/6.837/ivscan/ivwidgets -lInventorWidget\
    -L/usr/lib32 -lGLw -lGL -lInventorXt -lXt -lXm -lX11 -lm

# Put any include directories (-I...) here
INC=-nostdinc -I/usr/include/CC -I/usr/include -I/mit/6.837/ivscan

OLD_FLAG=-o32

# Put any defines or misc. C++ compiler flags here.
CCDEF= $(OLD_FLAG) -xansi -woff 3262 -float

CCFLAGS=$(INC) $(CCDEF) $(CCDEBUG)
CC=/usr/bin/CC

# should be first target
thedefault: /mit/6.837/ivscan/ivwidgets/libInventorWidget.a /mit/6.837/ivscan/ivwraplib/libivwrap.a
	$(MAKE) $(TARGET)

/mit/6.837/ivscan/ivwidgets/libInventorWidget.a:
	cd /mit/6.837/ivscan/ivwidgets; $(MAKE)

/mit/6.837/ivscan/ivwraplib/libivwrap.a:
	cd /mit/6.837/ivscan/ivwraplib; $(MAKE)

# optimized executable
opt:
	$(MAKE) $(TARGET) \
	    CCFLAGS="$(INC) $(CCDEF) -O -DNDEBUG"

#for compiling under IRIX 6.5
sixfive:
	$(MAKE) $(TARGET) \
	    OLD_FLAG="" \
	    LIBS="$(NEWLIBS)"

# make executable
$(TARGET): $(OBJS) /mit/6.837/ivscan/ivwidgets/libInventorWidget.a \
		/mit/6.837/ivscan/ivwraplib/libivwrap.a
	$(TARGET_COMPILER) $(OLD_FLAG) -Wl,-LD_MSG:off=15 -o $@ $(TARGET_COMPILER_FLAGS) \
	    $(OBJS)\
	    $(LIBS)
	@echo $@ is made.

test:Test.o
	CC Test.C -o test $(INC) $(LIBS)

# make student code by stripping SOLN lines
release:
	grep -v SOLN SOLN.Scan.C > Scan.C
	grep -v SOLN SOLN.Scan.h > Scan.h

# make our completed version by copying files
solution:
	cp SOLN.Scan.C Scan.C
	cp SOLN.Scan.h Scan.h

# clean up cruft
clean: .IGNORE
	rm -f *.o ii_files/* *.rgb *.tar \
	    *~ *.slo *.s \
	    *.a *..c TAGS \
	    core a.out \#* *.bak *.BAK *.CKP \
	    *.Addrs *.Counts *.pixie .\#*

# clean up everything
clobber realclean: .IGNORE
	make clean
	rm -f $(TARGET)
	rm -f *.rgb

# ignore errors
.IGNORE:

# known file types
.SUFFIXES: .C

# make a .o from a .C (C++ file)
.C.o:
	$(CC) $(CCFLAGS) -c $<

Scan.o: Scan.C $(HDRS)
ScanWrap.o: ScanWrap.C $(HDRS)
EdgeRec.o: EdgeRec.C $(HDRS)
EdgeRecList.o: EdgeRecList.C $(HDRS)
List.o: List.C List.h







