# Makefile

# Palomides:
#CC=i586-mingw32msvc-gcc
#CXX=i586-mingw32msvc-g++
#LD=i586-mingw32msvc-ld
#AR=i586-mingw32msvc-ar
#AS=i586-mingw32msvc-as
#NM=i586-mingw32msvc-nm
#STRIP=i586-mingw32msvc-strip
#RANLIB=i586-mingw32msvc-ranlib
#DLLTOOL=i586-mingw32msvc-dlltool
#OBJDUMP=i586-mingw32msvc-objdump
#RC=i586-mingw32msvc-windres

# Fedora 13:
CC=i686-pc-mingw32-gcc
CXX=i686-pc-mingw32-g++
LD=i686-pc-mingw32-ld
AR=i686-pc-mingw32-ar
AS=i686-pc-mingw32-as
NM=i686-pc-mingw32-nm
STRIP=i686-pc-mingw32-strip
RANLIB=i686-pc-mingw32-ranlib
DLLTOOL=i686-pc-mingw32-dlltool
OBJDUMP=i686-pc-mingw32-objdump
RC=i686-pc-mingw32-windres

LIB_DIR=../libraries

CFLAGS+=-DSIMULATOR -W -I$(LIB_DIR)/Boost1.40 -O0 -I../ -D_CRT_SECURE_NO_DEPRECATE -I$(LIB_DIR)/fltk-1.1.10 -I$(LIB_DIR)/vmmlib/include -I$(LIB_DIR)/glut-3.7.6/include -I$(LIB_DIR)/ann_1.1.1/include -DWIN32 -I$(LIB_DIR)/ -D_DEBUG -D_WINDOWS -DWIN32_LEAN_AND_MEAN -DVC_EXTRA_LEAN -I$(LIB_DIR)/polylib -DWIN32_EXTRA_LEAN -g -I/usr/i586-mingw32msvc/include -I/usr/i586-mingw32msvc/lib -I$(LIB_DIR)/libconfig-1.3.2 

LDFLAGS+=-L$(LIB_DIR)/boost1.40 
LDFLAGS+=-L$(LIB_DIR)/polylib 
LDFLAGS+=-L$(LIB_DIR)/fltk-1.1.10 
LDFLAGS+=-L$(LIB_DIR)/vmmlib 
LDFLAGS+=-L$(LIB_DIR)/CGAL_3.5/CGAL-3.5 
LDFLAGS+=-L$(LIB_DIR)/glut-3.7.6 
LDFLAGS+=-L$(LIB_DIR)/ann_1.1.1/include 
LDFLAGS+=-L$(LIB_DIR)/libconfig-1.3.2/lib 

# Palomides:
#LDFLAGS+=-L"/usr/i586-mingw32msvc/lib" 

# Fedora 13:
LDFLAGS+=-L"/usr/i686-pc-mingw32/lib"
LDFLAGS+=-lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lodbc32 -lodbccp32 -lwsock32 -lcomctl32 -lws2_32 -limm32 -lwinmm -lopengl32 -lstdc++ -lgcc -lctl3d32 -lwsock32 -lopengl32 -lglu32 

LDFLAGS+=-lpolylib -lconfig++ -lGLU -lGL -lfltk -lfltk_gl -lfltk_forms -lglut -lboost_thread-mt -lboost_system-mt 

ifeq ($(TARGET),)
	TARGET=RELEASE
endif

WARNING_FLAGS = -Wall

EXEC=RepSnapper.exe
EXEC_DEBUG=RepSnapper_debug.exe

ifeq ($(TARGET),RELEASE)
	CFLAGS ?= -O2 $(WARNING_FLAGS)
	EXECUTABLE=$(EXEC)
else
	CFLAGS ?= -g -O0 $(WARNING_FLAGS)
	EXECUTABLE=$(EXEC_DEBUG)
endif

GENERATED=ui.cxx ui.h

MAIN_SOURCES=repsnapper.cpp
TEST_SOURCES=unittest.cpp
SHARED_SOURCES=asyncserial.cpp stl.cpp reprapserial.cpp \
	processcontroller.cpp printer.cpp modelviewcontroller.cpp \
	gllight.cpp gcode.cpp arcball.cpp stdafx.cpp ui.cxx \
	rfo.cpp flu_dnd.cpp flu_pixmaps.cpp flu_simplestring.cpp \
	flu_tree_browser.cpp ivcon.cpp file.cpp platform.cpp

HEADERS=arcball.h asyncserial.h convert.h flu_dnd.h flu_enumerations.h \
	flu_export.h flu_pixmaps.h flu_simplestring.h flu_tree_browser.h \
	gcode.h gllight.h ivcon.h miniball.h modelviewcontroller.h \
	printer.h processcontroller.h reprapserial.h rfo.h \
	stdafx.h stl.h triangle.h ui.h platform.h

SHARED_OBJECTS=$(subst .c,.o,$(subst .cxx,.o,$(subst .cpp,.o,$(SHARED_SOURCES))))
MAIN_OBJECTS=$(subst .c,.o,$(subst .cxx,.o,$(subst .cpp,.o,$(MAIN_SOURCES)))) $(SHARED_OBJECTS)
TEST_OBJECTS=$(subst .c,.o,$(subst .cxx,.o,$(subst .cpp,.o,$(TEST_SOURCES)))) $(SHARED_OBJECTS)

all: $(EXECUTABLE)

$(EXECUTABLE): poly_lib $(MAIN_OBJECTS)
	$(CXX) ${INC} $(MAIN_OBJECTS) $(LDFLAGS) -o $@

unittest : poly_lib $(TEST_OBJECTS)
	$(CXX) ${INC} $(TEST_OBJECTS) $(LDFLAGS) $(TEST_LDFLAGS) -o $@

%.cxx %.h:%.fl
	rm -f $@ # fluid doesn't remove on failure.
	fluid -c $<
%.o:%.cxx
	$(CXX) ${INC} -c $(CFLAGS) $< -o $@
%.o:%.cpp
	$(CXX) ${INC} -c $(CFLAGS) $< -o $@
%.o:%.c
	$(CC) ${INC} -c $(CFLAGS) $< -o $@

poly_lib:
	make -C $(LIB_DIR)/polylib/ all

boost_lib:
	cd $(LIB_DIR)/Boost1.40/ && configure --host=i586-mingw32msvc --prefix=/usr/i586-mingw32msvc
	make -C $(LIB_DIR)/Boost1.40

libconfig_lib:
	PATH=/usr/i586-mingw32msvc/bin:$(PATH)
	cd $(LIB_DIR)/libconfig-1.3.2/ && ./configure --host=i586-mingw32msvc --prefix=$(realpath $(LIB_DIR)/libconfig-1.3.2/)
	make -C $(LIB_DIR)/libconfig-1.3.2/ all
	make -C $(LIB_DIR)/libconfig-1.3.2/ install
	

check: unittest
	./unittest

clean:
	rm -f $(SHARED_OBJECTS) $(MAIN_OBJECTS) $(TEST_OBJECTS) \
	      $(EXEC) $(EXEC_DEBUG) $(GENERATED) unittest
	make -i -C $(LIB_DIR)/polylib/ clean
	make -C $(LIB_DIR)/libconfig-1.3.2/ distclean

asyncserial.o: stdafx.h config.h platform.h arcball.h ivcon.h asyncserial.h
repsnapper.o: stdafx.h config.h platform.h arcball.h ivcon.h
repsnapper.o: modelviewcontroller.h ui.h file.h flu_tree_browser.h
repsnapper.o: flu_enumerations.h flu_export.h flu_simplestring.h gcode.h stl.h
repsnapper.o: processcontroller.h printer.h rfo.h gllight.h reprapserial.h
repsnapper.o: asyncserial.h
stl.o: stdafx.h config.h platform.h arcball.h ivcon.h stl.h gcode.h ui.h
stl.o: file.h modelviewcontroller.h processcontroller.h printer.h rfo.h
stl.o: flu_tree_browser.h flu_enumerations.h flu_export.h flu_simplestring.h
stl.o: gllight.h reprapserial.h asyncserial.h
reprapserial.o: stdafx.h config.h platform.h arcball.h ivcon.h reprapserial.h
reprapserial.o: ui.h file.h modelviewcontroller.h gcode.h stl.h
reprapserial.o: processcontroller.h printer.h rfo.h flu_tree_browser.h
reprapserial.o: flu_enumerations.h flu_export.h flu_simplestring.h gllight.h
reprapserial.o: asyncserial.h convert.h
processcontroller.o: stdafx.h config.h platform.h arcball.h ivcon.h
processcontroller.o: modelviewcontroller.h ui.h file.h flu_tree_browser.h
processcontroller.o: flu_enumerations.h flu_export.h flu_simplestring.h
processcontroller.o: gcode.h stl.h processcontroller.h printer.h rfo.h
processcontroller.o: gllight.h reprapserial.h asyncserial.h
printer.o: stdafx.h config.h platform.h arcball.h ivcon.h processcontroller.h
printer.o: printer.h gcode.h rfo.h flu_tree_browser.h flu_enumerations.h
printer.o: flu_export.h flu_simplestring.h stl.h
modelviewcontroller.o: stdafx.h config.h platform.h arcball.h ivcon.h
modelviewcontroller.o: modelviewcontroller.h ui.h file.h flu_tree_browser.h
modelviewcontroller.o: flu_enumerations.h flu_export.h flu_simplestring.h
modelviewcontroller.o: gcode.h stl.h processcontroller.h printer.h rfo.h
modelviewcontroller.o: gllight.h reprapserial.h asyncserial.h
gllight.o: stdafx.h config.h platform.h arcball.h ivcon.h gllight.h
gcode.o: stdafx.h config.h platform.h arcball.h ivcon.h gcode.h ui.h file.h
gcode.o: modelviewcontroller.h stl.h processcontroller.h printer.h rfo.h
gcode.o: flu_tree_browser.h flu_enumerations.h flu_export.h flu_simplestring.h
gcode.o: gllight.h reprapserial.h asyncserial.h
arcball.o: stdafx.h config.h platform.h arcball.h ivcon.h
stdafx.o: stdafx.h config.h platform.h arcball.h ivcon.h stl.h
ui.o: ui.h config.h stdafx.h platform.h arcball.h ivcon.h file.h
ui.o: modelviewcontroller.h gcode.h stl.h processcontroller.h printer.h rfo.h
ui.o: flu_tree_browser.h flu_enumerations.h flu_export.h flu_simplestring.h
ui.o: gllight.h reprapserial.h asyncserial.h
rfo.o: stdafx.h config.h platform.h arcball.h ivcon.h ui.h file.h
rfo.o: modelviewcontroller.h gcode.h stl.h processcontroller.h printer.h
rfo.o: rfo.h flu_tree_browser.h flu_enumerations.h flu_export.h
rfo.o: flu_simplestring.h gllight.h reprapserial.h asyncserial.h flu_pixmaps.h
flu_dnd.o: flu_dnd.h flu_enumerations.h flu_export.h
flu_pixmaps.o: flu_pixmaps.h flu_export.h
flu_simplestring.o: flu_simplestring.h flu_enumerations.h flu_export.h
flu_tree_browser.o: flu_tree_browser.h flu_enumerations.h flu_export.h
flu_tree_browser.o: flu_simplestring.h flu_pixmaps.h
ivcon.o: ivcon.h
file.o: stdafx.h config.h platform.h arcball.h ivcon.h file.h
file.o: modelviewcontroller.h ui.h flu_tree_browser.h flu_enumerations.h
file.o: flu_export.h flu_simplestring.h gcode.h stl.h processcontroller.h
file.o: printer.h rfo.h gllight.h reprapserial.h asyncserial.h
