summaryrefslogtreecommitdiff
path: root/configure
diff options
context:
space:
mode:
authorPaul Moore <pmoore@redhat.com>2012-03-30 17:47:22 -0400
committerPaul Moore <pmoore@redhat.com>2012-04-02 16:03:39 -0400
commit2dca3086e80e8054995be51542cd9d30dc54b9ae (patch)
tree08d837bac9186d3eb6eab9e124dc2e73ea80222d /configure
parent50ba41dbc4ea30ca8aa2a02c0cfe8a4c4d9024a8 (diff)
downloadlibseccomp-2dca3086e80e8054995be51542cd9d30dc54b9ae.tar.gz
build: introduce a configure script
Not really all that useful right now, but we need a way to determine if the system has the updated seccomp header files. Signed-off-by: Paul Moore <pmoore@redhat.com>
Diffstat (limited to 'configure')
-rwxr-xr-xconfigure210
1 files changed, 210 insertions, 0 deletions
diff --git a/configure b/configure
new file mode 100755
index 0000000..5998120
--- /dev/null
+++ b/configure
@@ -0,0 +1,210 @@
+#!/bin/bash
+
+#
+# Enhanced Seccomp Library Configure Script
+#
+# Copyright (c) 2012 Red Hat <pmoore@redhat.com>
+# Author: Paul Moore <pmoore@redhat.com>
+#
+
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of version 2 of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. 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
+ 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
+}
+
+####
+# 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
+
+#
+# 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