#!/bin/sh NAME='ibus-chewing' ARCH=$(uname -m) BUILD_DIR="/tmp/${NAME}_build" OUTPUTDIR='/tmp/out' #SOURCEDIR='/tmp/source' ## build dependencies ## BUILD_DEPS="cmake.tcz compiletc.tcz gettext-dev.tcz git.tcz glib2-dev.tcz glibc_gconv.tcz gob2.tcz gtk2-dev.tcz ibus-dev.tcz libchewing-dev.tcz squashfs-tools.tcz " echo tce-load -w $BUILD_DEPS tce-load -w $BUILD_DEPS > /dev/null 2>&1 echo tce-load -i $BUILD_DEPS tce-load -i $BUILD_DEPS > /dev/null 2>&1 || exit 1 rm -fr $OUTPUTDIR mkdir $OUTPUTDIR ## get source ## sudo rm -fr $BUILD_DIR mkdir -p $BUILD_DIR && cd $BUILD_DIR || { echo Can not create $BUILD_DIR >&2; exit 1; } git clone https://github.com/definite/ibus-chewing.git cd ibus-chewing || exit 1 # wget https://releases.pagure.org/cmake-fedora/cmake-fedora-modules-only-latest.tar.gz wget https://releases.pagure.org/cmake-fedora/cmake-fedora-2.9.2-modules-only.tar.gz # tar xf cmake-fedora-modules-only-latest.tar.gz || exit 1 tar xf cmake-fedora-2.9.2-modules-only.tar.gz ## compile flags ## FLAGS_i686='-march=i486 -mtune=i686 ' FLAGS_x86_64='-mtune=generic ' eval CFLAGS="\$FLAGS_${ARCH}" eval CXXFLAGS="\$FLAGS_${ARCH}" CFLAGS="${CFLAGS}-Os -pipe -fno-exceptions -flto -fuse-linker-plugin" CXXFLAGS="${CXXFLAGS}-Os -pipe -fno-exceptions -flto -fuse-linker-plugin -fno-rtti" LDFLAGS="-Wl,-O1" export CFLAGS CXXFLAGS LDFLAGS ## configure ## cmake . \ -DCMAKE_INSTALL_PREFIX='/usr/local' \ -DLIBEXEC_DIR='/usr/local/lib/ibus-chewing' \ -DDATA_DIR='/usr/local/share' \ -DPRJ_DOC_DIR='/usr/local/share/doc/ibus-chewing' \ -DPRJ_DATA_DIR='/usr/local/share/ibus-chewing' \ 2> ${BUILD_DIR}/cmake2 | tee ${BUILD_DIR}/cmake1 ## make ## make -j 2> ${BUILD_DIR}/make2 | tee ${BUILD_DIR}/make1 make DESTDIR=${BUILD_DIR}/${NAME}-base install [ $? != 0 ] && { echo Error occur, make install failed >&2 exit 1 } ## strip ## cd ${BUILD_DIR}/${NAME}-base find . -type f -exec file {} + | \ grep 'not stripped' | cut -d : -f 1 | \ xargs strip --strip-unneeded ## packing up ## ## doc AUTHORS COPYING LICENCE etc. EXT='-doc' mkdir -p ${BUILD_DIR}/${NAME}${EXT}/usr/local/share mv usr/local/share/doc ${BUILD_DIR}/${NAME}${EXT}/usr/local/share sudo chown root:root -R ${BUILD_DIR}/${NAME}${EXT} mksquashfs ${BUILD_DIR}/${NAME}${EXT} ${OUTPUTDIR}/${NAME}${EXT}.tcz ## locale ## EXT='-locale' for locale in $(find . -name *.mo); do path=${locale#./} path=${path%/*} mkdir -p ${BUILD_DIR}/${NAME}${EXT}/$path mv $locale ${BUILD_DIR}/${NAME}${EXT}/$path done 2> /dev/null sudo chown root:root -R ${BUILD_DIR}/${NAME}${EXT} mksquashfs ${BUILD_DIR}/${NAME}${EXT} ${OUTPUTDIR}/${NAME}${EXT}.tcz echo ibus-chewing.tcz > ${OUTPUTDIR}/${NAME}${EXT}.tcz.dep ## base ## EXT='-base' # remove empty directory find . -depth -type d -exec rmdir {} \; 2> /dev/null # add startup script example mkdir -p ${BUILD_DIR}/${NAME}${EXT}/usr/local/share/doc/${NAME} printf '#!/bin/sh # desktop SYSTEM_DESKTOP="$(cat /etc/sysconfig/desktop)" [ "$SYSTEM_DESKTOP" = "gnome-session" ] && { ibus-daemon -drx & } || { ibus-daemon -drx -n "$SYSTEM_DESKTOP" & } # choose engine ibus engine chewing & # set input-sources /usr/local/bin/gsettings \ set org.gnome.desktop.input-sources \ sources \x27[("ibus", "chewing")]\x27 & ' > ${BUILD_DIR}/${NAME}${EXT}/usr/local/share/doc/${NAME}/startup_script.example # adjust .desktop file for desktop in $(find . -name *.desktop); do printf "\nX-FullPathIcon=/usr/local/share/${NAME}/icons/ibus-setup-chewing.png\n" >> $desktop sed -i '/^[[:blank:]]*$/d' $desktop done # tce.installed mkdir -p usr/local/tce.installed printf '#!/bin/sh # update cache /usr/local/bin/gdk-pixbuf-query-loaders --update-cache & mkdir -p /usr/local/lib/gtk-2.0/2.10.0 /usr/local/bin/gtk-query-immodules-2.0 --update-cache & /usr/local/bin/gtk-query-immodules-3.0 --update-cache & # update schemas /usr/local/bin/glib-compile-schemas \ /usr/local/share/glib-2.0/schemas 2> /dev/null & # ~/.X.d for TCUSER in $(busybox ls /home); do mkdir -p /home/${TCUSER}/.X.d [ -f /home/${TCUSER}/.X.d/ibus-chewing ] || \ cp /usr/local/share/doc/ibus-chewing/startup_script.example \ /home/${TCUSER}/.X.d/ibus-chewing chmod 755 /home/${TCUSER}/.X.d/ibus-chewing chown ${TCUSER}:staff /home/${TCUSER}/.X.d/ibus-chewing done ' > ${BUILD_DIR}/${NAME}${EXT}/usr/local/tce.installed/${NAME} sudo chown root:root -R ${BUILD_DIR}/${NAME}${EXT} sudo chown root:staff -R ${BUILD_DIR}/${NAME}${EXT}/usr/local/tce.installed sudo chmod -R 775 ${BUILD_DIR}/${NAME}${EXT}/usr/local/tce.installed mksquashfs ${BUILD_DIR}/${NAME}${EXT} ${OUTPUTDIR}/${NAME}.tcz printf 'gtk2.tcz ibus-gir.tcz libchewing.tcz ' > ${OUTPUTDIR}/${NAME}.tcz.dep