Skip to content

Commit

Permalink
Rely on GNUInstallDirs for definition of libdir and adopt it for inst…
Browse files Browse the repository at this point in the history
…allation
  • Loading branch information
ckreibich committed Nov 19, 2020
1 parent f99e326 commit 80d0bec
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 24 deletions.
22 changes: 13 additions & 9 deletions CMakeLists.txt
@@ -1,10 +1,14 @@
cmake_minimum_required(VERSION 2.6.3 FATAL_ERROR)
project(ZeekControl C CXX)

include(GNUInstallDirs)
include(cmake/CommonCMakeConfig.cmake)

file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/VERSION" VERSION LIMIT_COUNT 1)

set(PREFIX "${CMAKE_INSTALL_PREFIX}")
set(LIBDIR "${CMAKE_INSTALL_FULL_LIBDIR}")
set(PY_MOD_INSTALL_DIR "${CMAKE_INSTALL_FULL_LIBDIR}/zeekctl")
set(ZEEKSCRIPTDIR "${ZEEK_SCRIPT_INSTALL_PATH}")
set(ETC "${ZEEK_ETC_INSTALL_DIR}")

Expand Down Expand Up @@ -107,7 +111,7 @@ InstallShellScript(share/zeekctl/scripts/helpers bin/helpers/top)
InstallShellScript(share/zeekctl/scripts/postprocessors bin/postprocessors/summarize-connections)

install(DIRECTORY ZeekControl
DESTINATION lib/zeekctl
DESTINATION ${LIBDIR}/zeekctl
PATTERN "options.py" EXCLUDE
PATTERN "ssh_runner.py" EXCLUDE
PATTERN "version.py" EXCLUDE
Expand All @@ -123,13 +127,13 @@ configure_file(ZeekControl/ssh_runner.py
configure_file(ZeekControl/version.py
${CMAKE_CURRENT_BINARY_DIR}/ZeekControl/version.py @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ZeekControl/options.py
DESTINATION lib/zeekctl/ZeekControl)
DESTINATION ${LIBDIR}/zeekctl/ZeekControl)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ZeekControl/ssh_runner.py
DESTINATION lib/zeekctl/ZeekControl)
DESTINATION ${LIBDIR}/zeekctl/ZeekControl)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ZeekControl/version.py
DESTINATION lib/zeekctl/ZeekControl)
DESTINATION ${LIBDIR}/zeekctl/ZeekControl)
install(DIRECTORY ZeekControl/plugins
DESTINATION lib/zeekctl)
DESTINATION ${LIBDIR}/zeekctl)

# Special cases where execute permission isn't applicable.
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/bin/helpers/to-bytes.awk
Expand Down Expand Up @@ -236,8 +240,8 @@ InstallPackageConfigFile(
InstallSymlink("${CMAKE_INSTALL_PREFIX}/bin/zeek-wrapper" "${CMAKE_INSTALL_PREFIX}/bin/broctl")

if ( NOT BINARY_PACKAGING_MODE )
# Need to remove pre-existing $prefix/lib/broctl dir from previous installs.
set(_broctl_lib_dst ${CMAKE_INSTALL_PREFIX}/lib/broctl)
# Need to remove pre-existing broctl dir from previous installs.
set(_broctl_lib_dst ${LIBDIR}/broctl)

install(CODE "
if ( \"\$ENV{DESTDIR}\" STREQUAL \"\" )
Expand All @@ -250,9 +254,9 @@ if ( NOT BINARY_PACKAGING_MODE )
")
endif ()

InstallSymlink("./zeekctl" "${CMAKE_INSTALL_PREFIX}/lib/broctl")
InstallSymlink("./zeekctl" "${LIBDIR}/broctl")

install(DIRECTORY BroControl DESTINATION lib/zeekctl)
install(DIRECTORY BroControl DESTINATION ${LIBDIR}/zeekctl)

########################################################################
## Packaging Setup
Expand Down
4 changes: 3 additions & 1 deletion ZeekControl/config.py
Expand Up @@ -53,9 +53,10 @@ def add_node(self, node):


class Configuration:
def __init__(self, basedir, cfgfile, zeekscriptdir, ui, state=None):
def __init__(self, basedir, libdir, cfgfile, zeekscriptdir, ui, state=None):
self.ui = ui
self.basedir = basedir
self.libdir = libdir
self.cfgfile = cfgfile
self.zeekscriptdir = zeekscriptdir
global Config
Expand Down Expand Up @@ -94,6 +95,7 @@ def _initialize_options(self):
self.init_option("zeekbase", self.basedir)
self.init_option("zeekscriptdir", self.zeekscriptdir)
self.init_option("version", VERSION)
self.init_option("libdir", self.libdir)

# Initialize options that are not already set.
errors = False
Expand Down
7 changes: 4 additions & 3 deletions ZeekControl/options.py
Expand Up @@ -173,11 +173,12 @@ def __init__(self, name, default, type, category, dontinit, description, legacy_
Option("StaticDir", "${ZeekBase}/share/zeekctl", "string", Option.AUTOMATIC, False,
"Directory for static, arch-independent files."),

Option("LibDir", "${ZeekBase}/lib", "string", Option.AUTOMATIC, False,
Option("LibDir", "", "string", Option.AUTOMATIC, False,
"Directory for library files."),
# XXX Do we still need the following? --cpk
Option("LibDir64", "${ZeekBase}/lib64", "string", Option.AUTOMATIC, False,
"Directory for 64-bit architecture library files."),
Option("LibDirInternal", "${ZeekBase}/lib/zeekctl", "string", Option.AUTOMATIC, False,
Option("LibDirInternal", "${LibDir}/zeekctl", "string", Option.AUTOMATIC, False,
"Directory for zeekctl-specific library files."),
Option("TmpDir", "${SpoolDir}/tmp", "string", Option.AUTOMATIC, False,
"Directory for temporary data."),
Expand All @@ -187,7 +188,7 @@ def __init__(self, name, default, type, category, dontinit, description, legacy_
"Directory where statistics are kept."),
Option("PluginDir", "${LibDirInternal}/plugins", "string", Option.AUTOMATIC, False,
"Directory where standard zeekctl plugins are located."),
Option("PluginZeekDir", "${ZeekBase}/lib/zeek/plugins", "string", Option.AUTOMATIC, False,
Option("PluginZeekDir", "${LibDir}/zeek/plugins", "string", Option.AUTOMATIC, False,
"Directory where Zeek plugins are located. ZeekControl will search this directory tree for zeekctl plugins that are provided by any Zeek plugin.", "PluginBroDir"),

Option("TraceSummary", "${bindir}/trace-summary", "string", Option.AUTOMATIC, False,
Expand Down
1 change: 1 addition & 0 deletions ZeekControl/version.py
Expand Up @@ -6,3 +6,4 @@
ZEEKBASE = "@PREFIX@"
CFGFILE = "@ETC@/zeekctl.cfg"
ZEEKSCRIPTDIR = "@ZEEKSCRIPTDIR@"
LIBDIR = "@LIBDIR@"
6 changes: 4 additions & 2 deletions ZeekControl/zeekctl.py
Expand Up @@ -62,11 +62,13 @@ def wrapper(self, *args, **kwargs):
return wrapper

class ZeekCtl(object):
def __init__(self, basedir=version.ZEEKBASE, cfgfile=version.CFGFILE, zeekscriptdir=version.ZEEKSCRIPTDIR, ui=TermUI(), state=None):
def __init__(self, basedir=version.ZEEKBASE, libdir=version.LIBDIR, cfgfile=version.CFGFILE,
zeekscriptdir=version.ZEEKSCRIPTDIR, ui=TermUI(), state=None):
self.ui = ui
self.zeekbase = basedir
self.libdir = libdir

self.config = config.Configuration(self.zeekbase, cfgfile, zeekscriptdir, self.ui, state)
self.config = config.Configuration(self.zeekbase, self.libdir, cfgfile, zeekscriptdir, self.ui, state)

# Remove all log handlers (set by any previous calls to logging.*)
logging.getLogger().handlers = []
Expand Down
2 changes: 1 addition & 1 deletion bin/zeekctl.in
Expand Up @@ -8,7 +8,7 @@ import time
import logging

# This is needed so that we can import ZeekControl.
sys.path.insert(0, "@PREFIX@/lib/zeekctl")
sys.path.insert(0, "@LIBDIR@/zeekctl")

from ZeekControl.zeekctl import ZeekCtl, ZeekControlError, CommandSyntaxError
from ZeekControl import zeekcmd
Expand Down
3 changes: 2 additions & 1 deletion bin/zeekctld.in
@@ -1,11 +1,12 @@
#!/usr/bin/env python

ZeekBase = "@PREFIX@"
LibDir = "@LIBDIR@"

import os
import sys

sys.path = [os.path.join(ZeekBase, "lib/zeekctl")] + sys.path
sys.path = [os.path.join(LibDir, "zeekctl")] + sys.path

from ZeekControl import zeekctld

Expand Down
9 changes: 6 additions & 3 deletions configure
Expand Up @@ -31,6 +31,7 @@ Usage: $0 [OPTION]... [VAR=VALUE]...
--python-install-dir the desired installation directory for
any auxiliary python modules (if present)
[PREFIX/lib/zeekctl]
--libdir=PATH installation directory for library files [PREFIX/lib]
Required Packages in Non-Standard Locations:
--with-pcap=PATH path to libpcap install root
Expand Down Expand Up @@ -67,8 +68,7 @@ append_cache_entry () {
builddir=build
prefix=/usr/local/zeek
CMakeCacheEntries=""
append_cache_entry CMAKE_INSTALL_PREFIX PATH $prefix
append_cache_entry PY_MOD_INSTALL_DIR PATH $prefix/lib/zeekctl
append_cache_entry CMAKE_INSTALL_PREFIX PATH $prefix
append_cache_entry ZEEK_SCRIPT_INSTALL_PATH STRING $prefix/share/zeek
append_cache_entry CPACK_SOURCE_IGNORE_FILES STRING

Expand All @@ -90,8 +90,11 @@ while [ $# -ne 0 ]; do
--prefix=*)
prefix=$optarg
append_cache_entry CMAKE_INSTALL_PREFIX PATH $optarg
append_cache_entry PY_MOD_INSTALL_DIR PATH $optarg/lib/zeekctl
;;
--libdir=*)
libdir=$optarg
append_cache_entry CMAKE_INSTALL_LIBDIR PATH $optarg
;;
--scriptdir=*)
append_cache_entry ZEEK_SCRIPT_INSTALL_PATH STRING $optarg
user_set_scriptdir="true"
Expand Down
13 changes: 9 additions & 4 deletions testing/Scripts/build-zeek
Expand Up @@ -35,14 +35,19 @@ build_zeek() {
if [ -n "${ZEEKCTL_TEST_USEBUILD}" ]; then
# Reuse a previous build in the default Zeek build directory.
BUILDPREFIX=build
# Rebuild using a new prefix (use ZEEKCTL_TEST_BUILDARGS to specify
# any other flags that were used for the previous build).
./configure --prefix="${INSTALLPREFIX}" ${ZEEKCTL_TEST_BUILDARGS}
# Rebuild using a new prefix (use ZEEKCTL_TEST_BUILDARGS to
# specify any other flags that were used for the previous
# build). Also specify a libdir so we know we're using "lib"
# as our library prefix -- it's used throughout the testsuite.
./configure --prefix="${INSTALLPREFIX}" --libdir="${INSTALLPREFIX}/lib" \
${ZEEKCTL_TEST_BUILDARGS}
else
# Use a build directory specifically for zeekctl tests.
BUILDPREFIX=${ZEEKCTLBUILDDIR}/zeek-build
# Additional configure options are used here to reduce the build size.
./configure --builddir=${BUILDPREFIX} --prefix="${INSTALLPREFIX}" --build-type=Release --disable-auxtools ${ZEEKCTL_TEST_BUILDARGS}
./configure --builddir=${BUILDPREFIX} --prefix="${INSTALLPREFIX}" \
--libdir="${INSTALLPREFIX}/lib" --build-type=Release \
--disable-auxtools ${ZEEKCTL_TEST_BUILDARGS}
fi

test $? -ne 0 && return 1
Expand Down

0 comments on commit 80d0bec

Please sign in to comment.