<commit_before>#!/bin/bash

CMD=$0
MODULE=$1
ARCH=$2

#default is x86
case $# in
0)
  MODULE=all;
  ARCH=x86;;
1)
  ARCH=x86;;
esac

#add supported platform to here
PLATFORM="[x86|pi|android]"

#basic libraries
BASIC_LIBS="libgzf liblog libgevent libworkq libdict"
NETWORK_LIBS="libskt"

usage()
{
  echo "==== build usage:"
  echo "$CMD <module> [platform]"
  echo "<module>: library to compile or all library, must needed"
  echo "[platform]: x86, raspberrypi or android, default is x86, optional"
  echo ""
  echo "./build.sh all $PLATFORM"
  echo "./build.sh basic_libs $PLATFORM"
  echo "./build.sh network_libs $PLATFORM"
  echo ""
  echo "basic libraries (must):"
  for item in $BASIC_LIBS
  do
    echo "$CMD $item $PLATFORM"
  done
  echo ""
  echo "network libraries (optional):"
  for item in $NETWORK_LIBS
  do
    echo "$CMD $item $PLATFORM"
  done
  exit
}

build_all()
{
  for item in $BASIC_LIBS $NETWORK_LIBS
  do
    MODULE="$item"
    build_module
  done
}

build_network_libs()
{
  for item in $NETWORK_LIBS
  do
    MODULE="$item"
    build_module
  done
}

config_x86()
{
  CROSS_PREFIX=
}

config_pi()
{
  CROSS_PREFIX=arm-linux-gnueabihf-
}

config_android()
{
  CROSS_PREFIX=arm-hisiv100nptl-linux-
}

config_common()
{
  STRIP=${CROSS_PREFIX}strip
  LIBS_DIR=`pwd`
  CPUS=`nproc`
  MAKE="make ARCH=${ARCH} OUTPUT=${LIBS_DIR}/output"
  echo "$MAKE"
}

build_module()
{
  if [ ! -d "${LIBS_DIR}/${MODULE}" ]; then
    echo "==== build ${MODULE} failed!"
    echo "     dir \"${LIBS_DIR}/${MODULE}\" is not exist"
    return;
  fi
  cd ${LIBS_DIR}/${MODULE}/

  make clean > /dev/null
  if [[ ${ARCH} == "x86" || ${ARCH} == "pi" ]]; then
    ${MAKE} > /dev/null
  else
    make -f Makefile.${ARCH} > /dev/null
  fi
  ${MAKE} install > /dev/null
  if [ $? -ne 0 ]; then
    echo "==== build ${MODULE} failed"
    return;
  else
    echo "==== build ${MODULE} ${ARCH} done."
  fi
}

build_liblog()
{
  build_module
}

case $ARCH in
"pi")
  config_pi;;
"android")
  config_android;;
"x86")
  config_x86;;
*)
  usage;;
esac

config_common

case $MODULE in
"all")
  build_all;;
"basic")
  build_ipcam_libs;;
"network")
  build_sys_libs;;
"liblog")
  build_liblog;;
"libskt")
  build_libskt;;
*)
  echo "$MODULE not found"
  usage;;
esac<commit_msg>update build.sh<commit_after>#!/bin/bash

CMD=$0
MODULE=$1
ARCH=$2

#default is x86
case $# in
0)
	MODULE=all;
	ARCH=x86;;
1)
	ARCH=x86;;
esac

#add supported platform to here
PLATFORM="[x86|pi|android]"

#basic libraries
BASIC_LIBS="libgzf liblog libgevent libworkq libdict libsort librbtree"
NETWORK_LIBS="libskt libstun libptcp libp2p librpc"

usage()
{
	echo "==== usage ===="
	echo "$CMD <module> [platform]"
	echo "<module>: library to compile or all library, must needed"
	echo "[platform]: x86, raspberrypi or android, default is x86, optional"
	echo ""
	echo "./build.sh all $PLATFORM"
	echo "./build.sh basic_libs $PLATFORM"
	echo "./build.sh network_libs $PLATFORM"
	echo ""
	echo "basic libraries (must):"
	for item in $BASIC_LIBS; do
		echo "$CMD $item $PLATFORM";
	done
	echo ""
	echo "network libraries (optional):"
	for item in $NETWORK_LIBS; do
		echo "$CMD $item $PLATFORM";
	done
	exit
}

config_x86()
{
	CROSS_PREFIX=
}

config_pi()
{
	CROSS_PREFIX=arm-linux-gnueabihf-
}

config_android()
{
	CROSS_PREFIX=arm-linux-androideabi-
}

config_common()
{
	STRIP=${CROSS_PREFIX}strip
	LIBS_DIR=`pwd`
	OUTPUT=${LIBS_DIR}/output
}

config_arch()
{
	case $ARCH in
		"pi")
		config_pi;;
	"android")
		config_android;;
	"x86")
		config_x86;;
	*)
		usage;;
	esac
}

check_output()
{
	if [ ! -d "${OUTPUT}" ]; then
		mkdir -p ${OUTPUT}/include
		mkdir -p ${OUTPUT}/lib
	fi
}

build_module()
{
	MODULE_DIR=${LIBS_DIR}/$1
	ACTION=$2
	if [ ! -d "${MODULE_DIR}" ]; then
		echo "==== build ${MODULE} failed!"
		echo "     dir \"${MODULE_DIR}\" is not exist"
		return
	fi
	cd ${LIBS_DIR}/${MODULE}/

	case $ACTION in
	"clean")
		make clean > /dev/null
		echo "==== clean ${MODULE} done."
		return
		;;
	"install")
		MAKE="make ARCH=${ARCH}"
		${MAKE} install > /dev/null
		if [ $? -ne 0 ]; then
			echo "==== install ${MODULE} failed"
			return;
		else
			echo "==== install ${MODULE} ${ARCH} done."
		fi
		;;
	"uninstall")
		MAKE="make ARCH=${ARCH}"
		${MAKE} uninstall > /dev/null
		if [ $? -ne 0 ]; then
			echo "==== uninstall ${MODULE} failed"
			return;
		else
			echo "==== uninstall ${MODULE} ${ARCH} done."
		fi
		;;
	*)
		MAKE="make ARCH=${ARCH} OUTPUT=${OUTPUT}"
		if [[ ${ARCH} == "x86" || ${ARCH} == "pi" ]]; then
			${MAKE} > /dev/null
		else
			make -f Makefile.${ARCH} > /dev/null
		fi
		${MAKE} install > /dev/null
		if [ $? -ne 0 ]; then
			echo "==== build ${MODULE} failed"
			return;
		else
			echo "==== build ${MODULE} ${ARCH} done."
		fi
		;;
	esac
}

build_all()
{
	for item in $BASIC_LIBS $NETWORK_LIBS; do
		MODULE="$item"
		ARG2=$1
		build_module $MODULE $ARG2
	done
}

do_build()
{
	case $MODULE in
		"all")
		build_all;;
	"clean")
		build_all clean;;
	"install")
		build_all install;;
	"uninstall")
		build_all uninstall;;
	"help")
		usage;;
	*)
		build_module $MODULE;;
	esac
}

config_arch
config_common
check_output
do_build
{'fraction_non_alphanumeric': 0.17115534738485558, 'fraction_numerical': 0.012295081967213115, 'mean_word_length': 3.6212804328223624, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '543376', 'n_tokens_mistral': 2186, 'n_tokens_neox': 2037, 'n_words': 514}