[e67459]: configure  Maximize  Restore  History

Download this file

235 lines (198 with data), 4.7 kB

#!/bin/bash

#
# Enhanced Seccomp Library Configure Script
#
# Copyright (c) 2012 Red Hat <pmoore@redhat.com>
# Author: Paul Moore <pmoore@redhat.com>
#

#
# This library is free software; you can redistribute it and/or modify it
# under the terms of version 2.1 of the GNU Lesser General Public License as
# published by the Free Software Foundation.
#
# This library is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
# for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this library; if not, see <http://www.gnu.org/licenses>.
#

# configuration defaults
opt_prefix="/usr/local"
opt_sysinc_seccomp="yes"

# output files
cnf_mk_file="configure.mk"
cnf_h_file="configure.h"

####
# functions

function verify_deps() {
	[[ -z "$1" ]] && return
	if ! which "$1" >& /dev/null; then
		echo "error: install \"$1\" and include it in your \$PATH"
		exit 1
	fi
}

function msg_usage() {
	cat << EOF
Configure the enhanced seccomp library, libseccomp, for this system.

Usage:
  ./configure <options>

Options:
* general configuration
  -h, --help		display this help and exit
* installation configuration
  --prefix=PREFIX	installation base [/usr/local]
EOF
}

function msg_summary() {
	cat << EOF
 CONFIGURATION SUMMARY
  libseccomp version:	${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_MICRO}
  installation base:	$opt_prefix
  use system includes:	$opt_sysinc_seccomp
EOF
}

function msg_error() {
	echo "error: $@"
}

function cnf_mk_header() {
	echo "# generated by configure on $(date -R)" >> $cnf_mk_file
	echo "#   options: \"$opt_str\"" >> $cnf_mk_file
	echo "" >> $cnf_mk_file
}

function cnf_mk_footer() {
	echo "" >> $cnf_mk_file
}

function cnf_mk_entry() {
	[[ $# -ne 2 ]] && return
	case "$2" in
	no)
		echo "$1 = 0" >> $cnf_mk_file
		;;
	yes)
		echo "$1 = 1" >> $cnf_mk_file
		;;
	*)
		echo "$1 = \"$2\"" >> $cnf_mk_file
	esac
}

function cnf_h_header() {
	echo "/* generated by configure on $(date -R) */" >> $cnf_h_file
	echo "/*   options: \"$opt_str\" */" >> $cnf_h_file
	echo "" >> $cnf_h_file
	echo "#ifndef _CONFIGURE_H" >> $cnf_h_file
	echo "#define _CONFIGURE_H" >> $cnf_h_file
	echo "" >> $cnf_h_file
}

function cnf_h_footer() {
	echo "" >> $cnf_h_file
	echo "#endif" >> $cnf_h_file
	echo "" >> $cnf_h_file
}

function cnf_h_entry() {
	[[ $# -ne 2 ]] && return
	case "$2" in
	no)
		echo "#undef $1" >> $cnf_h_file
		;;
	yes)
		echo "#define $1	1" >> $cnf_h_file
		;;
	*)
		echo "#define $1	$2" >> $cnf_h_file
	esac
}

function cnf_reset() {
	cat /dev/null > $cnf_mk_file
	cat /dev/null > $cnf_h_file
}

function cnf_header() {
	cnf_mk_header
	cnf_h_header
}

function cnf_entry() {
	cnf_mk_entry "$1" "$2"
	cnf_h_entry "$1" "$2"
}

function cnf_footer() {
	cnf_mk_footer
	cnf_h_footer
}

function tmpl_filter() {
	name="echo \$$1"
	val="$(eval $name)"
	cat - | sed -e 's/%%'"$1"'%%/'"${val//\//\\/}"'/g;'
}

####
# main

#
# setup
#

# verify script dependencies
verify_deps getopt

# parse the command line options
opt_str="$@"
opt=$(getopt -n "$0" --options "h" --longoptions "help,prefix:" -- "$@")
eval set -- "$opt"
while [[ $# -gt 0 ]]; do
	case "$1" in
	--prefix)
		opt_prefix="$2"
		shift 2
		;;
	-h|--help)
		msg_usage
		exit 0
		;;
	--)
		shift
		;;
	*)
		msg_usage
		exit 1
	esac
done

# validate the options
if [[ ! -d $opt_prefix ]]; then
	msg_error "install prefix ($opt_prefix) is not a directory"
	exit 1
fi

#
# automatic configuration
#

# system seccomp includes
if [[ -r "/usr/include/linux/seccomp.h" ]]; then
	opt_sysinc_seccomp="yes"
else
	opt_sysinc_seccomp="no"
fi

# generate the version files
. ./version_info
VERSION_RELEASE="${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_MICRO}"
rm -f ./version_info.mk
echo "# generated by configure on $(date -R)" >> ./version_info.mk
echo "VERSION_MAJOR=$VERSION_MAJOR" >> ./version_info.mk
echo "VERSION_MINOR=$VERSION_MINOR" >> ./version_info.mk
echo "VERSION_MICRO=$VERSION_MICRO" >> ./version_info.mk
echo "VERSION_RELEASE=$VERSION_RELEASE" >> ./version_info.mk

# generate the pkg-config metadata
INSTALL_PREFIX="$opt_prefix"
rm -f ./libseccomp.pc
cat ./libseccomp.pc.in | \
	tmpl_filter INSTALL_PREFIX | tmpl_filter VERSION_RELEASE \
	>> ./libseccomp.pc

#
# finish
#

# reset the configuration files
cnf_reset
cnf_header

# output the configuration files
cnf_mk_entry "CONF_INSTALL_PREFIX" "$opt_prefix"
cnf_entry "CONF_SYSINC_SECCOMP" "$opt_sysinc_seccomp"

# configuration footer
cnf_footer

# display a summary and exit
msg_summary
exit 0

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks