Newer
Older
Import / research / ui / TweakableProperties / Makefile.inc

####### Cross-platform settings

ifneq (,$(findstring Windows,$(PATH)))
    UNAME      := Windows
	TARGET_EXT := .exe
#	LFLAGS     := -Wl,-s -Wl,-subsystem,console
	DEL        := del /q
	SEPERATOR  := $(subst /,\,/)
	MKDIR       = if not exist $(subst /,\,$(1)) mkdir $(subst /,\,$(1))
else
    UNAME      := $(shell uname -s)
	TARGET_EXT :=
	LFLAGS     := -Wl,-s
	DEL        := rm 
	SEPERATOR  := /
	MKDIR       = mkdir -p $(1)
endif

####### Output directory

TARGET_DIR = bin
TEMPDIR    = build
TARGETBIN  = $(TARGET_DIR)/$(TARGET)$(TARGET_EXT)

####### Compiler, tools and options

CC         = gcc
CXX        = g++
LINK       = g++
STRIP      = strip

CFLAGS     = -MMD -Os -Wall $(DEFINES) $(INCLUDES)
CXXFLAGS   = -std=gnu++0x -fno-exceptions -fno-rtti $(CFLAGS)
LINKFLAGS  = $(LFLAGS)
STRIPFLAGS = --strip-all -x

####### Intermediate files

OBJECTS    = $(patsubst %.cpp,$(TEMPDIR)/%.o,$(SOURCES))
DEPENDS    = $(patsubst %.o,%.d,$(OBJECTS))

####### Build rules

all: $(TARGETBIN)

.PHONY: clean

clean:
	$(DEL) $(subst /,$(SEPERATOR),$(OBJECTS) $(DEPENDS) $(TARGETBIN))

####### Implicit rules

-include $(DEPENDS)

.SUFFIXES: .cpp .c

build/%.o : %.cpp
	$(call MKDIR,$(dir $@))
	$(CXX) -c $(CXXFLAGS) -o $@ $<

build/%.o : %.c
	$(call MKDIR,$(dir $@))
	$(CC) -c $(CFLAGS) -o $@ $<

####### Compile

$(TARGETBIN): $(OBJECTS)
	$(call MKDIR,$(dir $@))
	$(LINK) $(LINKFLAGS) -o $@ $^ $(LIBS)
	$(STRIP) $(STRIPFLAGS) $@