<commit_before>#!/bin/bash

CSDK_REVISION="0.9.2"

if test "x$1x" = "x--debugx"; then
	SCONS_FLAGS="RELEASE=False"
fi

set -x

get_output_path() {
	scons $SCONS_FLAGS -h | \
	awk \
		-v 'release=""' \
		-v 'os=""' \
		-v 'arch=""' \
		-v 'context=""' \
		'
		{
			if ( $1 == "RELEASE:" ) {
				context = "release";
			} else if ( $1 == "TARGET_OS:" ) {
				context = "os";
			} else if ( $1 == "TARGET_ARCH:" ) {
				context = "arch";
			}

			if ( $1 == "actual:" ) {
				if ( context == "release" ) {
					release = ( $2 == "True" ? "release" : "debug" );
					context = "";
				} else if ( context == "os" ) {
					os = $2;
					context = "";
				} else if ( context == "arch" ) {
					arch = $2;
					context = "";
				}
			}
		}
		END {
			print( "out/" os "/" arch "/" release );
		}
	'
}

install() {

	# Default prefix is /usr
	PREFIX="$(pwd)/../../deps/iotivity"

	# Install the first platform/arch/configuration we find
	PLATFORM="$(ls out | head -n 1)"

	if test "${PLATFORM}" = "darwin"; then
	  ARCH=x86_64
	else
	  ARCH="$(ls out/${PLATFORM} | head -n 1)"
	fi

	CONFIGURATION="$(ls out/${PLATFORM}/${ARCH} | grep -E "release|debug" | head -n 1)"

	LIBDIR="$( echo "${PREFIX}/lib" | sed 's@//*@/@g' )"
	INCLUDEDIR="$( echo "${PREFIX}/include" | sed 's@//*@/@g' )"

	OCTBSTACK_INCLUDEDIR=iotivity/resource/csdk/stack/include

	mkdir -p "${LIBDIR}" || return 1
	if test "${PLATFORM}" = "darwin"; then
	  cp out/${PLATFORM}/${ARCH}/${CONFIGURATION}/*.a ${LIBDIR} || return 1
	else
	  cp out/${PLATFORM}/${ARCH}/${CONFIGURATION}/liboctbstack.so ${LIBDIR} || return 1
	fi

	mkdir -p "${INCLUDEDIR}/iotivity/resource/csdk/stack" || return 1
	cp -a resource/csdk/stack/include "${INCLUDEDIR}/${OCTBSTACK_INCLUDEDIR}" || return 1
}

mkdir -p ./depbuild || exit 1

# Download and build iotivity from tarball
cd ./depbuild || exit 1
	wget -O iotivity.tar.gz 'https://gerrit.iotivity.org/gerrit/gitweb?p=iotivity.git;a=snapshot;h='"${CSDK_REVISION}"';sf=tgz' || exit 1
	tar xzf iotivity.tar.gz || exit 1

	# There should only be one directory inside this directory, so using the wildcard evaluates<commit_msg>Build: Add hack to csdk whereby it touches logger.h<commit_after>#!/bin/bash

CSDK_REVISION="0.9.2"

if test "x$1x" = "x--debugx"; then
	SCONS_FLAGS="RELEASE=False"
fi

set -x

get_output_path() {
	scons $SCONS_FLAGS -h | \
	awk \
		-v 'release=""' \
		-v 'os=""' \
		-v 'arch=""' \
		-v 'context=""' \
		'
		{
			if ( $1 == "RELEASE:" ) {
				context = "release";
			} else if ( $1 == "TARGET_OS:" ) {
				context = "os";
			} else if ( $1 == "TARGET_ARCH:" ) {
				context = "arch";
			}

			if ( $1 == "actual:" ) {
				if ( context == "release" ) {
					release = ( $2 == "True" ? "release" : "debug" );
					context = "";
				} else if ( context == "os" ) {
					os = $2;
					context = "";
				} else if ( context == "arch" ) {
					arch = $2;
					context = "";
				}
			}
		}
		END {
			print( "out/" os "/" arch "/" release );
		}
	'
}

install() {

	# Default prefix is /usr
	PREFIX="$(pwd)/../../deps/iotivity"

	# Install the first platform/arch/configuration we find
	PLATFORM="$(ls out | head -n 1)"

	if test "${PLATFORM}" = "darwin"; then
	  ARCH=x86_64
	else
	  ARCH="$(ls out/${PLATFORM} | head -n 1)"
	fi

	CONFIGURATION="$(ls out/${PLATFORM}/${ARCH} | grep -E "release|debug" | head -n 1)"

	LIBDIR="$( echo "${PREFIX}/lib" | sed 's@//*@/@g' )"
	INCLUDEDIR="$( echo "${PREFIX}/include" | sed 's@//*@/@g' )"

	OCTBSTACK_INCLUDEDIR=iotivity/resource/csdk/stack/include

	mkdir -p "${LIBDIR}" || return 1
	if test "${PLATFORM}" = "darwin"; then
	  cp out/${PLATFORM}/${ARCH}/${CONFIGURATION}/*.a ${LIBDIR} || return 1
	else
	  cp out/${PLATFORM}/${ARCH}/${CONFIGURATION}/liboctbstack.so ${LIBDIR} || return 1
	fi

	mkdir -p "${INCLUDEDIR}/iotivity/resource/csdk/stack" || return 1
	cp -a resource/csdk/stack/include "${INCLUDEDIR}/${OCTBSTACK_INCLUDEDIR}" || return 1

	# FIXME: Necessary for 0.9.2
	touch "${INCLUDEDIR}/${OCTBSTACK_INCLUDEDIR}"/logger.h || return 1
}

mkdir -p ./depbuild || exit 1

# Download and build iotivity from tarball
cd ./depbuild || exit 1
	wget -O iotivity.tar.gz 'https://gerrit.iotivity.org/gerrit/gitweb?p=iotivity.git;a=snapshot;h='"${CSDK_REVISION}"';sf=tgz' || exit 1
	tar xzf iotivity.tar.gz || exit 1

	# There should only be one directory inside this directory, so using the wildcard evaluates
{'fraction_non_alphanumeric': 0.20715760495526497, 'fraction_numerical': 0.013305804083505391, 'mean_word_length': 3.014732965009208, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3544877', 'n_tokens_mistral': 1934, 'n_tokens_neox': 1686, 'n_words': 405}