Home | History | Annotate | Download | only in tools
      1 #!/bin/bash
      2 #
      3 # A script that generates an ICU data file containing just timezone rules data.
      4 # The file can be used to provide time zone rules updates for compatible
      5 # devices. Note: Only the rules are contained and new timezones will not have
      6 # the translations.
      7 #
      8 # Usage:
      9 # ./createIcuUpdateResources.sh <tzdata tar.gz file> <ICU version>
     10 #
     11 # e.g.
     12 # ./createIcuUpdateResources.sh ~/Downloads/tzdata2015b.tar.gz 55
     13 #
     14 # After execution the file is generated.
     15 
     16 if (( $# != 2 )); then
     17   echo "Missing arguments"
     18   echo "Usage:"
     19   echo "./createIcuUpdateResources.sh <tzdata tar.gz file> <ICU version>"
     20   exit 1
     21 fi
     22 
     23 if [[ -z "${ANDROID_BUILD_TOP}" ]]; then
     24   echo "Configure your environment with build/envsetup.sh and lunch"
     25   exit 1
     26 fi
     27 
     28 TZ_DATA_FILE=$1
     29 ICU_VERSION=$2
     30 
     31 if [[ ! -f ${TZ_DATA_FILE} ]]; then
     32   echo "${TZ_DATA_FILE} not found"
     33   exit 1
     34 fi
     35 
     36 # Keep track of the original working dir. Must be the "tools" dir.
     37 START_DIR=`pwd`
     38 ICU_DIR=${ANDROID_BUILD_TOP}/external/icu/icu4c/source
     39 BUILD_DIR=${START_DIR}/icu_build
     40 
     41 # Fail if anything below fails
     42 set -e
     43 
     44 rm -rf ${BUILD_DIR}
     45 mkdir -p ${BUILD_DIR}
     46 cd ${BUILD_DIR}
     47 
     48 # Configure the build
     49 ${ICU_DIR}/runConfigureICU Linux
     50 mkdir -p ${BUILD_DIR}/bin
     51 cd ${BUILD_DIR}/tools/tzcode
     52 ln -s ${ICU_DIR}/tools/tzcode/icuregions ./icuregions
     53 ln -s ${ICU_DIR}/tools/tzcode/icuzones ./icuzones
     54 cp ${TZ_DATA_FILE} .
     55 
     56 # Make the tools
     57 make
     58 
     59 # Then make the whole thing
     60 cd ${BUILD_DIR}
     61 make -j32
     62 
     63 # Generate the tzdata.lst file used to configure which files are included.
     64 ICU_LIB_DIR=${BUILD_DIR}/lib
     65 BIN_DIR=${BUILD_DIR}/bin
     66 TZ_FILES=tzdata.lst
     67 
     68 echo metaZones.res > ${TZ_FILES}
     69 echo timezoneTypes.res >> ${TZ_FILES}
     70 echo windowsZones.res >> ${TZ_FILES}
     71 echo zoneinfo64.res >> ${TZ_FILES}
     72 
     73 # Copy all the .res files we need here a from, e.g. ./data/out/build/icudt55l
     74 RES_DIR=data/out/build/icudt${ICU_VERSION}l
     75 cp ${RES_DIR}/metaZones.res ${BUILD_DIR}
     76 cp ${RES_DIR}/timezoneTypes.res ${BUILD_DIR}
     77 cp ${RES_DIR}/windowsZones.res ${BUILD_DIR}
     78 cp ${RES_DIR}/zoneinfo64.res ${BUILD_DIR}
     79 
     80 # This is the package name required for the .dat file to be accepted by ICU.
     81 # This also affects the generated file name.
     82 ICU_PACKAGE=icudt${ICU_VERSION}l
     83 
     84 # Create the file
     85 LD_LIBRARY_PATH=${ICU_LIB_DIR} ${BIN_DIR}/pkgdata -F -m common -v -T . -d . -p ${ICU_PACKAGE} ${TZ_FILES}
     86 cp ${ICU_PACKAGE}.dat ${START_DIR}/icu_tzdata.dat
     87 
     88 # Copy the file to the original working dir.
     89 echo File can be found here: ${START_DIR}/icu_tzdata.dat
     90