## This file is included in make and all sub-makes

# Use the default mkoctfile if none is specified.
MKOCTFILE = mkoctfile

# Special flags for compiling functions which depend on Xlib.
XFLAGS=-L/usr/X11R6/lib -lX11

# Installation command
INSTALLOCT = $(TOP)/octinst.sh

## Complicated conditionals to determine if we need to call octinfo.sh
## * we need to call octinfo.sh if we need octinfo
## * we need octinfo if we need ver or if we need path and it isn't defined
## * we need ver if we are compiling or installing and it isn't defined
## * we need path if we are installing and it isn't defined
## * we are compiling if MAKECMDGOALS is empty, or if it contains all
## * we are installing if MAKECMDGOALS contains install
ifeq (install,$(findstring install,$(MAKECMDGOALS)))
  installing=1
  ifndef path
    need_octinfo=1
  endif
  ifndef ver
    need_ver=1
  endif
endif
ifeq (all,$(findstring all,$(MAKECMDGOALS)))
  compiling=1
endif
ifeq (,$(MAKECMDGOALS))
  compiling=1
endif
ifdef compiling
  ifndef ver
    need_ver=1
  endif
endif
ifdef need_ver
  need_octinfo = 1
endif

ifdef need_octinfo
  ifndef octinfo
    export octinfo = $(shell $(TOP)/octinfo.sh $(MKOCTFILE))
  endif
endif

ifdef need_ver
  verparts = $(subst ., ,$(word 1,$(octinfo)))
  export ver = $(word 1,$(verparts))$(word 2,$(verparts))
endif

# Installing, so need MPATH, OPATH, XPATH and ver
ifdef installing
  # If path is defined, then use it as the MPATH and OPATH
  ifdef path
    MPATH=$(path)
    OPATH=$(path)/oct
    XPATH=$(path)/bin
  else
    MPATH=$(word 2,$(octinfo))
    OPATH=$(word 3,$(octinfo))
    XPATH=$(word 4,$(octinfo))
  endif

  # If opath is defined, then use it as the OPATH
  ifdef opath
    OPATH=$(opath)
  endif

  # If xpath is defined, then use it as the XPATH
  ifdef xpath
    XPATH=$(xpath)
  endif
endif
