3 ### Prepare: set global variables ###
5 SCRIPTDIR="`cd \`dirname $0\`/; pwd`"
6 LIBDIR=$SCRIPTDIR/../lib/tizen-web-ui-fw
12 # Parse commandline options, and export option variables
14 # Created by Youmin Ha <youmin.ha@samsung.com>
17 # - Set option_list array like below:
18 # option_list=( "--prelink" "--foo=" )
19 # - Add this inc by following code:
20 # . ${TOPDIR}/inc/parseopt.inc
22 # After including parseopt.inc, argc and argv are set, excluding options in option_list.
29 if test ! -n "${option_list}"; then
30 local option_list=( ); # available option list, starting --
35 while [ "$idx" -lt "$argc" ];
37 local arg=${argv[${idx}]}
40 for _valid_option in ${option_list[@]}
42 #echo "...for valid option:$_valid_option"
43 #echo " ...check arg:${arg:0:${#_valid_option}}"
44 if [[ "$_valid_option" == "${arg:0:${#_valid_option}}" ]]; then
45 #echo "...found valid option:$_valid_option"
46 if [ ${_valid_option:${#_valid_option}-1} == "=" ]; then
47 eval "export ${arg#--}"
49 eval "export ${arg#--}=1"
52 # pull remained options
53 let "tmp_idx = $idx + 1"
54 while [ "$tmp_idx" -lt "${#argv[@]}" ]
56 argv[$tmp_idx-1]="${argv[$tmp_idx]}"
57 let "tmp_idx = $tmp_idx + 1"
59 unset argv[${#argv[@]}-1]
64 if [ ! -n "$__changed" ]; then
72 option_list=( "--copylib" "--type=" )
76 INSTALL_DIR=${argv[1]}
77 if [ ! -n "$INSTALL_DIR" ]; then
80 DESTDIR="$INSTALL_DIR/$APP_NAME"
83 # Print usage and exit #
87 if [ -n "$1" ]; then local ERRMSG=$1; else local ERRMSG="Invalid arguments"; fi
90 if [ -n "$1" ]; then EXITCODE=1; echo "ERROR: $ERRMSG"; echo ""; fi
92 if [ ! -n "$1" ]; then
93 echo "Usage: $0 <--copylib> <--type=[w3c|wac]> <app-name> <install-dir>"
95 echo " app-name : Your application name. If whitespace is contained, wrap it "
96 echo " by quote mark."
97 echo " install-dir : Directory which the template code directory with name of"
98 echo " app-name is created in."
99 echo " <install-dir>/<app-name>/ directory will be created."
100 echo " --copylib : When this option is used, all libs and resources will be "
101 echo " copied into template directory, and all templates will refer"
102 echo " those copied libs."
103 echo " --type=[w3c|wac]"
104 echo " Set type of application template. If no --type= option is given,"
105 echo " only default app template files will be copied."
116 if [ ! -d "$INSTALL_DIR" ]; then usage "No install-dir found; $INSTALL_DIR"; fi
117 if [ -e "$DESTDIR" ]; then usage "$DESTDIR already exists"; fi
121 ### Copy template files into installation directory ###
122 function copy_template
124 local libpath=$LIBDIR
125 local tplpath=$libpath/template
127 # Check if this script is in src script
128 if [ -e "${SCRIPTDIR}/../build/tizen-web-ui-fw" ]; then
129 libpath="${SCRIPTDIR}/../build/tizen-web-ui-fw"
130 tplpath=${SCRIPTDIR}/../src/template
133 echo "Copying template files into $DESTDIR..."
134 mkdir -p $DESTDIR || usage "ERROR: Failed to create directory: $DESTDIR"
135 find $tplpath/ -maxdepth 1 -type f | xargs -i cp -a {} $DESTDIR/ || usage "ERROR: Failed to copy templates" ;
136 if [[ -n "$type" && -d "$tplpath/$type" ]]; then # Copy type-specific files
137 cp -a $tplpath/$type/* $DESTDIR/ || usage "ERROR: Failed to copy templates"
140 # copy lib if --copylib option is given
141 if [ -n "$copylib" ]; then
142 echo "Copying libs into $DESTDIR..."
143 cp -a ${libpath} ${DESTDIR}/ || usage "ERROR: Failed to copy libs"
144 DATA_FRAMEWORK_ROOT="data-framework-root=\"tizen-web-ui-fw\""
145 LIBDIR="tizen-web-ui-fw/0.1/js" # This new value is used by replace_template()
146 else # otherwise, just set libdir
148 #LIBDIR="file://$LIBDIR/template"
153 ### Replace filename & keywords ###
154 function replace_template
156 echo "Replacing contents of template files..."
158 local replace_keywords=( "APP_NAME" "LIBDIR" "DATA_FRAMEWORK_ROOT")
160 local in_file_path_list=`find $DESTDIR -name '*.in' -type f -print`
161 for in_file_path in ${in_file_path_list[@]}; do
162 for keyword in "${replace_keywords[@]}"; do
163 eval "local val=\$$keyword"
164 #echo "keyword=$keyword, val=$val"
165 sed -i -e "s#@$keyword@#$val#g" $in_file_path
168 rename 's/\.in//' $DESTDIR/*