# -*- makefile -*-
#
# default rules used by the makefile templates in this directory
#
# macros:
#
#
API = $(API_0) $(API_1) $(API_2) $(API_3) $(API_4) $(API_5) $(API_6) $(API_7) \
      $(API_8) $(API_9) $(API_10)
DISTRIB = Makefile CVS $(API) $(HEADERS) $(SOURCES) $(EXTRAS) $(PACKAGE)


# empty stub
init:

# remove object and library files
#
clean:
	-$(RM) *.o *$(CSLU_SHLIB_SUFFIX) *$(CSLU_LIB_SUFFIX) *~ cntrs.exe
	-$(RM) $(TARGET) *.exp *.lib *.exe *.pch *.pdb
	-$(RMDIR) /s /q containers

# remove everything that isn't part of the distribution
#
distclean: clean
	@if test "x$(SURE)" != "xyes"; then \
	  echo "" >&2;\
	  echo "WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING!" >&2;\
	  echo "'$(MAKE) $@' will remove ALL files that are not part" >&2;\
	  echo "  of the source distribution (as listed in the Makefile)" >&2;\
	  echo "" >&2 ;\
	  echo "Please see the Makefile template directory for details." >&2;\
	  echo "" >&2 ;\
	  echo "If you are Really Sure that '$(MAKE) $@' is a Good Idea, run" >&2;\
	  echo "  '$(MAKE) $@ SURE=yes'" >&2 ;\
	  echo "" >&2;\
	  exit 7;\
	fi
	@$(MKDIR) distclean
	-@$(MV) $(DISTRIB) distclean
	-@$(RM) * 2> /dev/null
	@$(MV) distclean/* .
	@$(RMDIR) distclean

# create a new makefile in $(dir)
# must be invoked from the source directory
#
build:
	@echo "Creating Makefile in $(dir)"
	@$(MKDIR) -p $(dir)
	@sed -e "s@source = .*\$$@source = `cd $(source); pwd`@" Makefile > $(dir)/mft
	@$(MV) $(dir)/mft $(dir)/Makefile
	@if test "x$(OBJONLY)" != "x1"; then \
	  echo "" >> $(dir)/Makefile;\
	  echo "#-----------------------------------------------------------------------------" >>$(dir)/Makefile;\
	  echo "# Generated by 'make build dir=$(dir)'" >> $(dir)/Makefile;\
	  echo "#-----------------------------------------------------------------------------" >>$(dir)/Makefile;\
	  echo "BUILD = -I\$$(source)" >> $(dir)/Makefile;\
	  echo "OBJONLY = 1" >> $(dir)/Makefile;\
	  echo "" >> $(dir)/Makefile;\
	  for x in $(NAMES); \
	  do \
	    echo "$${x}.o: \$$(source)/$${x}.c" >> $(dir)/Makefile; \
	    echo "	\$$(CSLU_CC) \$$(CF) -o \$$@ \$$(source)/$${x}.c" >> $(dir)/Makefile; \
	    echo "" >> $(dir)/Makefile; \
	  done;\
	fi

# create a new NMAKE (spit!) makefile in $(dir)
# must be invoked from the source directory
#
ntbuild:
	@echo "Creating NT Makefile in $(dir)"
	@$(MKDIR) -p $(dir)
	@sed -e "s@^source = .*\$$@source = $(DPT)@" \
	     -e 's@_TOP_@\$$(TOP)@g' \
	     -e "s@^include @!include @" Makefile >$(dir)/mft
	@$(MV) $(dir)/mft $(dir)/Makefile
	@if test "x$(OBJONLY)" != "x1"; then \
	  echo "" >> $(dir)/Makefile;\
	  echo "#-----------------------------------------------------------------------------" >>$(dir)/Makefile;\
	  echo "# Generated by 'make build dir=$(dir)'" >> $(dir)/Makefile;\
	  echo "#-----------------------------------------------------------------------------" >>$(dir)/Makefile;\
	  echo "BUILD = -I\$$(source)" >> $(dir)/Makefile;\
	  echo "OBJONLY = 1" >> $(dir)/Makefile;\
	  echo "" >> $(dir)/Makefile;\
	  for x in $(NAMES); \
	  do \
	    echo "$${x}.o: \$$(source)/$${x}.c" >> $(dir)/Makefile; \
	    echo "	\$$(CSLU_CC) \$$(CF) -o \$$@ \$$(source)/$${x}.c" >> $(dir)/Makefile; \
	    echo "" >> $(dir)/Makefile; \
	  done;\
	fi

fixconfig:
	@echo "Updating CONFIG entry"
	@sed -e "s@CONFIG = .*\$$@CONFIG = $(CONFIG)@" Makefile > mft
	@$(MV) mft Makefile

backup:
	@cp Makefile Makefile.backup


$(SHLIB_DIR) $(INCLUDE_DIR) $(BIN_DIR) $(CONTAINER_DIR) $(PKG_DIR) $(LIB_DIR) $(OBJECTS_DIR):
	$(MKDIR) $@
	$(CHMOD) 755 $@


public:
	@echo "$(API)" > $@
