#
# Maverick Model 3D Makefile
#
# GNU Make required
#

# mingw.org's mingw32-make.exe on Windows doesn't have uname
ifdef MINGW32_MAKE
  COMPILE_PLATFORM=mingw32
  COMPILE_ARCH=x86
else
  COMPILE_PLATFORM=$(shell uname|sed -e s/_.*//|tr '[:upper:]' '[:lower:]'|sed -e 's/\//_/g')

  COMPILE_ARCH=$(shell uname -m | sed -e s/i.86/x86/)

  ifeq ($(COMPILE_PLATFORM),sunos)
    # Solaris uname and GNU uname differ
    COMPILE_ARCH=$(shell uname -p | sed -e s/i.86/x86/)
  endif
endif

#############################################################################
#
# If you require a different configuration from the defaults below, create a
# new file named "Makefile.local" in the same directory as this file and define
# your parameters there. This allows you to change configuration without
# causing problems with keeping up to date with the repository.
#
#############################################################################
-include Makefile.local

ifeq ($(COMPILE_PLATFORM),cygwin)
  PLATFORM=mingw32
endif

ifndef PLATFORM
PLATFORM=$(COMPILE_PLATFORM)
endif
export PLATFORM

ifeq ($(PLATFORM),mingw32)
  MINGW=1
endif
ifeq ($(PLATFORM),mingw64)
  MINGW=1
endif

ifeq ($(COMPILE_ARCH),powerpc)
  COMPILE_ARCH=ppc
endif
ifeq ($(COMPILE_ARCH),powerpc64)
  COMPILE_ARCH=ppc64
endif

ifndef ARCH
ARCH=$(COMPILE_ARCH)
endif
export ARCH

ifneq ($(PLATFORM),$(COMPILE_PLATFORM))
  CROSS_COMPILING=1
else
  CROSS_COMPILING=0

  ifneq ($(ARCH),$(COMPILE_ARCH))
    CROSS_COMPILING=1
  endif
endif
export CROSS_COMPILING

ifndef V
V=
endif
ifndef BUILD
BUILD=build
endif

bin_path=$(shell which $(1) 2> /dev/null)

BUILDSUB=${PLATFORM}-${ARCH}
B=${BUILD}/${BUILDSUB}

BUILDSUB_TOOLS=${COMPILE_PLATFORM}-${COMPILE_ARCH}
B_TOOLS=${BUILD}/${BUILDSUB_TOOLS}

INSTALL=install
ifdef MINGW32_MAKE
  MKDIR=mkdir
else
  MKDIR=mkdir -p
endif


#############################################################################
# SETUP AND BUILD -- MINGW
#############################################################################

ifdef MINGW
  ifndef QTDIR
    ifneq ($(CROSS_COMPILING),1)
      QTDIR=C:/Qt/5.11.1/mingw53_32

      ifdef MINGW32_MAKE
        CC=C:\Qt\Tools\mingw530_32\bin\i686-w64-mingw32-gcc-5.3.0.exe
        CXX=C:\Qt\Tools\mingw530_32\bin\i686-w64-mingw32-g++.exe
      endif
    endif
  endif

  ifdef QTDIR
    ifndef QT_BIN_DIR
      QT_BIN_DIR=${QTDIR}/bin
    endif
    ifndef QT_INCLUDE_DIR
      QT_INCLUDE_DIR=${QTDIR}/include
    endif
    ifndef QT_LIB_DIR
      QT_LIB_DIR=${QTDIR}/lib
    endif
    ifndef QT_TRANSLATIONS_DIR
      QT_TRANSLATIONS_DIR=${QTDIR}/translations
    endif
  endif

  ifndef QT_BIN_DIR
    $(error Need to specify QT_BIN_DIR with native Qt5 executables for uic, moc, rcc, and lrelease)
  endif
  ifndef QT_INCLUDE_DIR
    $(error Need to specify QT_INCLUDE_DIR with MinGW Qt5 headers)
  endif
  ifndef QT_LIB_DIR
    $(error Need to specify QT_LIB_DIR with MinGW Qt5 libs)
  endif
  # not required, it's only used on macOS right now
  #ifndef QT_TRANSLATIONS_DIR
  #  $(error Need to specify QT_TRANSLATIONS_DIR with MinGW Qt5 translations)
  #endif

  ifeq ($(CROSS_COMPILING),1)
    # If CC is already set to something generic, we probably want to use
    # something more specific
    ifneq ($(findstring $(strip $(CC)),cc gcc),)
      CC=
    endif
    ifneq ($(findstring $(strip $(CXX)),g++),)
      CXX=
    endif

    # We need to figure out the correct gcc and windres
    ifeq ($(ARCH),x86_64)
      MINGW_PREFIXES=x86_64-w64-mingw32 amd64-mingw32msvc
    endif
    ifeq ($(ARCH),x86)
      MINGW_PREFIXES=i686-w64-mingw32 i586-mingw32msvc i686-pc-mingw32
    endif

    # Prefer POSIX thread model (as opposed to win32) to use the same
    # libgcc and libstdc++ run-time as Qt. Debian has separate binaries
    # with -posix and -win32 suffix. "$(MINGW_PREFIX)-gcc" could be either.
    ifndef CC
      CC=$(strip $(foreach MINGW_PREFIX, $(MINGW_PREFIXES), \
         $(call bin_path, $(MINGW_PREFIX)-gcc-posix)))
    endif
    ifndef CC
      CC=$(strip $(foreach MINGW_PREFIX, $(MINGW_PREFIXES), \
         $(call bin_path, $(MINGW_PREFIX)-gcc)))
    endif

    ifndef CXX
      CXX=$(strip $(foreach MINGW_PREFIX, $(MINGW_PREFIXES), \
         $(call bin_path, $(MINGW_PREFIX)-g++-posix)))
    endif
    ifndef CXX
      CXX=$(strip $(foreach MINGW_PREFIX, $(MINGW_PREFIXES), \
         $(call bin_path, $(MINGW_PREFIX)-g++)))
    endif

    ifndef WINDRES
      WINDRES=$(strip $(foreach MINGW_PREFIX, $(MINGW_PREFIXES), \
         $(call bin_path, $(MINGW_PREFIX)-windres)))
    endif

    TOOLS_BINEXT=
  else
    # Some MinGW installations define CC to cc, but don't actually provide cc,
    # so check that CC points to a real binary and use gcc if it doesn't
    ifeq ($(call bin_path, $(CC)),)
      CC=gcc
    endif

    ifndef CXX
      CXX=g++
    endif

    ifndef WINDRES
      WINDRES=windres
    endif

    TOOLS_BINEXT=.exe
  endif

  ifeq ($(CC),)
    $(error Cannot find a suitable cross compiler for $(PLATFORM))
  endif

  ifdef MINGW32_MAKE
    # mingw32 windres needs absolute path to compiler for using as a preprocessor
    ifeq ("$(wildcard $(CC))","")
    #  $(error CC must be absolute path to gcc)
    endif
  endif

  ifndef QT_LIBS
    QT_LIBS=-lQt5Core -lQt5Gui -lQt5Widgets
  endif

  LINK=-L${QT_LIB_DIR} ${QT_LIBS} -mwindows -lshlwapi -lole32 -lopengl32 -lglu32

  # NOTE: If building using gcc/g++ with win32 thread model or a different
  #       toolchain than Qt was built with you may want to use static libgcc
  #       and libstdc++.
  #LINK+= -static-libgcc -static-libstdc++

  BASE_FLAGS+=-DWIN32

  BINEXT=.${ARCH}.exe

else # ifeq mingw

#############################################################################
# SETUP AND BUILD -- MAC OS X
#############################################################################

ifeq ($(PLATFORM),darwin)

  ifndef PREFIX
    PREFIX=/usr/local
  endif

  ifndef QTDIR
    QTDIR=/usr/local/Cellar/qt/5.11.1
  endif
  ifndef QT_BIN_DIR
    QT_BIN_DIR=${QTDIR}/bin
  endif
  ifndef QT_INCLUDE_DIR
    QT_INCLUDE_DIR=${QTDIR}/include
  endif
  ifndef QT_LIB_DIR
    QT_LIB_DIR=${QTDIR}/lib
  endif
  ifndef QT_FRAMEWORKS_DIR
    QT_FRAMEWORKS_DIR=${QTDIR}/lib
  endif
  ifndef QT_TRANSLATIONS_DIR
    QT_TRANSLATIONS_DIR=${QTDIR}/translations
  endif

  ifndef QT_LIBS
    QT_LIBS=
  endif
  ifndef QT_FRAMEWORKS
    QT_FRAMEWORKS=-framework QtCore -framework QtGui -framework QtWidgets
  endif

  FRAMEWORKS=${QT_FRAMEWORKS} -framework OpenGL
  LINK=-F${QT_FRAMEWORKS_DIR} ${FRAMEWORKS} -L${QT_LIB_DIR} ${QT_LIBS}

  # Required for C++11 on macOS
  BASE_FLAGS+=-stdlib=libc++

  ifeq ($(ARCH),x86)
    BASE_FLAGS += -m32
  endif

  BASE_FLAGS += -DPREFIX="\"$(PREFIX)\"" -DIS_OSX

  # Set this to match Qt's minimum macOS deployment target.
  ifdef MACOSX_VERSION_MIN
    BASE_FLAGS += -mmacosx-version-min=${MACOSX_VERSION_MIN}
  endif

  MACOSX_DEPLOYMENT_TARGET=$(MACOSX_VERSION_MIN)

  BASE_FLAGS += -F${QT_FRAMEWORKS_DIR}

  BINEXT=.${ARCH}
  TOOLS_BINEXT=

else # ifeq darwin

#############################################################################
# SETUP AND BUILD -- LINUX
#############################################################################

  ifndef PREFIX
    PREFIX=/usr/local
  endif

  ifdef QTDIR
    ifndef QT_BIN_DIR
      QT_BIN_DIR=${QTDIR}/bin
    endif
    ifndef QT_INCLUDE_DIR
      QT_INCLUDE_DIR=${QTDIR}/include
    endif
    ifndef QT_LIB_DIR
      QT_LIB_DIR=${QTDIR}/lib
    endif
    ifndef QT_TRANSLATIONS_DIR
      QT_TRANSLATIONS_DIR=${QTDIR}/translations
    endif
  else
    ifndef QT_BIN_DIR
      ifeq ($(ARCH),x86)
        QT_BIN_DIR=/usr/lib/i386-linux-gnu/qt5/bin
      else
        QT_BIN_DIR=/usr/lib/$(ARCH)-linux-gnu/qt5/bin
      endif
    endif
    ifndef QT_INCLUDE_DIR
      ifeq ($(ARCH),x86)
        QT_INCLUDE_DIR=/usr/include/i386-linux-gnu/qt5
      else
        QT_INCLUDE_DIR=/usr/include/$(ARCH)-linux-gnu/qt5
      endif
    endif
    ifndef QT_LIB_DIR
      ifeq ($(ARCH),x86)
        QT_LIB_DIR=/usr/lib/i386-linux-gnu
      else
        QT_LIB_DIR=/usr/lib/$(ARCH)-linux-gnu
      endif
    endif
    ifndef QT_TRANSLATIONS_DIR
      QT_TRANSLATIONS_DIR=/usr/share/qt5/translations/
    endif
  endif

  ifndef QT_LIBS
    QT_LIBS=-lQt5Core -lQt5Gui -lQt5Widgets
  endif

  LINK=-L${QT_LIB_DIR} ${QT_LIBS} -lGLU -lGL -ldl

  ifeq ($(ARCH),x86)
    # linux32 make ...
    BASE_FLAGS += -m32
  else
  ifeq ($(ARCH),ppc64)
    BASE_FLAGS += -m64
  endif
  endif

  BASE_FLAGS += -DPREFIX="\"$(PREFIX)\""

  BINEXT=.${ARCH}
  TOOLS_BINEXT=

endif # darwin
endif # mingw

ifndef QT_BIN_DIR
  $(error QT_BIN_DIR is not set)
endif
ifndef QT_INCLUDE_DIR
  $(error QT_INCLUDE_DIR is not set)
endif

ifndef UIC
  UIC=${QT_BIN_DIR}/uic${TOOLS_BINEXT}
endif
ifndef MOC
  MOC=${QT_BIN_DIR}/moc${TOOLS_BINEXT}
endif
ifndef RCC
  RCC=${QT_BIN_DIR}/rcc${TOOLS_BINEXT}
endif
ifndef LRELEASE
  LRELEASE=${QT_BIN_DIR}/lrelease${TOOLS_BINEXT}
endif
ifndef LCONVERT
  LCONVERT=${QT_BIN_DIR}/lconvert${TOOLS_BINEXT}
endif
ifndef WINDEPLOYQT
  WINDEPLOYQT=${QT_BIN_DIR}/windeployqt${TOOLS_BINEXT}
endif
ifndef MACDEPLOYQT
  MACDEPLOYQT=${QT_BIN_DIR}/macdeployqt${TOOLS_BINEXT}
endif

ifndef MINGW
# not for mingw because warning: -fPIC ignored for target (all code is position independent)
BASE_FLAGS+=-fPIC
endif

BASE_FLAGS+=-fno-math-errno -I${QT_INCLUDE_DIR} -DMM3D_EDIT -I. -I./src -I./src/libmm3d -I./src/mm3dcore -I./src/depui -I./src/qtui -I./src/implui -I./src/commands -I./src/tools -I${B}/depui -I${B}/qtui -I${B}/implui -I${B}/commands

# Generate dependencies (create .d files by the .o files)
BASE_FLAGS+=-MMD -MP

# Use debug or release cflags
#BUILD_FLAGS+=-Wall -Wextra -Wno-unused-parameter -Wno-format-zero-length -g -ggdb
#STRIP=
BUILD_FLAGS+=-Wall -Wextra -Wno-unused-parameter -Wno-format-zero-length -O2
STRIP=strip

CCFLAGS=-std=c99 ${BUILD_FLAGS} ${BASE_FLAGS}
CXXFLAGS=-std=c++11 ${BUILD_FLAGS} ${BASE_FLAGS}

# Use a native compiler for compiling build tools.
ifeq ($(CROSS_COMPILING),1)
	TOOLS_CC=cc
else
	TOOLS_CC=${CC}
endif
TOOLS_CCFLAGS=-std=c99 ${BUILD_FLAGS}

DEFS=

BIN=${B}

LIB_OBJ= \
	${B}/libmm3d/bsptree.o \
	${B}/libmm3d/cal3dfilter.o \
	${B}/libmm3d/cmdlinemgr.o \
	${B}/libmm3d/cobfilter.o \
	${B}/libmm3d/d3dfilter.o \
	${B}/libmm3d/datadest.o \
	${B}/libmm3d/datasource.o \
	${B}/libmm3d/filedatadest.o \
	${B}/libmm3d/filedatasource.o \
	${B}/libmm3d/memdatadest.o \
	${B}/libmm3d/memdatasource.o \
	${B}/libmm3d/dxffilter.o \
	${B}/libmm3d/filefactory.o \
	${B}/libmm3d/filtermgr.o \
	${B}/libmm3d/glmath.o \
	${B}/libmm3d/iqefilter.o \
	${B}/libmm3d/log.o \
	${B}/libmm3d/lwofilter.o \
	${B}/libmm3d/md2filter.o \
	${B}/libmm3d/md3filter.o \
	${B}/libmm3d/mesh.o \
	${B}/libmm3d/misc.o \
	${B}/libmm3d/mlocale.o \
	${B}/libmm3d/mm3dfilter.o \
	${B}/libmm3d/mm3dport.o \
	${B}/libmm3d/mm3dreg.o \
	${B}/libmm3d/model.o \
	${B}/libmm3d/model_anim.o \
	${B}/libmm3d/model_bool.o \
	${B}/libmm3d/model_copy.o \
	${B}/libmm3d/model_draw.o \
	${B}/libmm3d/model_group.o \
	${B}/libmm3d/model_influence.o \
	${B}/libmm3d/model_inner.o \
	${B}/libmm3d/model_insert.o \
	${B}/libmm3d/model_meta.o \
	${B}/libmm3d/model_ops.o \
	${B}/libmm3d/model_print.o \
	${B}/libmm3d/model_proj.o \
	${B}/libmm3d/model_select.o \
	${B}/libmm3d/model_texture.o \
	${B}/libmm3d/modelfilter.o \
	${B}/libmm3d/modelstatus.o \
	${B}/libmm3d/modelundo.o \
	${B}/libmm3d/modelutil.o \
	${B}/libmm3d/ms3dfilter.o \
	${B}/libmm3d/msg.o \
	${B}/libmm3d/objfilter.o \
	${B}/libmm3d/pcxtex.o \
	${B}/libmm3d/rawtex.o \
	${B}/libmm3d/smdfilter.o \
	${B}/libmm3d/texmgr.o \
	${B}/libmm3d/texscale.o \
	${B}/libmm3d/texture.o \
	${B}/libmm3d/tgatex.o \
	${B}/libmm3d/triprim.o \
	${B}/libmm3d/txtfilter.o \
	${B}/libmm3d/undo.o \
	${B}/libmm3d/undomgr.o \
	${B}/libmm3d/weld.o \

MM3D_UI= \
	${B}/qtui/alignwin.base.h \
	${B}/qtui/animconvertwin.base.h \
	${B}/qtui/animeditwin.base.h \
	${B}/qtui/animexportwin.base.h \
	${B}/qtui/animsetwin.base.h \
	${B}/qtui/animwidget.base.h \
	${B}/qtui/autoassignjointwin.base.h \
	${B}/qtui/backgroundselect.base.h \
	${B}/qtui/backgroundwin.base.h \
	${B}/qtui/boolwin.base.h \
	${B}/qtui/contextgroup.base.h \
	${B}/qtui/contextinfluences.base.h \
	${B}/qtui/contextname.base.h \
	${B}/qtui/contextposition.base.h \
	${B}/qtui/contextprojection.base.h \
	${B}/qtui/contextrotation.base.h \
	${B}/qtui/extrudewin.base.h \
	${B}/qtui/groupclean.base.h \
	${B}/qtui/groupwin.base.h \
	${B}/qtui/helpwin.base.h \
	${B}/qtui/jointwin.base.h \
	${B}/qtui/painttexturewin.base.h \
	${B}/qtui/pointwin.base.h \
	${B}/qtui/projectionwin.base.h \
	${B}/qtui/keyvaluewin.base.h \
	${B}/qtui/mapdirection.base.h \
	${B}/qtui/mergewin.base.h \
	${B}/qtui/metawin.base.h \
	${B}/qtui/modelview.base.h \
	${B}/qtui/newanim.base.h \
	${B}/qtui/cal3dprompt.base.h \
	${B}/qtui/iqeprompt.base.h \
	${B}/qtui/md3prompt.base.h \
	${B}/qtui/ms3dprompt.base.h \
	${B}/qtui/objprompt.base.h \
	${B}/qtui/smdprompt.base.h \
	${B}/qtui/offsetwin.base.h \
	${B}/qtui/pluginwin.base.h \
	${B}/qtui/statusbar.base.h \
	${B}/qtui/texturecoord.base.h \
	${B}/qtui/textwin.base.h \
	${B}/qtui/texwin.base.h \
	${B}/qtui/transformwin.base.h \
	${B}/qtui/valuewin.base.h \
	${B}/qtui/viewportsettings.base.h \
	\
	${B}/qtui/resources.cpp

MM3D_MOC= \
	${B}/implui/alignwin.moc.cc \
	${B}/implui/aboutwin.moc.cc \
	${B}/implui/animconvertwin.moc.cc \
	${B}/implui/animeditwin.moc.cc \
	${B}/implui/animexportwin.moc.cc \
	${B}/implui/animsetwin.moc.cc \
	${B}/implui/animwidget.moc.cc \
	${B}/implui/animwin.moc.cc \
	${B}/implui/autoassignjointwin.moc.cc \
	${B}/implui/backgroundselect.moc.cc \
	${B}/implui/backgroundwin.moc.cc \
	${B}/implui/boolpanel.moc.cc \
	${B}/implui/boolwin.moc.cc \
	${B}/implui/contextinfluences.moc.cc \
	${B}/implui/contextname.moc.cc \
	${B}/implui/contextpanel.moc.cc \
	${B}/implui/contextposition.moc.cc \
	${B}/implui/contextprojection.moc.cc \
	${B}/implui/contextrotation.moc.cc \
	${B}/tools/cubetoolwidget.moc.cc \
	${B}/tools/cylindertoolwidget.moc.cc \
	${B}/tools/ellipsetoolwidget.moc.cc \
	${B}/depui/errorobj.moc.cc \
	${B}/implui/extrudewin.moc.cc \
	${B}/implui/groupclean.moc.cc \
	${B}/implui/groupwin.moc.cc \
	${B}/implui/helpwin.moc.cc \
	${B}/implui/jointwin.moc.cc \
	${B}/implui/painttexturewin.moc.cc \
	${B}/implui/pointwin.moc.cc \
	${B}/implui/projectionwin.moc.cc \
	${B}/implui/keyvaluewin.moc.cc \
	${B}/implui/licensewin.moc.cc \
	${B}/implui/mergewin.moc.cc \
	${B}/implui/metawin.moc.cc \
	${B}/implui/mview.moc.cc \
	${B}/depui/modelviewport.moc.cc \
	${B}/implui/newanim.moc.cc \
	${B}/implui/cal3dprompt.moc.cc \
	${B}/implui/iqeprompt.moc.cc \
	${B}/implui/md3prompt.moc.cc \
	${B}/implui/ms3dprompt.moc.cc \
	${B}/implui/objprompt.moc.cc \
	${B}/implui/smdprompt.moc.cc \
	${B}/implui/offsetwin.moc.cc \
	${B}/implui/pluginwin.moc.cc \
	${B}/tools/polytoolwidget.moc.cc \
	${B}/tools/projtoolwidget.moc.cc \
	${B}/tools/scaletoolwidget.moc.cc \
	${B}/tools/selectfacetoolwidget.moc.cc \
	${B}/implui/spherifywin.moc.cc \
	${B}/implui/statusbar.moc.cc \
	${B}/depui/textureframe.moc.cc \
	${B}/implui/texturecoord.moc.cc \
	${B}/depui/texwidget.moc.cc \
	${B}/implui/texwin.moc.cc \
	${B}/implui/transformwin.moc.cc \
	${B}/implui/valuewin.moc.cc \
	${B}/implui/viewportsettings.moc.cc \
	${B}/implui/viewpanel.moc.cc \
	${B}/implui/viewwin.moc.cc \

MM3D_MOC_OBJ= \
	${B}/implui/alignwin.moc.o \
	${B}/implui/aboutwin.moc.o \
	${B}/implui/animconvertwin.moc.o \
	${B}/implui/animeditwin.moc.o \
	${B}/implui/animexportwin.moc.o \
	${B}/implui/animsetwin.moc.o \
	${B}/implui/animwidget.moc.o \
	${B}/implui/animwin.moc.o \
	${B}/implui/autoassignjointwin.moc.o \
	${B}/implui/backgroundselect.moc.o \
	${B}/implui/backgroundwin.moc.o \
	${B}/implui/boolpanel.moc.o \
	${B}/implui/boolwin.moc.o \
	${B}/implui/contextgroup.moc.o \
	${B}/implui/contextinfluences.moc.o \
	${B}/implui/contextname.moc.o \
	${B}/implui/contextpanel.moc.o \
	${B}/implui/contextposition.moc.o \
	${B}/implui/contextprojection.moc.o \
	${B}/implui/contextrotation.moc.o \
	${B}/tools/cubetoolwidget.moc.o \
	${B}/tools/cylindertoolwidget.moc.o \
	${B}/tools/ellipsetoolwidget.moc.o \
	${B}/tools/rotatetoolwidget.moc.o \
	${B}/tools/torustoolwidget.moc.o \
	${B}/tools/toolwidget.moc.o \
	${B}/depui/errorobj.moc.o \
	${B}/implui/extrudewin.moc.o \
	${B}/implui/groupclean.moc.o \
	${B}/implui/groupwin.moc.o \
	${B}/implui/helpwin.moc.o \
	${B}/implui/jointwin.moc.o \
	${B}/implui/painttexturewin.moc.o \
	${B}/implui/pointwin.moc.o \
	${B}/implui/projectionwin.moc.o \
	${B}/implui/keyvaluewin.moc.o \
	${B}/implui/licensewin.moc.o \
	${B}/implui/mapdirection.moc.o \
	${B}/implui/mergewin.moc.o \
	${B}/implui/metawin.moc.o \
	${B}/implui/mview.moc.o \
	${B}/depui/modelviewport.moc.o \
	${B}/implui/newanim.moc.o \
	${B}/implui/cal3dprompt.moc.o \
	${B}/implui/iqeprompt.moc.o \
	${B}/implui/md3prompt.moc.o \
	${B}/implui/ms3dprompt.moc.o \
	${B}/implui/objprompt.moc.o \
	${B}/implui/smdprompt.moc.o \
	${B}/implui/offsetwin.moc.o \
	${B}/implui/pluginwin.moc.o \
	${B}/tools/polytoolwidget.moc.o \
	${B}/tools/projtoolwidget.moc.o \
	${B}/tools/scaletoolwidget.moc.o \
	${B}/tools/selectfacetoolwidget.moc.o \
	${B}/implui/spherifywin.moc.o \
	${B}/implui/statusbar.moc.o \
	${B}/depui/textureframe.moc.o \
	${B}/implui/texturecoord.moc.o \
	${B}/depui/texwidget.moc.o \
	${B}/implui/texwin.moc.o \
	${B}/implui/transformwin.moc.o \
	${B}/implui/valuewin.moc.o \
	${B}/implui/viewportsettings.moc.o \
	${B}/implui/viewpanel.moc.o \
	${B}/implui/viewwin.moc.o \

MM3D_OBJ= \
	${B}/src/3dm.o \
	${B}/mm3dcore/3dmprefs.o \
	${B}/implui/aboutwin.o \
	${B}/mm3dcore/align.o \
	${B}/commands/aligncmd.o \
	${B}/implui/alignwin.o \
	${B}/mm3dcore/allocstats.o \
	${B}/implui/animconvertwin.o \
	${B}/implui/animeditwin.o \
	${B}/implui/animexportwin.o \
	${B}/implui/animsetwin.o \
	${B}/implui/animwidget.o \
	${B}/implui/animwin.o \
	${B}/tools/atrfartool.o \
	${B}/tools/atrneartool.o \
	${B}/implui/autoassignjointwin.o \
	${B}/implui/backgroundselect.o \
	${B}/implui/backgroundwin.o \
	${B}/implui/boolpanel.o \
	${B}/implui/boolwin.o \
	${B}/implui/contextgroup.o \
	${B}/implui/contextinfluences.o \
	${B}/implui/contextname.o \
	${B}/implui/contextpanel.o \
	${B}/implui/contextposition.o \
	${B}/implui/contextprojection.o \
	${B}/implui/contextrotation.o \
	${B}/mm3dcore/contextwidget.o \
	${B}/mm3dcore/contextpanelobserver.o \
	${B}/tools/bgmovetool.o \
	${B}/tools/bgscaletool.o \
	${B}/mm3dcore/bounding.o \
	${B}/mm3dcore/cmdline.o \
	${B}/mm3dcore/cmdmgr.o \
	${B}/mm3dcore/command.o \
	${B}/commands/capcmd.o \
	${B}/commands/copycmd.o \
	${B}/tools/cubetool.o \
	${B}/tools/cubetoolwidget.o \
	${B}/tools/cylindertool.o \
	${B}/tools/cylindertoolwidget.o \
	${B}/mm3dcore/decal.o \
	${B}/mm3dcore/decalmgr.o \
	${B}/commands/deletecmd.o \
	${B}/commands/dupcmd.o \
	${B}/commands/edgedivcmd.o \
	${B}/commands/edgeturncmd.o \
	${B}/tools/ellipsetool.o \
	${B}/tools/ellipsetoolwidget.o \
	${B}/tools/extrudetool.o \
	${B}/depui/errorobj.o \
	${B}/commands/extrudecmd.o \
	${B}/implui/extrudewin.o \
	${B}/commands/faceoutcmd.o \
	${B}/commands/flattencmd.o \
	${B}/commands/flipcmd.o \
	${B}/implui/groupclean.o \
	${B}/implui/groupwin.o \
	${B}/implui/helpwin.o \
	${B}/commands/hidecmd.o \
	${B}/commands/invertcmd.o \
	${B}/commands/invnormalcmd.o \
	${B}/tools/jointtool.o \
	${B}/tools/pointtool.o \
	${B}/tools/projtool.o \
	${B}/implui/jointwin.o \
	${B}/implui/painttexturewin.o \
	${B}/implui/pointwin.o \
	${B}/implui/projectionwin.o \
	${B}/implui/keycfg.o \
	${B}/implui/keyvaluewin.o \
	${B}/implui/licensewin.o \
	${B}/mm3dcore/luaif.o \
	${B}/mm3dcore/luascript.o \
	${B}/commands/makefacecmd.o \
	${B}/implui/mapdirection.o \
	${B}/implui/mergewin.o \
	${B}/implui/metawin.o \
	${B}/tools/movetool.o \
	${B}/implui/msgqt.o \
	${B}/implui/mview.o \
	${B}/depui/modelviewport.o \
	${B}/commands/pastecmd.o \
	${B}/mm3dcore/pluginmgr.o \
	${B}/implui/newanim.o \
	${B}/implui/cal3dprompt.o \
	${B}/implui/iqeprompt.o \
	${B}/implui/md3prompt.o \
	${B}/implui/ms3dprompt.o \
	${B}/implui/objprompt.o \
	${B}/implui/smdprompt.o \
	${B}/implui/pluginwin.o \
	${B}/commands/offsetcmd.o \
	${B}/implui/offsetwin.o \
	${B}/tools/polytool.o \
	${B}/tools/polytoolwidget.o \
	${B}/tools/projtoolwidget.o \
	${B}/mm3dcore/prefparse.o \
	${B}/mm3dcore/prefs.o \
	${B}/implui/qtmain.o \
	${B}/implui/qttex.o \
	${B}/tools/rectangletool.o \
	${B}/qtui/resources.o \
	${B}/mm3dcore/rotatepoint.o \
	${B}/commands/rotatetexcmd.o \
	${B}/tools/rotatetool.o \
	${B}/tools/scaletool.o \
	${B}/tools/scaletoolwidget.o \
	${B}/tools/selectfacetoolwidget.o \
	${B}/mm3dcore/scriptif.o \
	${B}/tools/selectbonetool.o \
	${B}/tools/selectpointtool.o \
	${B}/tools/selectprojtool.o \
	${B}/tools/selectconnectedtool.o \
	${B}/tools/selectfacetool.o \
	${B}/tools/selectgrouptool.o \
	${B}/tools/selectvertextool.o \
	${B}/tools/sheartool.o \
	${B}/commands/selectfreecmd.o \
	${B}/commands/simplifycmd.o \
	${B}/commands/snapcmd.o \
	${B}/commands/spherifycmd.o \
	${B}/implui/spherifywin.o \
	${B}/implui/statusbar.o \
	${B}/src/stdcmds.o \
	${B}/src/stdfilters.o \
	${B}/src/stdtexfilters.o \
	${B}/src/stdtools.o \
	${B}/commands/subdividecmd.o \
	${B}/mm3dcore/sysconf.o \
	${B}/depui/textureframe.o \
	${B}/implui/texturecoord.o \
	${B}/mm3dcore/texturetest.o \
	${B}/depui/texwidget.o \
	${B}/implui/texwin.o \
	${B}/implui/transformwin.o \
	${B}/implui/transimp.o \
	${B}/libmm3d/translate.o \
	${B}/mm3dcore/tool.o \
	${B}/mm3dcore/toolbox.o \
	${B}/mm3dcore/toolpoly.o \
	${B}/tools/rotatetoolwidget.o \
	${B}/tools/torustool.o \
	${B}/tools/torustoolwidget.o \
	${B}/tools/toolwidget.o \
	${B}/commands/unweldcmd.o \
	${B}/implui/valuewin.o \
	${B}/tools/vertextool.o \
	${B}/tools/dragvertextool.o \
	${B}/implui/viewportsettings.o \
	${B}/implui/viewpanel.o \
	${B}/implui/viewwin.o \
	${B}/implui/viewwin_influences.o \
	${B}/commands/weldcmd.o 

QMFILES = \
	${B}/translations/mm3d_de.qm \
	${B}/translations/mm3d_fr.qm \
	${B}/translations/mm3d_sk.qm \
	${B}/translations/mm3d_ref.qm \
	${B}/translations/mm3d_bork.qm

MM3D_HTML = \
	${B}/doc/html/olh_detailsindex.html \
	${B}/doc/html/olh_vertexdetails.html \
	${B}/doc/html/olh_facedetails.html \
	${B}/doc/html/olh_meshdetails.html \
	${B}/doc/html/olh_normaldetails.html \
	${B}/doc/html/olh_groupdetails.html \
	${B}/doc/html/olh_materialdetails.html \
	${B}/doc/html/olh_texturecoorddetails.html \
	${B}/doc/html/olh_projectiondetails.html \
	${B}/doc/html/olh_jointdetails.html \
	${B}/doc/html/olh_pointdetails.html \
	${B}/doc/html/olh_animationdetails.html \
	${B}/doc/html/olh_backgroundimagedetails.html \
	${B}/doc/html/olh_alignwin.html \
	${B}/doc/html/olh_animconvertwin.html \
	${B}/doc/html/olh_animexportwin.html \
	${B}/doc/html/olh_animsetwin.html \
	${B}/doc/html/olh_animwin.html \
	${B}/doc/html/olh_autoassignjointwin.html \
	${B}/doc/html/olh_backgroundwin.html \
	${B}/doc/html/olh_boolwin.html \
	${B}/doc/html/olh_cmdline.html \
	${B}/doc/html/olh_commands.html \
	${B}/doc/html/olh_develop.html \
	${B}/doc/html/olh_quakemd2.html \
	${B}/doc/html/olh_quakemd3.html \
	${B}/doc/html/olh_cal3d.html \
	${B}/doc/html/olh_groupwin.html \
	${B}/doc/html/olh_index.html \
	${B}/doc/html/olh_influences.html \
	${B}/doc/html/olh_jointwin.html \
	${B}/doc/html/olh_license.html \
	${B}/doc/html/olh_mergewin.html \
	${B}/doc/html/olh_metawin.html \
	${B}/doc/html/olh_mm3dformat.html \
	${B}/doc/html/olh_cal3dprompt.html \
	${B}/doc/html/olh_ms3dprompt.html \
	${B}/doc/html/olh_objprompt.html \
	${B}/doc/html/olh_iqeprompt.html \
	${B}/doc/html/olh_quakemd3prompt.html \
	${B}/doc/html/olh_smdprompt.html \
	${B}/doc/html/olh_offsetwin.html \
	${B}/doc/html/olh_painttexturewin.html \
	${B}/doc/html/olh_pointwin.html \
	${B}/doc/html/olh_pluginwin.html \
	${B}/doc/html/olh_projectionwin.html \
	${B}/doc/html/olh_properties.html \
	${B}/doc/html/olh_spherifywin.html \
	${B}/doc/html/olh_texturecoordwin.html \
	${B}/doc/html/olh_texturewin.html \
	${B}/doc/html/olh_tips.html \
	${B}/doc/html/olh_tools.html \
	${B}/doc/html/olh_tutorial_index.html \
	${B}/doc/html/olh_transformwin.html \
	${B}/doc/html/olh_viewportsettings.html \
	${B}/doc/html/olh_whatsnew.html \
	${B}/doc/html/olh_mainwin.html

ifeq (${V},1)
echo_cmd=@:
Q=
else
echo_cmd=@echo
Q=@
endif

define DO_CC
$(echo_cmd) "CC $<"
$(Q)${CC} ${DEFS} -c $< -o $@ ${CCFLAGS}
endef

define DO_TOOLS_CC
$(echo_cmd) "TOOLS CC $<"
$(Q)${TOOLS_CC} -c $< -o $@ ${TOOLS_CCFLAGS}
endef

define DO_CXX
$(echo_cmd) "CXX $<"
$(Q)${CXX} ${DEFS} -c $< -o $@ ${CXXFLAGS}
endef

define DO_UIC
$(echo_cmd) "UIC $<"
$(Q)${UIC} $< -o $@
endef

define DO_MOC
$(echo_cmd) "MOC $<"
$(Q)${MOC} $< -o $@
endef

define DO_LRELEASE
$(echo_cmd) "LRELEASE $<"
$(Q)${LRELEASE} $< -qm $@
endef

define DO_HTML
$(echo_cmd) "HTML $<"
$(Q)${B_TOOLS}/util/hpagemake${BINEXT} $< > $@
endef

.PHONY: all makedirs mm3d_ui mm3d_moc mm3d qmfiles hpagemake docs install deploy installer clean

all: makedirs mm3d_ui mm3d_moc mm3d qmfiles hpagemake docs

# mingw.org's mingw32-make.exe uses Window's command processing and mkdir
makedirs:
ifdef MINGW32_MAKE
	@IF NOT EXIST "${BUILD}\${BUILDSUB}" ${MKDIR} "${BUILD}\${BUILDSUB}"
	@IF NOT EXIST "${BUILD}\${BUILDSUB}\src" ${MKDIR} "${BUILD}\${BUILDSUB}\src"
	@IF NOT EXIST "${BUILD}\${BUILDSUB}\depui" ${MKDIR} "${BUILD}\${BUILDSUB}\depui"
	@IF NOT EXIST "${BUILD}\${BUILDSUB}\implui" ${MKDIR} "${BUILD}\${BUILDSUB}\implui"
	@IF NOT EXIST "${BUILD}\${BUILDSUB}\qtui" ${MKDIR} "${BUILD}\${BUILDSUB}\qtui"
	@IF NOT EXIST "${BUILD}\${BUILDSUB}\tools" ${MKDIR} "${BUILD}\${BUILDSUB}\tools"
	@IF NOT EXIST "${BUILD}\${BUILDSUB}\libmm3d" ${MKDIR} "${BUILD}\${BUILDSUB}\libmm3d"
	@IF NOT EXIST "${BUILD}\${BUILDSUB}\mm3dcore" ${MKDIR} "${BUILD}\${BUILDSUB}\mm3dcore"
	@IF NOT EXIST "${BUILD}\${BUILDSUB}\commands" ${MKDIR} "${BUILD}\${BUILDSUB}\commands"
	@IF NOT EXIST "${BUILD}\${BUILDSUB}\translations" ${MKDIR} "${BUILD}\${BUILDSUB}\translations"
	@IF NOT EXIST "${BUILD}\${BUILDSUB}\doc" ${MKDIR} "${BUILD}\${BUILDSUB}\doc"
	@IF NOT EXIST "${BUILD}\${BUILDSUB}\doc\html" ${MKDIR} "${BUILD}\${BUILDSUB}\doc\html"
	@IF NOT EXIST "${BUILD}\${BUILDSUB_TOOLS}" ${MKDIR} "${BUILD}\${BUILDSUB_TOOLS}"
	@IF NOT EXIST "${BUILD}\${BUILDSUB_TOOLS}\util" ${MKDIR} "${BUILD}\${BUILDSUB_TOOLS}\util"
else
	@${MKDIR} "${B}"
	@${MKDIR} "${B}/src"
	@${MKDIR} "${B}/depui"
	@${MKDIR} "${B}/implui"
	@${MKDIR} "${B}/qtui"
	@${MKDIR} "${B}/tools"
	@${MKDIR} "${B}/libmm3d"
	@${MKDIR} "${B}/mm3dcore"
	@${MKDIR} "${B}/commands"
	@${MKDIR} "${B}/translations"
	@${MKDIR} "${B}/doc"
	@${MKDIR} "${B}/doc/html"
	@${MKDIR} "${B_TOOLS}"
	@${MKDIR} "${B_TOOLS}/util"
endif

mm3d_ui: ${MM3D_UI}

mm3d_moc: ${MM3D_MOC}

qmfiles: ${QMFILES}

${B_TOOLS}/util/hpagemake${BINEXT}: ${B_TOOLS}/util/hpagemake.o
	$(Q)${TOOLS_CC} ${TOOLS_CCFLAGS} -o ${B_TOOLS}/util/hpagemake${BINEXT} ${B_TOOLS}/util/hpagemake.o

hpagemake: ${B_TOOLS}/util/hpagemake${BINEXT}

docs: hpagemake ${MM3D_HTML}

$(BIN)/mm3d${BINEXT}: ${MM3D_MOC_OBJ} ${LIB_OBJ} ${MM3D_OBJ}
	$(echo_cmd) "LINKING $(BIN)/mm3d${BINEXT}"
ifdef MINGW
ifdef MINGW32_MAKE
	$(Q)${WINDRES} --preprocessor="$(CC) -E -xc-header -DRC_INVOKED" src/win_resource.rc ${B}/src/win_resource.o
else
	$(Q)${WINDRES} src/win_resource.rc ${B}/src/win_resource.o
endif
	$(Q)${CXX} ${CXXFLAGS} ${DEFS} -o $(BIN)/mm3d${BINEXT} ${MM3D_OBJ} ${MM3D_MOC_OBJ} ${LIB_OBJ} ${B}/src/win_resource.o ${LINK}
else
	$(Q)${CXX} ${CXXFLAGS} ${DEFS} -o $(BIN)/mm3d${BINEXT} ${MM3D_OBJ} ${MM3D_MOC_OBJ} ${LIB_OBJ} ${LINK}
endif
ifdef STRIP
	$(echo_cmd) "STRIP $(BIN)/mm3d${BINEXT}"
	$(Q)$(STRIP) $(BIN)/mm3d${BINEXT}
endif

mm3d: $(BIN)/mm3d${BINEXT}

# make install doesn't work for mingw32-make.exe because it's case insenitive and autotools requires INSTALL file.
install: deploy

deploy: all
ifdef MINGW
ifdef MINGW32_MAKE
	@IF NOT EXIST "${BUILD}\${BUILDSUB}\install" ${MKDIR} "${BUILD}\${BUILDSUB}\install"
	@IF NOT EXIST "${BUILD}\${BUILDSUB}\install\doc" ${MKDIR} "${BUILD}\${BUILDSUB}\install\doc"
	@IF NOT EXIST "${BUILD}\${BUILDSUB}\install\doc\html" ${MKDIR} "${BUILD}\${BUILDSUB}\install\doc\html"
	@IF NOT EXIST "${BUILD}\${BUILDSUB}\install\doc\html\olh_images" ${MKDIR} "${BUILD}\${BUILDSUB}\install\doc\html\olh_images\screencaps"
	@IF NOT EXIST "${BUILD}\${BUILDSUB}\install\doc\html\olh_images\screencaps" ${MKDIR} "${BUILD}\${BUILDSUB}\install\doc\html\olh_images"
	@IF NOT EXIST "${BUILD}\${BUILDSUB}\install\doc\html\olh_images\tools" ${MKDIR} "${BUILD}\${BUILDSUB}\install\doc\html\olh_images\tools"
	@IF NOT EXIST "${BUILD}\${BUILDSUB}\install\translations" ${MKDIR} "${BUILD}\${BUILDSUB}\install\translations"
	@IF NOT EXIST "${BUILD}\${BUILDSUB}\install\plugins" ${MKDIR} "${BUILD}\${BUILDSUB}\install\plugins"
	@IF NOT EXIST "${BUILD}\${BUILDSUB}\install\plugins\1.3" ${MKDIR} "${BUILD}\${BUILDSUB}\install\plugins\1.3"
	@copy "$(BUILD)\$(BUILDSUB)\mm3d${BINEXT}" "$(BUILD)\$(BUILDSUB)\install"
	@copy "$(BUILD)\$(BUILDSUB)\doc\html\*.html" "$(BUILD)\$(BUILDSUB)\install\doc\html"
	@copy "doc\html\olh_images\screencaps\*.png" "$(BUILD)\$(BUILDSUB)\install\doc\html\olh_images\screencaps"
	@copy "doc\html\olh_images\tools\*.png" "$(BUILD)\$(BUILDSUB)\install\doc\html\olh_images\tools"
	@copy "doc\html\olh_images\tools\*.jpg" "$(BUILD)\$(BUILDSUB)\install\doc\html\olh_images\tools"
	@copy "$(BUILD)\$(BUILDSUB)\translations\*.qm" "$(BUILD)\$(BUILDSUB)\install\translations"
	@$(WINDEPLOYQT) "$(BUILD)\$(BUILDSUB)\install"
else
	@$(MKDIR) "$(B)/install"
	@$(MKDIR) "$(B)/install/doc/html"
	@$(MKDIR) "$(B)/install/doc/html/olh_images/screencaps"
	@$(MKDIR) "$(B)/install/doc/html/olh_images/tools"
	@$(MKDIR) "$(B)/install/translations"
	@$(MKDIR) "$(B)/install/plugins/1.3"
	@cp "$(B)/mm3d${BINEXT}" "$(B)/install"
	@cp $(QMFILES) "$(B)/install/translations"
	@cp $(MM3D_HTML) "$(B)/install/doc/html"
	@cp doc/html/olh_images/screencaps/*.png "$(B)/install/doc/html/olh_images/screencaps"
	@cp doc/html/olh_images/tools/*.png "$(B)/install/doc/html/olh_images/tools"
	@cp doc/html/olh_images/tools/*.jpg "$(B)/install/doc/html/olh_images/tools"
	@$(WINDEPLOYQT) "$(B)/install"
endif
else
	$(INSTALL) -d "$(PREFIX)/bin"
	$(INSTALL) -m 0755 $(BIN)/mm3d${BINEXT} "$(PREFIX)/bin/mm3d"
	$(INSTALL) -d "$(PREFIX)/share/mm3d/translations/"
	${INSTALL} -m 0644 $(QMFILES) "$(PREFIX)/share/mm3d/translations/"
	$(INSTALL) -d "$(PREFIX)/share/applications/"
	$(INSTALL) -d "$(PREFIX)/share/metainfo/"
	$(INSTALL) -d "$(PREFIX)/share/mime/packages/"
	$(INSTALL) -d "$(PREFIX)/share/icons/hicolor/128x128/apps/"
	$(INSTALL) -d "$(PREFIX)/share/icons/hicolor/64x64/apps/"
	$(INSTALL) -d "$(PREFIX)/share/icons/hicolor/32x32/apps/"
	$(INSTALL) -d "$(PREFIX)/share/icons/hicolor/16x16/apps/"
	${INSTALL} -m 0644 desktop/moe.clover.mm3d.desktop "$(PREFIX)/share/applications/"
	${INSTALL} -m 0644 desktop/moe.clover.mm3d.metainfo.xml "$(PREFIX)/share/metainfo/"
	${INSTALL} -m 0644 desktop/moe.clover.mm3d.mm3dmodel.xml "$(PREFIX)/share/mime/packages/"
	${INSTALL} -m 0644 desktop/moe.clover.mm3d.png "$(PREFIX)/share/icons/hicolor/128x128/apps/moe.clover.mm3d.png"
	${INSTALL} -m 0644 desktop/moe.clover.mm3d-64.png "$(PREFIX)/share/icons/hicolor/64x64/apps/moe.clover.mm3d.png"
	${INSTALL} -m 0644 desktop/moe.clover.mm3d-32.png "$(PREFIX)/share/icons/hicolor/32x32/apps/moe.clover.mm3d.png"
	${INSTALL} -m 0644 desktop/moe.clover.mm3d-16.png "$(PREFIX)/share/icons/hicolor/16x16/apps/moe.clover.mm3d.png"
	$(INSTALL) -d "$(PREFIX)/share/man/man1/"
	${INSTALL} -m 0644 man/mm3d.1 "$(PREFIX)/share/man/man1/"
	$(INSTALL) -d "$(PREFIX)/share/mm3d/plugins/1.3"
	$(INSTALL) -d "$(PREFIX)/share/doc/mm3d/html/"
	$(INSTALL) -d "$(PREFIX)/share/doc/mm3d/html/olh_images/screencaps/"
	$(INSTALL) -d "$(PREFIX)/share/doc/mm3d/html/olh_images/tools/"
	${INSTALL} -m 0644 $(MM3D_HTML) "$(PREFIX)/share/doc/mm3d/html/"
	${INSTALL} -m 0644 doc/html/olh_images/screencaps/*.png "$(PREFIX)/share/doc/mm3d/html/olh_images/screencaps/"
	${INSTALL} -m 0644 doc/html/olh_images/tools/*.png "$(PREFIX)/share/doc/mm3d/html/olh_images/tools/"
	${INSTALL} -m 0644 doc/html/olh_images/tools/*.jpg "$(PREFIX)/share/doc/mm3d/html/olh_images/tools/"
endif

installer: deploy
ifdef MINGW
	makensis mm3d-win32-installer.nsi
endif

#
# macOS AppBundle
#
MAC_APP = $(B)/Maverick Model 3D.app

define INFOPLIST
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>UTExportedTypeDeclarations</key>
<array>
    <dict>
        <key>UTTypeConformsTo</key>
        <array>
            <string>public.data</string>
        </array>
        <key>UTTypeIdentifier</key>
        <string>moe.clover.mm3dmodel</string>
        <key>UTTypeDescription</key>
        <string>MM3D model</string>
        <key>UTTypeIconFile</key>
        <string>mm3d</string>
        <key>UTTypeReferenceURL</key>
        <string>https://clover.moe/mm3d_manual/olh_mm3dformat.html</string>
        <key>UTTypeTagSpecification</key>
        <dict>
            <key>public.filename-extension</key>
            <string>mm3d</string>
        </dict>
    </dict>
</array>
<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeName</key>
        <string>MM3D model</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>moe.clover.mm3dmodel</string>
        </array>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>LSHandlerRank</key>
        <string>Owner</string>
    </dict>
    <dict>
        <key>CFBundleTypeName</key>
        <string>Quake 2 model</string>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>md2</string>
        </array>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
    </dict>
    <dict>
        <key>CFBundleTypeName</key>
        <string>Quake 3 model</string>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>md3</string>
        </array>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
    </dict>
    <dict>
        <key>CFBundleTypeName</key>
        <string>Milkshape 3D model</string>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>ms3d</string>
        </array>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
    </dict>
    <dict>
        <key>CFBundleTypeName</key>
        <string>Wavefront OBJ model</string>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>obj</string>
        </array>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
    </dict>
</array>
<key>CFBundleExecutable</key>
<string>mm3d</string>
<key>CFBundleIconFile</key>
<string>mm3d</string>
<key>CFBundleIdentifier</key>
<string>moe.clover.mm3d</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>Maverick Model 3D</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.3.15</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.3.15</string>
<key>CGDisableCoalescedUpdates</key>
<true/>
<key>LSMinimumSystemVersion</key>
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2004-2008 Kevin Worcester, Copyright © 2009-2024 Zack Middleton.</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>
endef
export INFOPLIST

define LOCVERSIONPLIST
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>LprojCompatibleVersion</key>
    <string>123</string>
    <key>LprojLocale</key>
    <string>XXLANGXX</string>
    <key>LprojRevisionLevel</key>
    <string>1</string>
    <key>LprojVersion</key>
    <string>123</string>
</dict>
</plist>
endef
export LOCVERSIONPLIST

appbundle: all
	${INSTALL} -d      "$(MAC_APP)/Contents/MacOS/"
	${INSTALL} -d      "$(MAC_APP)/Contents/Resources/"
	${INSTALL} -d      "$(MAC_APP)/Contents/PlugIns/mm3d/1.3"
	${INSTALL} -d      "$(MAC_APP)/Contents/SharedSupport/mm3d/doc/html/olh_images/screencaps/"
	${INSTALL} -d      "$(MAC_APP)/Contents/SharedSupport/mm3d/doc/html/olh_images/tools/"
	${INSTALL} -d      "$(MAC_APP)/Contents/SharedSupport/mm3d/translations/"
	${INSTALL} -m 0755 "$(BIN)/mm3d${BINEXT}" "$(MAC_APP)/Contents/MacOS/mm3d"
	${INSTALL} -m 0644 mm3d.icns "$(MAC_APP)/Contents/Resources/mm3d.icns"
	${INSTALL} -m 0644 $(MM3D_HTML) "$(MAC_APP)/Contents/SharedSupport/mm3d/doc/html/"
	${INSTALL} -m 0644 doc/html/olh_images/screencaps/*.png "$(MAC_APP)/Contents/SharedSupport/mm3d/doc/html/olh_images/screencaps/"
	${INSTALL} -m 0644 doc/html/olh_images/tools/*.png "$(MAC_APP)/Contents/SharedSupport/mm3d/doc/html/olh_images/tools/"
	${INSTALL} -m 0644 doc/html/olh_images/tools/*.jpg "$(MAC_APP)/Contents/SharedSupport/mm3d/doc/html/olh_images/tools/"
	${INSTALL} -m 0644 $(QMFILES) "$(MAC_APP)/Contents/SharedSupport/mm3d/translations/"
	echo "APPL????" > "$(MAC_APP)/Contents/PkgInfo"
	@echo "$$INFOPLIST" > "$(MAC_APP)/Contents/Info.plist"
	@echo "Wrote \"$(MAC_APP)/Contents/Info.plist\""
	$(MACDEPLOYQT) "$(MAC_APP)"
	@# Add translations of Qt itself
	$(LCONVERT) -o "$(MAC_APP)/Contents/SharedSupport/mm3d/translations/qt_de.qm" "$(QT_TRANSLATIONS_DIR)/qtbase_de.qm"
	$(LCONVERT) -o "$(MAC_APP)/Contents/SharedSupport/mm3d/translations/qt_fr.qm" "$(QT_TRANSLATIONS_DIR)/qtbase_fr.qm"
	$(LCONVERT) -o "$(MAC_APP)/Contents/SharedSupport/mm3d/translations/qt_sk.qm" "$(QT_TRANSLATIONS_DIR)/qtbase_sk.qm"
	@# Tell macOS to translate builtin dialogs (i.e., file chooser)
	${INSTALL} -d      "$(MAC_APP)/Contents/Resources/en.lproj"
	${INSTALL} -d      "$(MAC_APP)/Contents/Resources/de.lproj"
	${INSTALL} -d      "$(MAC_APP)/Contents/Resources/fr.lproj"
	${INSTALL} -d      "$(MAC_APP)/Contents/Resources/sk.lproj"
	@echo "$$LOCVERSIONPLIST" | sed "s/XXLANGXX/en/g" > "$(MAC_APP)/Contents/Resources/en.lproj/locversion.plist"
	@echo "$$LOCVERSIONPLIST" | sed "s/XXLANGXX/de/g" > "$(MAC_APP)/Contents/Resources/de.lproj/locversion.plist"
	@echo "$$LOCVERSIONPLIST" | sed "s/XXLANGXX/fr/g" > "$(MAC_APP)/Contents/Resources/fr.lproj/locversion.plist"
	@echo "$$LOCVERSIONPLIST" | sed "s/XXLANGXX/sk/g" > "$(MAC_APP)/Contents/Resources/sk.lproj/locversion.plist"



${B}/%.o: src/%.c
	$(DO_CC)

${B_TOOLS}/util/%.o: util/%.c
	$(DO_TOOLS_CC)

${B}/%.o: src/%.cc
	$(DO_CXX)

${B}/src/%.o: src/%.cc
	$(DO_CXX)

${B}/qtui/%.base.h: src/qtui/%.ui
	$(DO_UIC)

${B}/implui/%.moc.cc: src/implui/%.h
	$(DO_MOC)

${B}/tools/%.moc.cc: src/tools/%.h
	$(DO_MOC)

${B}/depui/%.moc.cc: src/depui/%.h
	$(DO_MOC)

${B}/%.moc.o: ${B}/%.moc.cc
	$(DO_CXX)

${B}/qtui/resources.cpp: src/qtui/resources.qrc src/qtui/images/zoomin.xpm src/qtui/images/zoomout.xpm
	$(echo_cmd) "RCC $<"
	$(Q)${RCC} --name qtuiResources $< -o $@

${B}/qtui/resources.o: ${B}/qtui/resources.cpp
	$(DO_CXX)

${B}/translations/%.qm: translations/%.ts
	$(DO_LRELEASE)

${B}/doc/html/%.html: doc/html/%.page doc/html/%.htm doc/html/template.htm ${B_TOOLS}/util/hpagemake${BINEXT}
	$(DO_HTML)

# Include build dependencies (.d files).
OBJ=${LIB_OBJ} ${MM3D_OBJ} ${MM3D_MOC_OBJ}
OBJ_D_FILES=$(filter %.d,$(OBJ:%.o=%.d))
-include $(OBJ_D_FILES)

clean:
	$(Q)rm -f ${OBJ_D_FILES}
	$(Q)rm -f ${LIB_OBJ}
	$(Q)rm -f ${MM3D_UI}
	$(Q)rm -f ${MM3D_MOC}
	$(Q)rm -f ${QMFILES}
	$(Q)rm -f ${MM3D_OBJ}
	$(Q)rm -f ${MM3D_MOC_OBJ}
	$(Q)rm -f ${MM3D_HTML}
	$(Q)rm -f $(BIN)/mm3d${BINEXT}

