###############################################################################
# $Id: Makefile.in,v 1.28 2009/03/03 15:50:14 faust Exp $
###############################################################################

include ../../Makefile.conf

PROG = lib$(LIB_NAME).a

ifeq ($(STG_TIME), yes)
DEFS += -DSTG_TIME
endif

ifneq ($(ADD_DEFS),)
DEFS += $(ADD_DEFS)
endif

SEARCH_DIRS = -I $(DIR_INCLUDE) -I ./

OBJS = $(notdir $(patsubst %.cpp, %.o, $(patsubst %.c, %.o, $(SRCS))))

INST_INCS = $(addprefix $(DIR_INCLUDE)/, $(notdir $(INCS)))
INST_LIBS = $(DIR_LIB)/lib$(LIB_NAME)

CXXFLAGS += -fPIC
CFLAGS += -fPIC

vpath %.a $(DIR_LIB)

all: $(PROG)

$(PROG): $(OBJS) $(STGLIBS)
	ar rc lib$(LIB_NAME).a $(OBJS)
	ranlib lib$(LIB_NAME).a
	cp *.a $(DIR_LIB)

includes: $(INCS)
	cp -p $(INCS) $(DIR_INCLUDE)/stg

clean:
	rm -f deps $(PROG) *.o *.a *.so tags *.*~ 
	for file in $(INCS); do \
	    rm -f $(DIR_INCLUDE)/stg/$$file; \
	done

install: $(PROG)
	mkdir -m $(DIR_MODE) -p $(PREFIX)/usr/lib/stg
	install -m $(BIN_MODE) -o $(OWNER) -s $(PROG) $(PREFIX)/usr/lib/stg/$(PROG)
	mkdir -m $(DIR_MODE) -p $(PREFIX)/usr/include/stg
	install -m $(DATA_MODE) -o $(OWNER) $(INCS) $(PREFIX)/usr/include/stg/

uninstall:
	rm -f $(PREFIX)/usr/lib/stg/$(PROG)
	for file in $(INCS); do \
	    rm -f $(PREFIX)/usr/include/stg/$$file; \
	done

ifneq ($(MAKECMDGOALS),includes)
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(MAKECMDGOALS),uninstall)
-include deps
endif
endif
endif

deps:	$(SRCS) ../../Makefile.conf
	@>deps ;\
	for file in $(SRCS); do\
	  echo "`$(CC) $(CXXFLAGS) $(SEARCH_DIRS) $(DEFS) -MM $$file` Makefile ../../Makefile.conf" >> deps ;\
	  echo -e '\t$$(CC) $(CXXFLAGS) $(SEARCH_DIRS) $(DEFS) -c $$<' >> deps ;\
	done