#A linux centric GNU makefile:
#  http://www.gnu.org/software/make/manual/make.html
#
COMPILER=clang++

RC_CFLAGS=-fPIC
SOEXT=so
EXTRA_FLAGS=-std=c++0x -D_LIBCPP_VISIBILITY_TAG=0
ARCHIVE_BASE_NAME=libtest
LDSHARED_FLAGS=-o $(ARCHIVE_BASE_NAME).$(SOEXT).1.0 \
    -shared -nodefaultlibs -Wl,-soname,$(ARCHIVE_BASE_NAME).$(SOEXT).1 \
    -lpthread -lrt -lc -lstdc++

SRC.dir=../src
SRCS=$(wildcard $(SRC.dir)/*.cpp)
OBJ.dir=../build
OBJS=  $(patsubst $(SRC.dir)/%.cpp,$(BLD.dir)/%.o,$(SRCS))
LIB.dir=.

PP_E.opts?=-Wp,-C,-dD#,-MM

.PHONY: mk_lib target.Ei target.dM

show:
	echo $(OBJS)

target.o: $(OBJ.dir)/$(TARGET).o


target.Ei: $(SRC.dir)/$(TARGET).cpp
	install -d $(OBJ.dir)
	$(COMPILER) -E $(EXTRA_FLAGS) -nostdinc++ -I../include $< > $(OBJ.dir)/$(TARGET).E.cpp
	cat $(OBJ.dir)/$(TARGET).E.cpp \
      | indent -bap - \
      | sed -e 's/} template/}\n\n  template/g' \
      | sed -e 's/:::/: ::/g' \
      > $(OBJ.dir)/$(TARGET).Ei.cpp

target.dM: $(SRC.dir)/$(TARGET).cpp
	install -d $(OBJ.dir)
	$(COMPILER) -E -Wp,-dM $(EXTRA_FLAGS) -nostdinc++ -I../include $< > $(OBJ.dir)/$(TARGET).dm

$(OBJ.dir)/%.o: $(SRC.dir)/%.cpp
	install -d $(OBJ.dir)
	$(COMPILER) -c -g -O0 -MMD $(RC_CFLAGS) $(EXTRA_FLAGS) -nostdinc++ -I../include $< -o $@

$(LIB.dir)/$(ARCV).$(SOEXT).1.0:$(OBJS)
	cc $(OBJS) $(RC_CFLAGS) $(LDSHARED_FLAGS)

mk_lib:$(LIB.dir)/$(ARCV).$(SOEXT).1.0

ifneq ($(INCDEPS),no) 
  include $(OBJ.dir)/*.d
endif
