Tizen 2.0 Release
[sdk/ide/websimulator-eplugin.git] / package / build.linux
1 #!/bin/bash -x
2
3 build_path=${SRCDIR}/build_result
4
5 __set_parameter()
6 {
7         build_id=${package_name}
8         build_type=N
9         build_result_directory=${build_type}.${build_id}
10         build_result_path="$build_path/$build_result_directory"
11         architecture=x86
12         ide_root_path_name=ide
13
14         case ${TARGET_OS} in
15                 ubuntu-32|ubuntu-64)
16                         archive_platform_name=linux
17                         windowing=gtk
18                         ;;
19                 windows-32|windows-64)
20                         archive_platform_name=win32
21                         windowing=win32
22                         ;;
23         macos-64)
24             archive_platform_name=macosx
25             windowing=cocoa
26             ;;
27                 *)
28                         echo "${TARGET_OS} is not support yet."
29                         ;;
30         esac
31
32         result_archive_file=${build_id}-${archive_platform_name}.${windowing}.${architecture}.zip
33 }
34
35 __set_build_parameter()
36 {
37         case ${TARGET_OS} in
38                 ubuntu-32|ubuntu-64)
39                         reference_ide_path=${ROOTDIR}/indigo-pde/eclipse
40                         ;;
41                 windows-32|windows-64)
42                         reference_ide_path=${ROOTDIR}/indigo-winpde/eclipse
43                         ;;
44         macos-64)
45             reference_ide_path=${ROOTDIR}/indigo-macpde/eclipse
46             ;;
47                 *)
48                         echo "${TARGET_OS} is not support yet."
49                         ;;
50         esac
51 }
52
53 __set_install_parameter()
54 {
55         INSTALL_DIR=${SRCDIR}/package/${package_name}.package.${platform}/data
56 }
57
58 __clean_build_environment()
59 {
60         if [ -d $build_path ]
61         then
62                 echo "Build result directory : [$build_path]"
63         else
64                 echo "Make build result directory [$build_path]"
65                 mkdir -p $build_path
66         fi
67
68         echo "Remove legacy build files..."
69         if [ -d ${build_result_path}/${archive_platform_name}.${windowing}.${architecture} ]
70         then
71                 rm -rf ${build_result_path}/${archive_platform_name}.${windowing}.${architecture}
72         fi
73         if [ -e ${build_result_path}/${result_archive_file} ]
74         then
75                 rm -rf ${build_result_path}/${result_archive_file}
76         fi
77         if [ -d ${build_path}/tmp ]
78         then
79                 rm -rf ${build_path}/tmp
80         fi
81
82         if [ -d ${build_path}/buildRepo ]
83         then
84                 rm -rf ${build_path}/buildRepo
85         fi
86
87         rm -rf ${build_path}/*.xml
88         rm -rf ${build_path}/*.properties
89         rm -rf ${build_path}/*.clean
90
91
92         if [ -d $build_path/plugins ]
93         then
94                 echo "plugins directory recreate..."
95                 rm -rf $build_path/plugins
96                 mkdir $build_path/plugins
97         else
98                 echo "Make plugins directory..."
99                 mkdir $build_path/plugins
100         fi
101         if [ -d $build_path/features/ ]
102         then
103                 echo "features directory recreate..."
104                 rm -rf $build_path/features
105                 mkdir $build_path/features
106         else
107                 echo "Make features directory..."
108                 mkdir $build_path/features
109         fi
110
111 }
112
113 __copy_build_sources()
114 {
115         echo "Copy features from $SRCDIR to $build_path/features"
116         temp_dir="`mktemp -d /tmp/ide.XXXXX`"
117         cp -r $SRCDIR/* $temp_dir
118         cp -r $temp_dir/* $build_path/features
119         rm -rf $temp_dir
120
121         echo "Copy plugins from $SRCDIR to $build_path/plugins"
122         temp_dir="`mktemp -d /tmp/ide.XXXXX`"
123         cp -r $SRCDIR/* $temp_dir
124         cp -r $temp_dir/* $build_path/plugins
125         rm -rf $temp_dir
126 }
127
128 __copy_dependency_plugins()
129 {
130         dependency_plugin_path=${ROOTDIR}/${ide_root_path_name}
131         if [ -d ${dependency_plugin_path} ]
132         then
133                 cp -rf ${dependency_plugin_path}/features/* ${build_path}/features/
134                 cp -rf ${dependency_plugin_path}/plugins/* ${build_path}/plugins/
135     else
136         echo "ERROR : ${dependency_plugin_path} is not exist."
137         fi
138 }
139
140 __make_ant_build_properties_file()
141 {
142         builder_path="${SRCDIR}/builder"
143         parent_path_of_based_eclipse=${reference_ide_path}/..
144
145         echo "Make build.properties file..."
146         if [ ! -e $builder_path/build.properties.clean ] ; then
147                 echo "ERROR : \"build.properties.clean\" file does not exist..."
148                 exit 1
149         fi
150         cp $builder_path/build.properties.clean $build_path
151         cp $builder_path/customTargets.xml $build_path
152
153         if [ -d $reference_ide_path ] 
154         then
155                 sed -e "s;\(^buildDirectory=\).*;\1${build_path};g" \
156                 -e "s;\(^base=\).*;\1${parent_path_of_based_eclipse};g" \
157                 -e "s;\(^baseLocation=\).*;\1${reference_ide_path};g" \
158                 -e "s;\(^configs=\).*;\1${archive_platform_name},${windowing},${architecture};g" \
159                 -e "s;\(^buildType=\).*;\1${build_type};g" \
160                 -e "s;\(^buildId=\).*;\1${build_id};g" \
161                 -e "s;\(^archivePrefix=\).*;\1${build_id};g" \
162                 < $build_path/build.properties.clean > $build_path/build.properties
163
164         else
165                 echo "ERROR : target eclipse is not exist."
166                 exit 1
167         fi
168 }
169
170 __execute_pde_build()
171 {
172         echo "Execute Product Ant Builder..."
173         equinox_launcher=`echo org.eclipse.equinox.launcher_*.jar`
174         pde_build=`echo org.eclipse.pde.build_*`
175
176         java -jar ${reference_ide_path}/plugins/$equinox_launcher -application org.eclipse.ant.core.antRunner -buildfile ${reference_ide_path}/plugins/$pde_build/scripts/productBuild/productBuild.xml -Dbuilder=$build_path -Dosgi.locking=none 2>&1
177
178         if [ $? != 0 ];
179         then
180                 echo "Build failed..."
181                 exit 1
182         fi
183 }
184
185 __unzip_plugin_pack()
186 {
187         echo "unzip to $build_result_path"
188         unzip -a $build_result_path/${result_archive_file} -d $build_result_path/${archive_platform_name}.${windowing}.${architecture}
189 }
190
191 build_plugins()
192 {
193         case ${platform} in
194                 ubuntu-32|ubuntu-64)
195                         echo "build plugin for ${platform}"
196                         ;;
197                 windows-32|windows-64)
198                         echo "build plugin for ${platform}"
199                         ;;
200         macos-64)
201             echo "build plugin for ${platform}"
202             ;;
203                 *)
204                         echo "${platform} is not support yet."
205                         exit 1
206                         ;;
207         esac
208
209         __set_parameter
210         __set_build_parameter
211         __clean_build_environment
212         __copy_build_sources
213         __copy_dependency_plugins
214         __make_ant_build_properties_file
215         __execute_pde_build
216         __unzip_plugin_pack
217
218         echo "Build SUCCESS. You will find SDK IDE in \"${build_result_path}\"."
219 }
220
221 __clean_packaging_environment()
222 {
223
224         if [ -d ${INSTALL_DIR} ]
225         then
226                 rm -rf ${INSTALL_DIR}
227         else
228                 mkdir -p ${INSTALL_DIR}
229         fi
230 }
231
232 __copy_necessary_binaries()
233 {
234         echo "add necessary files."
235         ## ex) cp -rf ~~~~/file.file ${INSTALL_DIR}/${ide_root_path_name}/
236 }
237
238 packaging_plugins()
239 {
240         __set_parameter
241         __set_install_parameter
242
243         __clean_packaging_environment
244         __copy_necessary_binaries
245
246         install_ide_path=${INSTALL_DIR}/${ide_root_path_name}
247         
248         if [ ! -d ${install_ide_path} ]
249         then
250                 mkdir -p ${install_ide_path}
251         fi
252
253         cp -rf ${build_result_path}/${archive_platform_name}.${windowing}.${architecture}/${package_name}/* ${install_ide_path}/
254 }
255
256 # clean
257 clean()
258 {
259         echo "=========================================CLEAN============================================"
260         rm -rf ${SRCDIR}/*.zip
261         rm -rf ${SRCDIR}/*.tar.gz
262         rm -rf ${build_path}
263 }
264
265 # build
266 build() 
267 {
268         echo "=========================================BUILD============================================"
269         pkgname_and_platform_list=`awk 'BEGIN{RS="\n\n"; FS="\n"} /Package:/{for(i=1;i<NF;i++){if($i ~ /^OS:/){print $1,$i}}}' ${SRCDIR}/package/pkginfo.manifest | tr ' ' '@'`
270         for pkgname_and_platform in ${pkgname_and_platform_list}
271         do
272                 pkgname_and_platform=`echo $pkgname_and_platform | tr '@' ' '`
273                 package_name=`echo ${pkgname_and_platform} | cut -f1 -d " " | cut -f2 -d ":"`
274                 platform=`echo ${pkgname_and_platform} | cut -f2 -d " " | cut -f2 -d ":"`
275         
276                 if [ "x${TARGET_OS}" = "x${platform}" ]
277                 then
278                         build_plugins
279                 else
280                         echo ""
281                 fi
282         done
283 }
284
285 # install
286 install() 
287 {
288         pkgname_and_platform_list=`awk 'BEGIN{RS="\n\n"; FS="\n"} /Package:/{for(i=1;i<NF;i++){if($i ~ /^OS:/){print $1,$i}}}' ${SRCDIR}/package/pkginfo.manifest | tr ' ' '@'`
289         for pkgname_and_platform in ${pkgname_and_platform_list}
290         do
291                 echo "=========================================INSTALL============================================"
292                 pkgname_and_platform=`echo $pkgname_and_platform | tr '@' ' '`
293                 package_name=`echo ${pkgname_and_platform} | cut -f1 -d " " | cut -f2 -d ":"`
294                 platform=`echo ${pkgname_and_platform} | cut -f2 -d " " | cut -f2 -d ":"`
295
296                 if [ "x${TARGET_OS}" = "x${platform}" ]
297                 then
298                         packaging_plugins
299                 else
300                         echo ""
301                 fi
302         done    
303 }
304
305 [ "$1" = "clean" ] && clean
306 [ "$1" = "build" ] && build
307 [ "$1" = "install" ] && install
308 exit 0