# -*- makefile -*- 
#
# builds a C library
#

# Required macros:
#  TARGET = libraryname  (no leading lib or trailing .so or whatever)
# VERSION = version number major.minor
#     API = public include files
# HEADERS = private include files
# SOURCES = list of C source files in this library
#  CFLAGS = extra compiler flags
#  EXTRAS = other files that make distclean should not nuke
#
#       CONTAINER = name of any one of the containers to create
#   DEFAULT_EXTRA = extra default make targets, use 'containers'
#   INSTALL_EXTRA = extra install targets
# UNINSTALL_EXTRA = extra uninstall targets

LIB_SUFFIX = $(CSLU_SHLIB_SUFFIX)

INC = -I$(CSLU_INCLUDE_DIR) -I$(CONFIG_DIR) $(BUILD) $(TCL_INC)
CF  = -c $(INC) $(CSLU_SHLIB_CFLAGS) $(CSLU_DEFS) $(CFLAGS) $(COPT)
TSO = $(TARGET)$(LIB_SUFFIX)
TSL = $(TARGET).lib

default: $(TSO) $(DEFAULT_EXTRA)
install: install-libs install-includes $(INSTALL_EXTRA)
install-libs: $(SHLIB_DIR) $(SHLIB_DIR)\$(TSO) $(LIB_DIR) $(LIB_DIR)\$(TSL)
install-containers: $(CONTAINER_DIR) $(CONTAINER_DIR)\$(CONTAINER)

uninstall: uninstall-libs uninstall-includes $(UNINSTALL_EXTRA)

uninstall-libs:
	-$(RM) $(SHLIB_DIR)\$(TSO)
	-$(RM) $(LIB_DIR)\$(TSL)

objects: $(OBJECTS) $(OBJECTS_DIR)
	$(AR) -NOLOGO -OUT:$(TARGET).LIB $(OBJECTS)
	$(CP) $(TARGET).LIB $(OBJECTS_DIR)\LIB_$(TARGET).LIB

$(TSO): $(OBJECTS)
	-$(RM) $@
	$(CSLU_SHLIB_LD) -OUT:$@ $(LFLAGS) $(LOPT) $(OBJECTS) $(LIBS) $(TCLLIB) $(TKLIB) $(WINLIBS)

$(SHLIB_DIR)\$(TSO): $(TSO)
	$(CP) $(TSO) $@
	$(TOUCH) $@

$(LIB_DIR)\$(TSL): $(TSL)
	$(CP) $(TSL) $@
	$(TOUCH) $@

$(TSL): $(TSO)

cntrs.o: $(source)\cntrs.c
	$(CSLU_CC) $(CF) -Fo$@ $(source)\cntrs.c

cntrs.exe: cntrs.o
	link -nologo -out:$@ cntrs.o \
	     container.lib hash.lib result.lib dballoc0.lib $(TCLLIB)

containers: containers\$(CONTAINER)

containers\$(CONTAINER): cntrs.exe
	.\cntrs.exe
 
$(CONTAINER_DIR)\$(CONTAINER): containers\$(CONTAINER)
	xcopy containers $(CONTAINER_DIR) /f /s
	$(TOUCH) $@

uninstall-containers:
	@echo not removing containers!

.c.o:
	$(CSLU_CC) $(CF) -Fo$@ $<
