#!/bin/bash # Shave and a Haircut # (c) 2019 Epic Games # US Patent 6720962 # Returns six words, separated by spaces: raw normal major minor release dir # # 'raw' is the compact version used in MAYA_API_VERSION (e.g. "201500" prior # to Maya 2018, "20180000" from Maya 2018 onward) # # 'normal' is the version number by which Maya is known. E.g. "2015" # Although there may be multiple releases of Maya within a year (e.g. Maya 2015 # SP1, Maya 2015 Extension 1) they are normally all binary compatible and will # have the same 'normal' version number (e.g. "2015"). However, there are # occasional exceptions. For example two binary incompatible versions of Maya # 2016 were released: Maya 2016 ('normal' value "2016") and Maya 2016 Extension # 2 ('normal' value "2016.5"). # # 'major' is the major version number # # 'minor' is the minor version number. Usually this is "0" except in those cases # where multiple versions of Maya were made in the same year. For example, for # Maya 2016.5 this will contain "5". # # 'release' is the incremental release number within a version of Maya. For # example, if the 'raw' version is "201507" then the 'release' will be "7". # From Maya 2018 onward, the release number is 4 digits long, so a 'raw' # version of "20180123" would give a 'release' of "123". # # 'dir' is the version number as it appears in Maya's install path. On MacOS # and Windows this will be the same as the 'normal' version number but on Linux # some versions of Maya include a '-x64' suffix in their path # (e.g. "2015-x64"). # # From a Makefile these can easily be accessed as follows: # # versionInfo := $(shell getMayaAPIVersion.sh) # raw := $(word 1,$(versionInfo)) # normal := $(word 2,$(versionInfo)) # major := $(word 3,$(versionInfo)) # minor := $(word 4,$(versionInfo)) # release := $(word 5,$(versionInfo)) # dir := $(word 6,$(versionInfo)) # # From a csh or tcsh script: # # set versionInfo = `getMayaAPIVersion.sh` # set raw = ${versionInfo[1]} # set normal = ${versionInfo[2]} # set major = ${versionInfo[3]} # set minor = ${versionInfo[4]} # set release = ${versionInfo[5]} # set dir = ${versionInfo[6]} # # From a Bourne shell or bash script: # # versionInfo=(`getMayaAPIVersion.sh`) # raw=${versionInfo[0]} # normal=${versionInfo[1]} # major=${versionInfo[2]} # minor=${versionInfo[3]} # release=${versionInfo[4]} # dir=${versionInfo[5]} # if [ "${MAYA_LOCATION}" = "" ]; then echo "getMayaVersion:error: MAYA_LOCATION not defined." >&2 exit 1 fi if [ ! -d ${MAYA_LOCATION} ]; then echo "getMayaVersion:error: MAYA_LOCATION contains '${MAYA_LOCATION}', which does not exist." >&2 exit 2; fi versionFile=${MAYA_LOCATION}/include/maya/MTypes.h # Prior to Maya 2016, the API 'includes' directory was inside the 'devkit' # directory. Now it's at the same level as 'devkit', like Linux. # if [ "`uname -s`" == "Darwin" ]; then if [ ! -r ${versionFile} ]; then versionFile=${MAYA_LOCATION}/devkit/include/maya/MTypes.h fi fi if [ ! -r ${versionFile} ]; then echo "getMayaVersion:error: File '${versionFile}' does not exist." >&2 exit 4 fi compact=`grep '^[ \t]*\#define[ \t]*MAYA_API_VERSION' ${versionFile} | sed 's/^[^0-9]*//'` major=`echo ${compact} | sed 's/\(.*\)[0-9][0-9]$/\1/'` # From Maya 2018 onward the API version number is 8 digits long. if [ ${major} -gt 2017 ]; then major=`echo ${compact} | sed 's/\(.*\)[0-9][0-9][0-9][0-9]$/\1/'` release=`echo ${compact} | sed 's/.*\([0-9][0-9][0-9][0-9]\)$/\1/'` else release=`echo ${compact} | sed 's/.*\([0-9][0-9]\)$/\1/'` fi # Strip leading zeroes from the release number. release=`echo ${release} | sed 's/^0*//'` # If the release string is empty, set it to zero. if [ "${release}" == "" ]; then release=0 fi combined=${major} minor=0 # Special handling for Maya 2013.5 & 2016.5 if [ \( ${major} -eq 2013 -o ${major} -eq 2016 \) -a ${release} -ge 50 ]; then combined=${major}.5 minor=5 fi if `echo ${MAYA_LOCATION} | grep -q '[-]x64'`; then dir=${combined}-x64 else dir=${combined} fi echo ${compact} ${combined} ${major} ${minor} ${release} ${dir}