-
Notifications
You must be signed in to change notification settings - Fork 9
/
build.sh
executable file
·181 lines (127 loc) · 6.33 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/usr/bin/env bash
# This is the GCC build script for the Maya example Python C extension.
# usage: build.sh [debug|release]
StartTime=`date +%T`;
echo "Build script started executing at ${StartTime}...";
# Process command line arguments
BuildType=$1;
if [ "$BuildType" == "" ]; then
BuildType="release";
fi;
# Define colours to be used for terminal output messages
RED='\033[0;31m';
GREEN='\033[0;32m';
NC='\033[0m'; # No Color
# If cleaning builds, just delete build artifacts and exit immediately
if [ "$BuildType" == "clean" ]; then
echo "Cleaning build from directory: $BuildDir. Files will be deleted!";
read -p "Continue? (Y/N)" ConfirmCleanBuild;
if [ $ConfirmCleanBuild == [Yy] ]; then
echo "Removing files in: $BuildDir...";
rm -rf $BuildDir;
fi;
exit 0;
fi;
# Create a build directory to store artifacts
BuildDir="${PWD}/linuxbuild";
echo "Building in directory: $BuildDir";
if [ ! -d "$BuildDir" ]; then
mkdir -p "$BuildDir";
fi;
# Set up globals
MayaRootDir="/usr/bin/autodesk/maya2018";
MayaIncludeDir="$MayaRootDir/include";
MayaLibraryDir="$MayaRootDir/lib";
ProjectName="maya_python_c_ext";
MayaPluginEntryPoint="${PWD}/${ProjectName}_plugin_main.cpp";
PythonModuleEntryPoint="${PWD}/${ProjectName}_py_mod_main.cpp";
# Setup all the compiler flags
CommonCompilerFlags="-DBits64_ -m64 -DUNIX -D_BOOL -DLINUX -DFUNCPROTO -D_GNU_SOURCE -DLINUX_64 -fPIC -fno-strict-aliasing -DREQUIRE_IOSTREAM -Wall -std=c++11 -Wno-multichar -Wno-comment -Wno-sign-compare -funsigned-char -pthread -Wno-deprecated -Wno-reorder -ftemplate-depth-25 -fno-gnu-keywords";
# Add the include directories for header files
CommonCompilerFlags="${CommonCompilerFlags} -I${MayaIncludeDir} -I${MayaIncludeDir}/python2.7";
CommonCompilerFlagsDebug="-ggdb -O0 ${CommonCompilerFlags}";
CommonCompilerFlagsRelease="-O3 ${CommonCompilerFlags}";
MayaPluginIntermediateObject="${BuildDir}/${ProjectName}_plugin_main.o";
PythonModuleIntermediateObject="${BuildDir}/${ProjectName}_py_mod_main.o";
MayaPluginCompilerFlagsDebug="${CommonCompilerFlagsDebug} -c ${MayaPluginEntryPoint} -o ${MayaPluginIntermediateObject}";
MayaPluginCompilerFlagsRelease="${CommonCompilerFlagsRelease} -c ${MayaPluginEntryPoint} -o ${MayaPluginIntermediateObject}";
PythonModuleCompilerFlagsDebug="${CommonCompilerFlagsDebug} -c ${PythonModuleEntryPoint} -o ${PythonModuleIntermediateObject}";
PythonModuleCompilerFlagsRelease="${CommonCompilerFlagsRelease} -c ${PythonModuleEntryPoint} -o ${PythonModuleIntermediateObject}";
# As per the Maya official Makefile:
# -Bsymbolic binds references to global symbols within the library.
# This avoids symbol clashes in other shared libraries but forces
# the linking of all required libraries.
CommonLinkerFlags="-Bsymbolic -shared -lm -ldl -lstdc++";
# Add all the Maya libraries to link against
CommonLinkerFlags="${CommonLinkerFlags} ${MayaLibraryDir}/libOpenMaya.so ${MayaLibraryDir}/libOpenMayaAnim.so ${MayaLibraryDir}/libOpenMayaFX.so ${MayaLibraryDir}/libOpenMayaRender.so ${MayaLibraryDir}/libOpenMayaUI.so ${MayaLibraryDir}/libFoundation.so ${MayaLibraryDir}/libclew.so ${MayaLibraryDir}/libImage.so ${MayaLibraryDir}/libIMFbase.so";
CommonLinkerFlagsDebug="${CommonLinkerFlags} -ggdb -O0";
CommonLinkerFlagsRelease="${CommonLinkerFlags} -O3";
MayaPluginExtension="so";
PythonModuleExtension="${MayaPluginExtension}";
MayaPluginLinkerFlagsCommon="-o ${BuildDir}/${ProjectName}_plugin.${MayaPluginExtension} ${MayaPluginIntermediateObject}";
PythonModuleLinkerFlagsCommon="-o ${BuildDir}/${ProjectName}.${PythonModuleExtension} ${PythonModuleIntermediateObject}";
MayaPluginLinkerFlagsRelease="${CommonLinkerFlagsRelease} ${MayaPluginLinkerFlagsCommon}";
MayaPluginLinkerFlagsDebug="${CommonLinkerFlagsDebug} ${MayaPluginLinkerFlagsCommon}";
PythonModuleLinkerFlagsRelease="${CommonLinkerFlagsRelease} ${PythonModuleLinkerFlagsCommon}";
PythonModuleLinkerFlagsDebug="${CommonLinkerFlagsDebug} ${PythonModuleLinkerFlagsCommon}";
if [ "$BuildType" == "debug" ]; then
echo "Building in debug mode...";
MayaPluginCompilerFlags="${MayaPluginCompilerFlagsDebug}";
MayaPluginLinkerFlags="${MayaPluginLinkerFlagsDebug}";
PythonModuleCompilerFlags="${PythonModuleCompilerFlagsDebug}";
PythonModuleLinkerFlags="${PythonModuleLinkerFlagsDebug}";
else
echo "Building in release mode...";
MayaPluginCompilerFlags="${MayaPluginCompilerFlagsRelease}";
MayaPluginLinkerFlags="${MayaPluginLinkerFlagsRelease}";
PythonModuleCompilerFlags="${PythonModuleCompilerFlagsRelease}";
PythonModuleLinkerFlags="${PythonModuleLinkerFlagsRelease}";
fi;
# Now build the standalone Python module first
echo "Compiling Python module (command follows)...";
echo "g++ ${PythonModuleCompilerFlags}";
echo "";
g++ ${PythonModuleCompilerFlags};
if [ $? -ne 0 ]; then
echo -e "${RED}***************************************${NC}";
echo -e "${RED}* !!! An error occurred!!! *${NC}";
echo -e "${RED}***************************************${NC}";
exit 1;
fi;
echo "Linking Python module (command follows)...";
echo "g++ ${PythonModuleLinkerFlags}";
echo "";
g++ -v ${PythonModuleLinkerFlags};
if [ $? -ne 0 ]; then
echo -e "${RED}***************************************${NC}";
echo -e "${RED}* !!! An error occurred!!! *${NC}";
echo -e "${RED}***************************************${NC}";
exit 2;
fi;
# Now build the Maya plugin
echo "Compiling Maya plugin (command follows)...";
echo "g++ ${MayaPluginCompilerFlags}";
echo "";
g++ ${MayaPluginCompilerFlags};
if [ $? -ne 0 ]; then
echo -e "${RED}***************************************${NC}";
echo -e "${RED}* !!! An error occurred!!! *${NC}";
echo -e "${RED}***************************************${NC}";
exit 3;
fi;
echo "Linking (command follows)...";
echo "g++ ${MayaPluginLinkerFlags}";
echo "";
g++ -v ${MayaPluginLinkerFlags};
if [ $? -ne 0 ]; then
echo -e "${RED}***************************************${NC}";
echo -e "${RED}* !!! An error occurred!!! *${NC}";
echo -e "${RED}***************************************${NC}";
exit 4;
fi;
echo -e "${GREEN}***************************************${NC}";
echo -e "${GREEN}* Build completed successfully! *${NC}";
echo -e "${GREEN}***************************************${NC}";
EndTime=`date +%T`;
echo "Build script finished execution at ${EndTime}.";
exit 0;