############################################
############################################
#########     AZTEC 3D MODELLER    #########
#########    (c) Phillip Martin    #########
######### http://diginux.net/aztec #########
############################################
############################################
#########     MODULE: Milkshape3DPlugin#####
#########     PLATFORM: Linux      #########	
#########     PROC: i386           #########
############################################
############################################

#**** The following do not be re-defined ****#
  
#Location of executable 
EXECUTE_DIR=../../redist/release/linux-i386/bin/
#Location of object files
OBJECT_DIR=../../redist/release/linux-i386/obj/Milkshape3DPlugin
#List of all the directories we want to compile
SRC_DIRS = src 
#Location of include files
INCLUDE_DIR=include 


#*** The following are defined according to the platform noted above ****#

#Define the C compiler
CC=gcc
#Define the C++ compiler
CPP=g++
#Define the linker
LD=ld
#Extension name for object files
OBJEXT = .o
# Define our make dir command
MAKE_DIR = mkdir
#The finished file we want
TARGET=Milkshape3DPlugin.so
#The finished static file we want
STATIC_TARGET=Milkshape3DPlugin.so
#Standard Linux include directoires
STD_DIR = -I./include -I/usr/include -I./../AztecLib/include
#Location of X include files
X_DIR = -I/usr/X11R6/include
#Standard library directory for Linux
LIB_DIR = -L/usr/lib
#Command line switches for compiler
CFLAGS = -g -O2 -D_REENTRANT -DHAVE_OPENGL -I${INCLUDE_DIR} ${STD_DIR}
CPPFLAGS = -g -O2 -D_REENTRANT -DHAVE_OPENGL -I${INCLUDE_DIR} ${STD_DIR}
#The whole command line for compiler grouped together
COMPILE_FLAGS = ${CFLAGS} ${STD_DIR} ${X_DIR} ${SDL_DIR} -I${INCLUDE_DIR}
#Command line switches for linker
LFLAGS = -E -share
#The whole command line for linker
LINK_FLAGS = ${LIB_DIR} ${LFLAGS} ../../redist/release/linux-i386/bin/libAztecLib.so


AZTEC_ECHO = echo

#**** We now compile everything ****#


# set up our source files
C_SRC := $(wildcard $(SRC_DIRS:%=%/*.c))
CPP_SRC := $(wildcard $(SRC_DIRS:%=%/*.cpp))

# now transform our source files into object files.
OBJECT_FILES := \
	$(C_SRC:%.c=%$(OBJEXT)) \
	$(CPP_SRC:%.cpp=%$(OBJEXT))

#now pfrefix all those object filenames with the directory we wish to place them.
OBJECT_FILES := $(OBJECT_FILES:%=$(OBJECT_DIR)/%)

# Makes all the cpp source files
$(OBJECT_DIR)/%$(OBJEXT): %.cpp
	$(CPP) -c -Wall $(CFLAGS) $< -o $@

# Makes all the c source files
$(OBJECT_DIR)/%$(OBJEXT): %.c
	$(CC) -c -Wall $(CFLAGS) $< -o $@

$(EXECUTE_DIR)/$(TARGET): $(OBJECT_FILES)
	$(LD) $(LINK_FLAGS) $^ -o $@

all: Milkshape3DPlugin

InitialiseDirs:
	@$(AZTEC_ECHO) "Creating directories for Milkshape3DPlugin..."
	$(MAKE_DIR) -p $(OBJECT_DIR)
	$(MAKE_DIR) -p $(EXECUTE_DIR)
	$(foreach i, $(SRC_DIRS), \
		$(shell $(MAKE_DIR) -p $(OBJECT_DIR)/$(i)  ))


#Command to make the Milkshape3DPlugin
Milkshape3DPlugin: InitialiseDirs $(EXECUTE_DIR)/$(TARGET)

#Cleanup all files
clean:
	rm -f ${EXECUTE_DIR}/${TARGET} ${EXECUTE_DIR}/${STATIC_TARGET} $(OBJECT_DIR)/src/*.*


#### END OF MAKEFILE ####



 