| 1 | #!/bih/sh
 | 
|---|
| 2 | 
 | 
|---|
| 3 | #
 | 
|---|
| 4 | # Qt4 distribution ZIP archive creator.
 | 
|---|
| 5 | #
 | 
|---|
| 6 | # NOTE: This script requires the basic set of unix tools such as cp, mkdir,
 | 
|---|
| 7 | # pwd, readlink, find etc.
 | 
|---|
| 8 | #
 | 
|---|
| 9 | 
 | 
|---|
| 10 | #
 | 
|---|
| 11 | # Defaults
 | 
|---|
| 12 | #
 | 
|---|
| 13 | 
 | 
|---|
| 14 | out_dir_base="."
 | 
|---|
| 15 | 
 | 
|---|
| 16 | cp="cp -Rdp"
 | 
|---|
| 17 | 
 | 
|---|
| 18 | #
 | 
|---|
| 19 | # Functions
 | 
|---|
| 20 | #
 | 
|---|
| 21 | 
 | 
|---|
| 22 | die() { echo "ERROR: $@"; cd "$start_dir"; exit 1; }
 | 
|---|
| 23 | 
 | 
|---|
| 24 | run()
 | 
|---|
| 25 | {
 | 
|---|
| 26 |     echo "$@"
 | 
|---|
| 27 |     "$@" || die \
 | 
|---|
| 28 | "Last command failed (exit status $?)."
 | 
|---|
| 29 | }
 | 
|---|
| 30 | 
 | 
|---|
| 31 | cp_files()
 | 
|---|
| 32 | {
 | 
|---|
| 33 |     local src_base="$1" # source directory base
 | 
|---|
| 34 |     local out_base="$2" # output directory base
 | 
|---|
| 35 |     local path="$3"     # file path relative to $src_base, may be glob
 | 
|---|
| 36 |     local tgt_path="$4" # target path if differs from path, if ends with slash
 | 
|---|
| 37 |                         # only the dir part of path is changed
 | 
|---|
| 38 |                         # [optional]
 | 
|---|
| 39 |     local exclude="$5"  # exclude pattern (relative to $src_base),
 | 
|---|
| 40 |                         # case syntax [optional]
 | 
|---|
| 41 |     local ext="$6"      # additional extension of $path base to copy (e.g. .sym)
 | 
|---|
| 42 |                         # [optional]
 | 
|---|
| 43 | 
 | 
|---|
| 44 |     [ -z "$src_base" -o -z "$out_base" -o -z "$path" ] && \
 | 
|---|
| 45 |         die "cp_files: invalid arguments."
 | 
|---|
| 46 | 
 | 
|---|
| 47 |     local path_dir="${path%/*}"
 | 
|---|
| 48 |     [ "$path_dir" = "$path" ] && path_dir=.
 | 
|---|
| 49 |     local path_file="${path##*/}"
 | 
|---|
| 50 | 
 | 
|---|
| 51 |     if [ -n "$tgt_path" ]; then
 | 
|---|
| 52 |         local tgt_path_dir="${tgt_path%/*}"
 | 
|---|
| 53 |         [ "$tgt_path_dir" = "$tgt_path" ] && path_dir=.
 | 
|---|
| 54 |         local tgt_path_file="${tgt_path##*/}"
 | 
|---|
| 55 |         [ -z "$tgt_path_file" ] && tgt_path_file="$path_file"
 | 
|---|
| 56 |     else
 | 
|---|
| 57 |         local tgt_path_dir="$path_dir"
 | 
|---|
| 58 |         local tgt_path_file="$path_file"
 | 
|---|
| 59 |     fi
 | 
|---|
| 60 | 
 | 
|---|
| 61 |     [ -d "$out_base/$tgt_path_dir" ] || run mkdir -p "$out_base/$tgt_path_dir"
 | 
|---|
| 62 | 
 | 
|---|
| 63 |     # if path_file is a mask, reset tgt_path_file (to cp to just tgt_path_dir)
 | 
|---|
| 64 |     case "$path_file" in
 | 
|---|
| 65 |         *"*"*|*"?"*) tgt_path_file=;;
 | 
|---|
| 66 |     esac
 | 
|---|
| 67 | 
 | 
|---|
| 68 |     # simple case?
 | 
|---|
| 69 |     if [ -z "$exclude" -a -z "$ext" ]; then
 | 
|---|
| 70 |         run $cp "$src_base/$path" "$out_base/$tgt_path_dir/$tgt_path_file"
 | 
|---|
| 71 |         return
 | 
|---|
| 72 |     fi
 | 
|---|
| 73 | 
 | 
|---|
| 74 |     # complex case with exclude pattern or with additional extension
 | 
|---|
| 75 |     for f in $src_base/$path; do
 | 
|---|
| 76 |         [ -z "$exclude" ] || \
 | 
|---|
| 77 |             eval "case ${f#$src_base/} in $exclude) continue;; esac"
 | 
|---|
| 78 |         run $cp "$f" "$out_base/$tgt_path_dir/"
 | 
|---|
| 79 |         [ -z "$ext" ] || run $cp "${f%.*}.$ext" "$out_base/$tgt_path_dir/"
 | 
|---|
| 80 |     done
 | 
|---|
| 81 | }
 | 
|---|
| 82 | 
 | 
|---|
| 83 | cp_files_inst_out() cp_files "$inst_base" "$out_base" "$1" "$2" "$3" "$4"
 | 
|---|
| 84 | 
 | 
|---|
| 85 | cp_exe_files_inst_out() cp_files "$inst_base" "$out_base" "$1" "$2" "$3" "sym"
 | 
|---|
| 86 | 
 | 
|---|
| 87 | split_out_sym()
 | 
|---|
| 88 | {
 | 
|---|
| 89 |     local out_base="$1"
 | 
|---|
| 90 |     local out_base_sym="$2"
 | 
|---|
| 91 | 
 | 
|---|
| 92 |     [ -z "$out_base" -o -z "$out_base_sym" ] && \
 | 
|---|
| 93 |         die "create_zips: invalid arguments."
 | 
|---|
| 94 | 
 | 
|---|
| 95 |     run mkdir -p "$out_base_sym/"
 | 
|---|
| 96 | 
 | 
|---|
| 97 |     for f in $(cd "$out_base" && find -type f -name "*.sym"); do
 | 
|---|
| 98 |         local fd="${f%/*}"/
 | 
|---|
| 99 |         [ "$fd" = "$f/" ] && fd=
 | 
|---|
| 100 |         [ -d "$out_base_sym/$fd" ] || run mkdir -p "$out_base_sym/$fd"
 | 
|---|
| 101 |         run mv "$out_base/$f" "$out_base_sym/$fd"
 | 
|---|
| 102 |     done
 | 
|---|
| 103 | 
 | 
|---|
| 104 |     run $cp "$script_dir/INSTALL.OS2.debuginfo" "$out_base_sym/"
 | 
|---|
| 105 | }
 | 
|---|
| 106 | 
 | 
|---|
| 107 | parse_version()
 | 
|---|
| 108 | {
 | 
|---|
| 109 |     local spec_file="$start_dir/qt4.spec"
 | 
|---|
| 110 | 
 | 
|---|
| 111 |     # get the version info from .spec
 | 
|---|
| 112 |     ver_major=$(sed -nre \
 | 
|---|
| 113 |         "s/^%define ver_major[[:space:]]+([0-9]+).*$/\1/p" < "$spec_file")
 | 
|---|
| 114 |     ver_minor=$(sed -nre \
 | 
|---|
| 115 |         "s/^%define ver_minor[[:space:]]+([0-9]+).*$/\1/p" < "$spec_file")
 | 
|---|
| 116 |     ver_patch=$(sed -nre \
 | 
|---|
| 117 |         "s/^%define ver_patch[[:space:]]+([0-9]+).*$/\1/p" < "$spec_file")
 | 
|---|
| 118 |     os2_release=$(sed -nre \
 | 
|---|
| 119 |         "s/^%define os2_release[[:space:]]+([0-9]+).*$/\1/p" < "$spec_file")
 | 
|---|
| 120 |     rpm_release=$(sed -nre \
 | 
|---|
| 121 |         "s/^%define rpm_release[[:space:]]+([0-9]+).*$/\1/p" < "$spec_file")
 | 
|---|
| 122 | 
 | 
|---|
| 123 |     [ -z "$ver_major" -o -z "$ver_minor" -o -z "$ver_patch" -o \
 | 
|---|
| 124 |       -z "$os2_release" -o -z "$rpm_release" ] && \
 | 
|---|
| 125 |         die "Could not determine version number in '$spec_file'."
 | 
|---|
| 126 | 
 | 
|---|
| 127 |     ver_full_spec="$ver_major.$ver_minor.$ver_patch"
 | 
|---|
| 128 |     [ "$os2_release" != "0" ] && ver_full_spec="ver_full_spec.$os2_release"
 | 
|---|
| 129 |     ver_full_spec="$ver_full_spec-$rpm_release"
 | 
|---|
| 130 | 
 | 
|---|
| 131 |     ver_full="$ver_full_spec"
 | 
|---|
| 132 |     [ -n "$build_num" ] && ver_full="${ver_full}_${build_num}"
 | 
|---|
| 133 | }
 | 
|---|
| 134 | 
 | 
|---|
| 135 | create_zips()
 | 
|---|
| 136 | {
 | 
|---|
| 137 |     [ -z "$start_dir" -o -z "$out_dir" -o \
 | 
|---|
| 138 |       -z "$pkg_name" -o -z "$full_pkg_name" -o -z "$out_base" ] && \
 | 
|---|
| 139 |         die "create_zips: invalid arguments."
 | 
|---|
| 140 | 
 | 
|---|
| 141 |     local out_base_sym="$out_dir/$full_pkg_name-debuginfo/$pkg_name-$ver_full"
 | 
|---|
| 142 | 
 | 
|---|
| 143 |     # .SYM files
 | 
|---|
| 144 |     split_out_sym "$out_base" "$out_base_sym"
 | 
|---|
| 145 | 
 | 
|---|
| 146 |     local cwd=$(pwd)
 | 
|---|
| 147 | 
 | 
|---|
| 148 |     run cd "$out_base/.."
 | 
|---|
| 149 |     run zip -SrX9 "$full_pkg_name-$ver_full.zip" "$pkg_name-$ver_full"
 | 
|---|
| 150 |     run mv "$full_pkg_name-$ver_full.zip" "$out_dir/.."
 | 
|---|
| 151 | 
 | 
|---|
| 152 |     run cd "$out_base_sym/.."
 | 
|---|
| 153 |     run zip -SrX9 "$full_pkg_name-debuginfo-$ver_full.zip" "$pkg_name-$ver_full"
 | 
|---|
| 154 |     run mv "$full_pkg_name-debuginfo-$ver_full.zip" "$out_dir/.."
 | 
|---|
| 155 | 
 | 
|---|
| 156 |     run cd "$cwd"
 | 
|---|
| 157 | }
 | 
|---|
| 158 | 
 | 
|---|
| 159 | cmd_create()
 | 
|---|
| 160 | {
 | 
|---|
| 161 |     local inst_base="$1"
 | 
|---|
| 162 |     local build_num="$2"
 | 
|---|
| 163 | 
 | 
|---|
| 164 |     [ -d "$inst_base" ] || die "'$inst_base' is not a directory."
 | 
|---|
| 165 |     [ -d "$out_dir_base" ] || die "'$out_dir_base' is not a directory."
 | 
|---|
| 166 | 
 | 
|---|
| 167 |     parse_version
 | 
|---|
| 168 |     [ -z "$ver_full" ] && die "Version is not defined."
 | 
|---|
| 169 | 
 | 
|---|
| 170 |     echo "Spec version: $ver_full_spec"
 | 
|---|
| 171 |     echo "Full version: $ver_full"
 | 
|---|
| 172 | 
 | 
|---|
| 173 |     local out_dir="$out_dir_base/tmp-zip-qt4-$ver_full"
 | 
|---|
| 174 | 
 | 
|---|
| 175 |     run rm -rf "$out_dir"
 | 
|---|
| 176 | 
 | 
|---|
| 177 |     #--------------------------------------------------------------------------
 | 
|---|
| 178 |     # commons
 | 
|---|
| 179 |     #--------------------------------------------------------------------------
 | 
|---|
| 180 | 
 | 
|---|
| 181 |     local pkg_name="qt4"
 | 
|---|
| 182 | 
 | 
|---|
| 183 |     local designer_dlls="QtDsg*.dll"
 | 
|---|
| 184 |     local designer_plugin_dirs="designer"
 | 
|---|
| 185 | 
 | 
|---|
| 186 |     usr="@unixroot/usr"
 | 
|---|
| 187 | 
 | 
|---|
| 188 |     #--------------------------------------------------------------------------
 | 
|---|
| 189 |     # runtime package
 | 
|---|
| 190 |     #--------------------------------------------------------------------------
 | 
|---|
| 191 | 
 | 
|---|
| 192 |     local full_pkg_name="qt4"
 | 
|---|
| 193 |     local out_base="$out_dir/$full_pkg_name/$pkg_name-$ver_full"
 | 
|---|
| 194 | 
 | 
|---|
| 195 |     # Readmes
 | 
|---|
| 196 |     cp_files_inst_out "$usr/share/doc/qt4/LGPL_EXCEPTION.txt" "./"
 | 
|---|
| 197 |     cp_files_inst_out "$usr/share/doc/qt4/LICENSE.*" "./"
 | 
|---|
| 198 |     cp_files_inst_out "$usr/share/doc/qt4/README" "./"
 | 
|---|
| 199 |     cp_files_inst_out "$usr/share/doc/qt4/changes-$ver_major.$ver_minor.$ver_patch" "./"
 | 
|---|
| 200 |     cp_files_inst_out "$usr/share/doc/qt4/README.OS2" "./"
 | 
|---|
| 201 |     cp_files_inst_out "$usr/share/doc/qt4/CHANGES.OS2" "./"
 | 
|---|
| 202 |     run $cp "$script_dir/INSTALL.OS2" "$out_base/"
 | 
|---|
| 203 | 
 | 
|---|
| 204 |     # DLLs
 | 
|---|
| 205 |     cp_exe_files_inst_out "$usr/lib/Qt*.dll" "bin/" "$usr/lib/$designer_dlls"
 | 
|---|
| 206 | 
 | 
|---|
| 207 |     # Imports
 | 
|---|
| 208 |     cp_files_inst_out "$usr/lib/qt4/imports" "./"
 | 
|---|
| 209 | 
 | 
|---|
| 210 |     # Plugins
 | 
|---|
| 211 |     for d in $inst_base/$usr/lib/qt4/plugins/*; do
 | 
|---|
| 212 |         local dn=${d##*/}
 | 
|---|
| 213 |         eval "case $dn in $designer_plugin_dirs) continue;; esac"
 | 
|---|
| 214 |         cp_exe_files_inst_out "$usr/lib/qt4/plugins/$dn/*.dll" "plugins/$dn/"
 | 
|---|
| 215 |     done
 | 
|---|
| 216 | 
 | 
|---|
| 217 |     # Translations
 | 
|---|
| 218 |     cp_files_inst_out "$usr/share/qt4/translations/qt_??.qm" "translations/"
 | 
|---|
| 219 |     cp_files_inst_out "$usr/share/qt4/translations/qt_??_??.qm" "translations/"
 | 
|---|
| 220 |     cp_files_inst_out "$usr/share/qt4/translations/qt_help_??.qm" "translations/"
 | 
|---|
| 221 |     cp_files_inst_out "$usr/share/qt4/translations/qt_help_??_??.qm" "translations/"
 | 
|---|
| 222 | 
 | 
|---|
| 223 |     # qt.conf
 | 
|---|
| 224 |     echo \
 | 
|---|
| 225 | "[Paths]
 | 
|---|
| 226 | Prefix = ..
 | 
|---|
| 227 | Settings = \$(ETC)/xdg
 | 
|---|
| 228 | Examples = examples
 | 
|---|
| 229 | Demos = demos" \
 | 
|---|
| 230 |     > "$out_base/bin/qt.conf"
 | 
|---|
| 231 | 
 | 
|---|
| 232 |     create_zips
 | 
|---|
| 233 | 
 | 
|---|
| 234 |     #--------------------------------------------------------------------------
 | 
|---|
| 235 |     # development package
 | 
|---|
| 236 |     #--------------------------------------------------------------------------
 | 
|---|
| 237 | 
 | 
|---|
| 238 |     local full_pkg_name="qt4-devel-kit"
 | 
|---|
| 239 |     local out_base="$out_dir/$full_pkg_name/$pkg_name-$ver_full"
 | 
|---|
| 240 | 
 | 
|---|
| 241 |     # Readmes
 | 
|---|
| 242 |     cp_files_inst_out "$usr/share/doc/qt4/LGPL_EXCEPTION.txt" "./"
 | 
|---|
| 243 |     cp_files_inst_out "$usr/share/doc/qt4/LICENSE.*" "./"
 | 
|---|
| 244 |     cp_files_inst_out "$usr/share/doc/qt4/README" "./"
 | 
|---|
| 245 |     cp_files_inst_out "$usr/share/doc/qt4/changes-$ver_major.$ver_minor.$ver_patch" "./"
 | 
|---|
| 246 |     cp_files_inst_out "$usr/share/doc/qt4/README.OS2" "./"
 | 
|---|
| 247 |     cp_files_inst_out "$usr/share/doc/qt4/CHANGES.OS2" "./"
 | 
|---|
| 248 |     run $cp "$script_dir/INSTALL.OS2.develop" "$out_base/"
 | 
|---|
| 249 | 
 | 
|---|
| 250 |     # EXEs & DLLs
 | 
|---|
| 251 |     cp_exe_files_inst_out "$usr/lib/qt4/bin/*.exe" "bin/" "$usr/lib/qt4/bin/qmake.exe"
 | 
|---|
| 252 |     cp_exe_files_inst_out "$usr/bin/*.exe" "bin/"
 | 
|---|
| 253 |     cp_exe_files_inst_out "$usr/lib/$designer_dlls" "bin/"
 | 
|---|
| 254 | 
 | 
|---|
| 255 |     # Demos
 | 
|---|
| 256 |     cp_files_inst_out "$usr/lib/qt4/demos" "./"
 | 
|---|
| 257 | 
 | 
|---|
| 258 |     # Doc (no html, qch only)
 | 
|---|
| 259 |     cp_files_inst_out "$usr/share/qt4/doc/qch" "doc/"
 | 
|---|
| 260 |     cp_files_inst_out "$usr/share/qt4/q3porting.xml" "./"
 | 
|---|
| 261 | 
 | 
|---|
| 262 |     # Examples
 | 
|---|
| 263 |     cp_files_inst_out "$usr/lib/qt4/examples" "./"
 | 
|---|
| 264 | 
 | 
|---|
| 265 |     # Includes
 | 
|---|
| 266 |     cp_files_inst_out "$usr/include" "./"
 | 
|---|
| 267 | 
 | 
|---|
| 268 |     # Libraries
 | 
|---|
| 269 |     cp_files_inst_out "$usr/lib/Qt*.prl" "lib/"
 | 
|---|
| 270 |     cp_files_inst_out "$usr/lib/Qt*.lib" "lib/"
 | 
|---|
| 271 | 
 | 
|---|
| 272 |     # Mkspecs
 | 
|---|
| 273 |     cp_files_inst_out "$usr/share/qt4/mkspecs" "./"
 | 
|---|
| 274 | 
 | 
|---|
| 275 |     # Phrasebooks
 | 
|---|
| 276 |     cp_files_inst_out "$usr/share/qt4/phrasebooks" "./"
 | 
|---|
| 277 | 
 | 
|---|
| 278 |     # Plugins
 | 
|---|
| 279 |     for d in $inst_base/$usr/lib/qt4/plugins/*; do
 | 
|---|
| 280 |         local dn=${d##*/}
 | 
|---|
| 281 |         eval "case $dn in $designer_plugin_dirs) ;; *) continue;; esac"
 | 
|---|
| 282 |         cp_exe_files_inst_out "$usr/lib/qt4/plugins/$dn/*.dll" "plugins/$dn/"
 | 
|---|
| 283 |     done
 | 
|---|
| 284 | 
 | 
|---|
| 285 |     # Translations
 | 
|---|
| 286 |     cp_files_inst_out "$usr/share/qt4/translations/assistant_??.qm" "translations/"
 | 
|---|
| 287 |     cp_files_inst_out "$usr/share/qt4/translations/assistant_??_??.qm" "translations/"
 | 
|---|
| 288 |     cp_files_inst_out "$usr/share/qt4/translations/designer_??.qm" "translations/"
 | 
|---|
| 289 |     cp_files_inst_out "$usr/share/qt4/translations/designer_??_??.qm" "translations/"
 | 
|---|
| 290 |     cp_files_inst_out "$usr/share/qt4/translations/linguist_??.qm" "translations/"
 | 
|---|
| 291 |     cp_files_inst_out "$usr/share/qt4/translations/linguist_??_??.qm" "translations/"
 | 
|---|
| 292 | 
 | 
|---|
| 293 |     create_zips
 | 
|---|
| 294 | 
 | 
|---|
| 295 |     run rm -rf "$out_dir"
 | 
|---|
| 296 | 
 | 
|---|
| 297 |     echo "ALL DONE."
 | 
|---|
| 298 | }
 | 
|---|
| 299 | 
 | 
|---|
| 300 | #
 | 
|---|
| 301 | # Main
 | 
|---|
| 302 | #
 | 
|---|
| 303 | 
 | 
|---|
| 304 | script_path=$(readlink -e $0)
 | 
|---|
| 305 | script_dir=${script_path%/*}
 | 
|---|
| 306 | script_name=$(basename $0)
 | 
|---|
| 307 | 
 | 
|---|
| 308 | start_dir=$(pwd)
 | 
|---|
| 309 | 
 | 
|---|
| 310 | [ -z "$out_dir_base" ] && out_dir_base="."
 | 
|---|
| 311 | out_dir_base=$(readlink -m "$out_dir_base")
 | 
|---|
| 312 | 
 | 
|---|
| 313 | # Parse arguments
 | 
|---|
| 314 | 
 | 
|---|
| 315 | cmd_help()
 | 
|---|
| 316 | {
 | 
|---|
| 317 |     echo \
 | 
|---|
| 318 | "
 | 
|---|
| 319 | Usage:
 | 
|---|
| 320 |   $script_name all [options]    Create ZIPs.
 | 
|---|
| 321 | 
 | 
|---|
| 322 | Options:
 | 
|---|
| 323 |   <instdir>     (*) Qt installation tree location
 | 
|---|
| 324 |   <outdir>          Destination directory for ZIPs [$out_dir_base]
 | 
|---|
| 325 |   <bldnum>          Build number [none]
 | 
|---|
| 326 | "
 | 
|---|
| 327 | }
 | 
|---|
| 328 | 
 | 
|---|
| 329 | case "$1" in
 | 
|---|
| 330 |     all)
 | 
|---|
| 331 |         if [ -n "$2" ]; then
 | 
|---|
| 332 |             [ -n "$3" ] && out_dir_base=$(echo "$3" | tr '\\' '/')
 | 
|---|
| 333 |             cmd_create $(echo "$2" | tr '\\' '/') "$4"
 | 
|---|
| 334 |         else
 | 
|---|
| 335 |             cmd_help
 | 
|---|
| 336 |         fi;;
 | 
|---|
| 337 |     -h|-?|--help|*) cmd_help;;
 | 
|---|
| 338 | esac
 | 
|---|
| 339 | 
 | 
|---|
| 340 | # end of story
 | 
|---|
| 341 | 
 | 
|---|
| 342 | exit 0
 | 
|---|