build.sh 3.8 KB
Newer Older
1
#!/bin/bash
O
oceanbase-admin 已提交
2 3 4
TOPDIR="$(dirname $(readlink -f "$0"))"
DEP_DIR=${TOPDIR}/deps/3rd/usr/local/oceanbase/deps/devel
TOOLS_DIR=${TOPDIR}/deps/3rd/usr/local/oceanbase/devtools
W
wangzelin.wzl 已提交
5
RUNTIME_DIR=${TOPDIR}/deps/3rd/usr
6
CPU_CORES=`grep -c ^processor /proc/cpuinfo`
W
wangzelin.wzl 已提交
7 8 9 10 11 12 13
MAKE_ARGS="-j $CPU_CORES"

PACKAGE=${2:-obproxy-ce}
VERSION=${3:-`cat rpm/${PACKAGE}-VER.txt`}
RELEASE=${4:-1}
PREFIX=/home/admin/obproxy
SPEC_FILE=obproxy.spec
O
oceanbase-admin 已提交
14 15 16 17 18 19 20 21

function sw()
{
  export DEP_DIR;
  export TOOLS_DIR;
  export RUNTIME_DIR;
  export DEP_VAR=$DEP_DIR/var/;
  /sbin/ldconfig -n $DEP_DIR/lib;
22 23 24 25
  export LD_LIBRARY_PATH=$DEP_DIR/lib:$DEP_VAR/usr/local/lib64:$DEP_VAR/usr/local/lib:$DEP_VAR/usr/lib64:$DEP_VAR/usr/lib:$DEP_VAR/lib64:/usr/lib/x86_64-linux-gnu;
  export LIBRARY_PATH=$DEP_DIR/lib:$DEP_VAR/usr/local/lib64:$DEP_VAR/usr/local/lib:$DEP_VAR/usr/lib64:$DEP_VAR/usr/lib:/usr/lib/x86_64-linux-gnu;
  export CPLUS_INCLUDE_PATH=$DEP_DIR/include:${RUNTIME_DIR}/include:$DEP_VAR/usr/local/include:$DEP_VAR/usr/include:$DEP_VAR/devel/include:/usr/include/x86_64-linux-gnu;
  export C_INCLUDE_PATH=$DEP_DIR/include:${RUNTIME_DIR}/include:/usr/include/x86_64-linux-gnu;
O
oceanbase-admin 已提交
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
  export PATH=$DEP_DIR/bin:$TOOLS_DIR/bin:$PATH;
}

export AUTOM4TE="autom4te"
export AUTOCONF="autoconf"

function do_init()
{
	set -x
  sw
	aclocal
	libtoolize --force --copy --automake
	autoconf --force
	automake --foreign --copy --add-missing -Woverride -Werror
}

function do_dep_init()
{
W
wangzelin.wzl 已提交
44
  cd $TOPDIR/deps/3rd && bash dep_create.sh
O
oceanbase-admin 已提交
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
  cd $TOPDIR
  do_init
}

function do_clean()
{
	echo 'cleaning...'
	make distclean >/dev/null 2>&1
	rm -rf autom4te.cache
	for fn in aclocal.m4 configure config.guess config.sub depcomp install-sh \
		ltmain.sh libtool missing mkinstalldirs config.log config.status Makefile; do
		rm -f $fn
	done

	find . -name Makefile.in -exec rm -f {} \;
	find . -path ./tools/codestyle/astyle/build -prune -o -path ./doc -prune -o -name Makefile -exec rm -f {} \;
	find . -name .deps -prune -exec rm -rf {} \;
	echo 'done'
}

function do_config()
{
  set -x
  sw
  case "x$1" in
    xdebug)
      # configure for developers
      ./configure --with-gcc-version=5.2.0 --with-coverage=no --enable-buildtime=no --enable-strip-ut=no --enable-silent-rules --enable-dlink-observer=no
      echo -e "\033[31m ===build debug version=== \033[0m"
      ;;
    xgcov)
      # configure for release
      ./configure --with-gcc-version=5.2.0 --with-coverage=yes --enable-buildtime=no --enable-strip-ut=no --enable-silent-rules --enable-dlink-observer=no
      echo -e "\033[31m ===build gcov version=== \033[0m"
      ;;
    *)
      # configure for release
      ./configure --with-gcc-version=5.2.0 --with-coverage=no --enable-buildtime=no --enable-strip-ut=no --enable-silent-rules --enable-dlink-observer=no --with-release
      echo -e "\033[31m ===build release version=== \033[0m"
      ;;
  esac
}

function do_make()
{
  set -x
  sw
W
wangzelin.wzl 已提交
92
  make $MAKE_ARGS
O
oceanbase-admin 已提交
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
}

function do_rpm()
{
  set -x
  sw

  echo "[BUILD] make dist..."
  make dist-gzip || exit 1

  TMP_DIR=/${TOPDIR}/obproxy-tmp.$$
  echo "[BUILD] create tmp dirs...TMP_DIR=${TMP_DIR}"
  mkdir -p ${TMP_DIR}
  mkdir -p ${TMP_DIR}/BUILD
  mkdir -p ${TMP_DIR}/RPMS
  mkdir -p ${TMP_DIR}/SOURCES
  mkdir -p ${TMP_DIR}/SRPMS
110
  cp ${PACKAGE}-${VERSION}.tar.gz ${TMP_DIR}/SOURCES
O
oceanbase-admin 已提交
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
  cd ${TMP_DIR}/BUILD

  echo "[BUILD] make rpms..._prefix=${PREFIX} spec_file=${SPEC_FILE}"
  rpmbuild --define "_topdir ${TMP_DIR}" --define "NAME ${PACKAGE}" --define "VERSION ${VERSION}" --define "_prefix ${PREFIX}" --define "RELEASE ${RELEASE}" -ba ${TOPDIR}/deps/3rd/${SPEC_FILE} || exit 2
  echo "[BUILD] make rpms done."

  cd ${TOPDIR}
  find ${TMP_DIR}/RPMS/ -name "*.rpm" -exec mv '{}' ./ \;
  rm -rf ${TMP_DIR}
}

case "x$1" in
xinit)
  do_dep_init
	;;
xqinit)
  do_init
	;;
xclean)
  do_clean
	;;
xconfig)
  do_config $2
  ;;
xmake)
  do_make
  ;;
xrpm)
  do_dep_init
  do_config
  do_rpm
  ;;
*)
  do_dep_init
  do_config
  do_make
	;;
esac