
.PHONY: clean veryclean install uninstall

clean:
	@echo Cleaning up...
ifdef UNIX_TOOLS
	- rm -f $(OBJECTS)
	- rm -f $(EXAMPLE_DIR_U)/*.obj
	- rm -f $(EXAMPLE_DIR_U)/*.o
	- rm -f $(EXAMPLE_DIR_U)/allegro.log
	- rm -f $(EXAMPLE_DIR_U)/*exe.manifest
	- rm -f $(EXAMPLE_DIR_U)/*.pdb
	- rm -f $(EXAMPLE_DIR_U)/*.ilk
else
	- del $(EXAMPLE_DIR_D)\*.obj
	- del $(EXAMPLE_DIR_D)\*.o
	- del $(OBJ_DIR_D)\*.obj
	- del $(OBJ_DIR_D)\*.o
	- del $(EXAMPLE_DIR_D)\allegro.log
	- del $(EXAMPLE_DIR_D)\*exe.manifest
	- del $(EXAMPLE_DIR_D)\*.pdb
	- del $(EXAMPLE_DIR_D)\*.ilk
endif

veryclean: clean
ifdef UNIX_TOOLS
	- rm -f $(LIB_PATH_U)
	- rm -f $(LIB_LINKS_U)
	- rm -f $(EXAMPLES)
	- rm -rf docs/html
	- rm -rf docs/rtf
else
	- del $(LIB_PATH_D)
   define RM_EXAMPLES
      $(foreach file, $(wildcard $(subst /,\,$(EXAMPLES))), - del $(file)
      )
   endef
	- $(RM_EXAMPLES)
	- @echo Y|del docs\html\*.*
	- rd docs\html
	- @echo Y|del docs\rtf\*.*
	- rd docs\rtf
endif

ifeq ($(DATA_INSTALLER),)
  DATA_INSTALLER=cp
  PROG_INSTALLER=cp
endif

install: $(LIB_PATH_U) $(HEADERS_U) $(EXT_HEADERS_U)
ifdef UNIX_TOOLS
   define CP_INSTALL
      $(foreach file, $(HEADERS_U), - $(DATA_INSTALLER) $(file) $(subst include,$(COMPILER_INCLUDE_DIR_U),$(file))
      )
      $(foreach file, $(EXT_HEADERS_U), - $(DATA_INSTALLER) $(file) $(subst include,$(COMPILER_INCLUDE_DIR_U),$(file))
      )
   endef
   define INSTALL_LINK
      $(foreach link, $(LIB_LINKS_U), - ln -sf $(notdir $(LIB_PATH_U)) $(subst $(LIB_DIR),$(COMPILER_LIB_DIR_U),$(link))
      )
   endef
      ifeq ($(wildcard $(COMPILER_INCLUDE_DIR_U)/allegrogl),)
	mkdir -p $(COMPILER_INCLUDE_DIR_U)/allegrogl
      endif
      ifeq ($(wildcard $(COMPILER_INCLUDE_DIR_U)/allegrogl/GLext),)
	mkdir -p $(COMPILER_INCLUDE_DIR_U)/allegrogl/GLext
      endif
      ifeq ($(wildcard $(COMPILER_LIB_DIR_U)),)
	mkdir -p $(COMPILER_LIB_DIR_U)
      endif
	- $(CP_INSTALL)
	$(PROG_INSTALLER) $(LIB_PATH_U) $(subst $(LIB_DIR),$(COMPILER_LIB_DIR_U),$(LIB_PATH_U))
	- $(INSTALL_LINK)
	- $(LDCONFIG)
else
   define CP_INSTALL
      $(foreach file, $(HEADERS_D), - copy /y $(file) $(subst include,$(COMPILER_INCLUDE_DIR_D),$(file))
      )
      $(foreach file, $(EXT_HEADERS_D), - copy /y $(file) $(subst include,$(COMPILER_INCLUDE_DIR_D),$(file))
      )
   endef
	- mkdir $(COMPILER_INCLUDE_DIR_D)\allegrogl
	- mkdir $(COMPILER_INCLUDE_DIR_D)\allegrogl\GLext
	- $(CP_INSTALL)
	copy /y $(LIB_PATH_D) $(COMPILER_LIB_DIR_D)
endif
	@echo -
	@echo AllegroGL is now installed.

uninstall:
ifdef UNIX_TOOLS
   define RM_UNINSTALL
      $(foreach link, $(LIB_LINKS_U), - rm -f $(subst $(LIB_DIR),$(COMPILER_LIB_DIR_U),$(link))
      )
      $(foreach file, $(HEADERS_U), - rm -f $(subst include,$(COMPILER_INCLUDE_DIR_U),$(file))
      )
      $(foreach file, $(EXT_HEADERS_U), - rm -f $(subst include,$(COMPILER_INCLUDE_DIR_U),$(file))
      )
   endef
	- rm -f $(COMPILER_LIB_DIR_U)/$(notdir $(LIB_PATH_U))
	- $(RM_UNINSTALL)
	- rm -rf $(COMPILER_INCLUDE_DIR_U)/allegrogl/GLext
	- rm -rf $(COMPILER_INCLUDE_DIR_U)/allegrogl
else
   define RM_UNINSTALL
      $(foreach file, $(notdir $(HEADERS_D)), - del $(COMPILER_INCLUDE_DIR_D)\$(file)
      )
      $(foreach file, $(notdir $(EXT_HEADERS_D)), - del $(COMPILER_INCLUDE_DIR_D)\$(file)
      )
   endef
	- $(RM_UNINSTALL)
	- rmdir /s /q $(COMPILER_INCLUDE_DIR_D)\allegrogl
	- del $(COMPILER_LIB_DIR_D)\$(notdir $(LIB_PATH_U))
endif
	@echo -
	@echo AllegroGL is uninstalled.

$(EXT_HEADERS_PATH_U)/gl_ext_alias.h: $(EXT_HEADERS_PATH_U)/gl_ext_api.h
ifdef UNIX_TOOLS
	$(SHELL) -c './misc/mkalias.sh'
endif

$(EXT_HEADERS_PATH_U)/glx_ext_alias.h: $(EXT_HEADERS_PATH_U)/glx_ext_api.h
ifdef UNIX_TOOLS
	$(SHELL) -c './misc/mkalias.sh'
endif

$(EXT_HEADERS_PATH_U)/wgl_ext_alias.h: $(EXT_HEADERS_PATH_U)/wgl_ext_api.h
ifdef UNIX_TOOLS
	$(SHELL) -c './misc/mkalias.sh'
endif
