TARGET = lib$(IVTARGET).a

PLATFORM = Linux

CC = g++

release: BUILD = Release
release: CFLAGS = -c -O
release: $(TARGET)
release: copyheaders

debug: BUILD = Debug
debug: CFLAGS = -c -g
debug: $(TARGET)
debug: copyheaders

#------------------------------
# set based on build type

TARGETDIR = ../Libs/$(PLATFORM)$(BUILD)
OBJSDIR = $(PLATFORM)$(BUILD)
HEADERSDIR = ../Includes

ifeq ($(PLATFORM),Linux)
	SYSIPATH = -I/usr/X11R6/include
else
	SYSIPATH =
endif

$(OBJSDIR):
	-mkdir -p $(OBJSDIR)
	
$(TARGETDIR):
	-mkdir -p $(TARGETDIR)

#-------------------------------

OBJS = $(patsubst %.cpp,%.o,$(wildcard *.cpp))
HEADERS = $(wildcard *.h)

#-------------------------------

$(TARGET): $(OBJS) $(TARGETDIR)
	cd $(OBJSDIR) && ar rc ../$(TARGETDIR)/$(TARGET) $(OBJS)
	ranlib $(TARGETDIR)/$(TARGET)

%.o: %.cpp $(OBJSDIR)
	$(CC) $(CFLAGS) -DPLATFORM_$(PLATFORM) $(IVINCLUDEDIRS) $(SYSIPATH) $< -o $(OBJSDIR)/$@

#-------------------------------

.PHONY: copyheaders
copyheaders:
	-mkdir -p $(HEADERSDIR)
	cp $(HEADERS) $(HEADERSDIR)

.PHONY: clean
clean:
	-cd $(PLATFORM)Release && rm -f $(OBJS)
	-cd .. && cd Libs && cd $(PLATFORM)Release && rm -f $(TARGET) 
	-cd $(PLATFORM)Debug && rm -f $(OBJS)
	-cd .. && cd Libs && cd $(PLATFORM)Debug && rm -f $(TARGET) 
	-cd .. && cd Includes && rm -f $(HEADERS) 
