Skip to content

Instantly share code, notes, and snippets.

@svagionitis
Created May 11, 2017 14:07
Show Gist options
  • Save svagionitis/3668d8bb051be04ba9b5a6d5823d16ff to your computer and use it in GitHub Desktop.
Save svagionitis/3668d8bb051be04ba9b5a6d5823d16ff to your computer and use it in GitHub Desktop.
tpm-tools build script
#!/bin/sh -ex
mkdir -p sysroot
PREFIX_DIR=$(readlink -e sysroot)
mkdir -p $PREFIX_DIR/include
INCLUDE_DIR=$(readlink -e $PREFIX_DIR/include/)
mkdir -p $PREFIX_DIR/lib
LIB_DIR=$(readlink -e $PREFIX_DIR/lib/)
mkdir -p $LIB_DIR/pkgconfig
PKG_CONFIG_PATH=$(readlink -e $LIB_DIR/pkgconfig/)
mkdir -p manifest
MF_DIR=$(readlink -e manifest)
mkdir -p $PREFIX_DIR/bin
BIN_DIR=$(readlink -e $PREFIX_DIR/bin/)
mkdir -p $PREFIX_DIR/share
DATA_DIR=$(readlink -e $PREFIX_DIR/share/)
mkdir -p $PREFIX_DIR/etc
CONFIG_DIR=$(readlink -e $PREFIX_DIR/etc/)
mkdir -p src
SOURCE_DIR=$(readlink -e src)
mkdir -p build
BUILD_DIR=$(readlink -e build)
COMMON_ARGS="--prefix=${PREFIX_DIR} --enable-shared --disable-static --host=x86_64-linux-gnu"
MAKE="make -j2"
modules="\
trousers \
tpm_tools"
export PKG_CONFIG_PATH
CFLAGS="-O0 -g -pthread -I${INCLUDE_DIR} -L${LIB_DIR}"
LD=gold
export CFLAGS
export LD
# run autotools configure out of tree
prep() {
local S
local B
S=$1
B=$2
cd $S
libtoolize
if [ ! -e configure ]; then
if [ -e bootstrap.sh ]; then
sh ./bootstrap.sh
else
NOCONFIGURE=1 ./autogen.sh
fi
fi
mkdir -p $B
cd ${B}
echo ${EXTRA_CONFIGURE_ARGS}
${S}/configure ${COMMON_ARGS} ${EXTRA_CONFIGURE_ARGS}
EXTRA_CONFIGURE_ARGS=""
}
build_git_autoconf_module() {
local module
local repo
local branch
local S
local B
module=$1
repo=$2
branch=$3
S=${SOURCE_DIR}/${module}
B=${BUILD_DIR}/${module}
if [ ! -d $S ]; then
cd ${SOURCE_DIR}
# Swallow clone
#git clone --depth 1 ${repo} $S
git clone ${repo} $S
(cd $S
local current_branch
current_branch=$(git rev-parse --abbrev-ref HEAD)
if [ $current_branch != $branch ]; then
git checkout -b $branch origin/$branch
fi
# not everybody needs this, but it doesn't hurt
git submodule init
git submodule update
)
fi
if [ ! -e $B/Makefile ]; then
prep $S $B
fi
cd $B
$MAKE
make install
}
build_tpm() {
build_git_autoconf_module $1 "git://git.code.sf.net/p/trousers/$1" "master"
}
trousers() {
build_tpm "trousers"
}
tpm_tools() {
build_tpm "tpm-tools"
}
help() {
echo "the automagic tpm trousers stack builder"
echo
echo "build all: <$0>"
echo
echo "build a module: <$0> <module>"
echo
echo "where module is one of:"
for m in $modules; do
echo $m
done
}
check_and_build() {
local module
local manifest
module=$1
manifest=$MF_DIR/$module
if [ ! -e $manifest ]; then
echo building $module
$module
touch $manifest
else
echo not touching $module
fi
}
if [ "$#" -eq 0 ]; then
for m in $modules; do
echo checking $m
check_and_build $m
done
else
$1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment