<commit_before># Copyright (c) 2017 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Determine the lower-case name of the distro
distro := $(shell \
for file in /etc/os-release /usr/lib/os-release; do \
    if [ -e $$file ]; then \
        grep ^ID= $$file|cut -d= -f2-|tr -d '"'; \
        break; \
    fi \
done)

# A "CC system build" is either triggered by specifying
# a special target or via an environment variable.
cc_system_build_requested := $(foreach f,\
    build-cc-system install-cc-system,\
    $(findstring $(f),$(MAKECMDGOALS)))
ifneq (,$(strip $(cc_system_build_requested)))
    cc_system_build = yes
else
    cc_system_build = no
endif

# If this environment variable is set to any value,
# enable the CC system build.
ifneq (,$(CC_SYSTEM_BUILD))
    cc_system_build = yes
endif

TARGET = cc-runtime
DESTDIR :=
CCDIR := clear-containers

ifeq ($(cc_system_build),yes)
    # Configure the build for a standard Clear Containers system that is
    # using OBS-generated packages.
    PREFIX        := /usr
    BINDIR        := $(PREFIX)/bin
    DESTBINDIR    := /usr/local/bin
    QEMUBINDIR    := $(BINDIR)
    SYSCONFDIR    := /etc
    LOCALSTATEDIR := /var
else
    PREFIX        := /usr/local
    BINDIR        := $(PREFIX)/bin
    DESTBINDIR    := $(DESTDIR)/$(BINDIR)
    QEMUBINDIR    := $(BINDIR)
    SYSCONFDIR    := $(PREFIX)/etc
    LOCALSTATEDIR := $(PREFIX)/var
endif

LIBEXECDIR := $(PREFIX)/libexec
SHAREDIR := $(PREFIX)/share

PKGDATADIR := $(SHAREDIR)/$(CCDIR)
PKGLIBDIR := $(LOCALSTATEDIR)/lib/$(CCDIR)
PKGRUNDIR := $(LOCALSTATEDIR)/run/$(CCDIR)
PKGLIBEXECDIR := $(LIBEXECDIR)/$(CCDIR)

KERNELPATH := $(PKGDATADIR)/vmlinuz.container
IMAGEPATH := $(PKGDATADIR)/clear-containers.img

KERNELPARAMS :=

# The CentOS/RHEL hypervisor binary is not called qemu-lite
ifeq (,$(filter-out centos rhel,$(distro)))
QEMUCMD := qemu-system-x86_64
else
QEMUCMD := qemu-lite-system-x86_64
endif

QEMUPATH := $(QEMUBINDIR)/$(QEMUCMD)
MACHINETYPE := pc

SHIMCMD := cc-shim
SHIMPATH := $(PKGLIBEXECDIR)/$(SHIMCMD)

PROXYCMD := cc-proxy
PROXYURL := unix://$(PKGRUNDIR)/proxy.sock
PROXYPATH := $(PKGLIBEXECDIR)/$(PROXYCMD)

PAUSEROOTPATH := $(PKGLIBDIR)/runtime/bundles/pause_bundle
PAUSEBINRELPATH := bin/pause

GLOBALLOGPATH := $(PKGLIBDIR)/runtime/runtime.log

# Default number of vCPUs
DEFVCPUS := 1
# Default memory size in MiB
DEFMEMSZ := 2048

DEFDISABLEBLOCK := false

SED = sed

SOURCES := $(shell find . 2>&1 | grep -E '.*\.(c|h|go)$$')
VERSION := ${shell cat ./VERSION}
COMMIT_NO := $(shell git rev-parse HEAD 2> /dev/null || true)
COMMIT := $(if $(shell git status --porcelain --untracked-files=no),${COMMIT_NO}-dirty,${COMMIT_NO})

CONFIG_FILE = configuration.toml
CONFIG = config/$(CONFIG_FILE)
CONFIG_IN = $(CONFIG).in

DESTTARGET := $(abspath $(DESTBINDIR)/$(TARGET))

DESTCONFDIR := $(DESTDIR)/$(SYSCONFDIR)/$(CCDIR)
DESTCONFIG := $(abspath $(DESTCONFDIR)/$(CONFIG_FILE))

PAUSEDESTDIR := $(abspath $(DESTDIR)/$(PAUSEROOTPATH)/$(PAUSEBINRELPATH))

# list of variables the user may wish to override
USER_VARS += BINDIR
USER_VARS += CC_SYSTEM_BUILD
USER_VARS += DESTCONFIG
USER_VARS += DESTDIR
USER_VARS += DESTTARGET
USER_VARS += GLOBALLOGPATH
USER_VARS += IMAGEPATH
USER_VARS += MACHINETYPE
USER_VARS += KERNELPATH
USER_VARS += KERNELPARAMS
USER_VARS += LIBEXECDIR
USER_VARS += LOCALSTATEDIR
USER_VARS += PAUSEBINRELPATH
USER_VARS += PAUSEROOTPATH
USER_VARS += PKGDATADIR
USER_VARS += PKGLIBDIR
USER_VARS += PKGLIBEXECDIR
USER_VARS += PKGRUNDIR
USER_VARS += PREFIX
USER_VARS += PROXYPATH
USER_VARS += PROXYURL
USER_VARS += QEMUBINDIR
USER_VARS += QEMUCMD
USER_VARS += QEMUPATH
USER_VARS += SHAREDIR
USER_VARS += SHIMPATH
USER_VARS += SYSCONFDIR
USER_VARS += PAUSEDESTDIR
USER_VARS += DEFVCPUS
USER_VARS += DEFMEMSZ
USER_VARS += DEFDISABLEBLOCK


V              = @
Q              = $(V:1=)
QUIET_BUILD    = $(Q:@=@echo    '     BUILD   '$@;)
QUIET_CHECK    = $(Q:@=@echo    '     CHECK   '$@;)
QUIET_CLEAN    = $(Q:@=@echo    '     CLEAN   '$@;)
QUIET_CONFIG   = $(Q:@=@echo    '     CONFIG  '$@;)
QUIET_GENERATE = $(Q:@=@echo    '     GENERATE '$@;)
QUIET_INST     = $(Q:@=@echo    '     INSTALL '$@;)
QUIET_TEST     = $(Q:@=@echo    '     TEST    '$@;)

default: $(TARGET) $(CONFIG) pause install-git-hooks
.DEFAULT: default

build: default
build-cc-system: default
install-cc-system: install

define GENERATED_CODE
// WARNING: This file is auto-generated - DO NOT EDIT!
//
// Note that some variables are "var" to allow them to be modified
// by the tests.
package main

// commit is the git commit the runtime is compiled from.
var commit = "$(COMMIT)"

// version is the runtime version.
var version = "$(VERSION)"

const defaultHypervisorPath = "$(QEMUPATH)"
const defaultImagePath = "$(IMAGEPATH)"
const defaultKernelPath = "$(KERNELPATH)"
const defaultKernelParams = "$(KERNELPARAMS)"
const defaultMachineType = "$(MACHINETYPE)"
const defaultPauseRootPath = "$(PAUSEROOTPATH)"
const defaultProxyURL = "$(PROXYURL)"
const defaultRootDirectory = "$(PKGRUNDIR)"
const defaultRuntimeLib = "$(PKGLIBDIR)"
const defaultRuntimeRun = "$(PKGRUNDIR)"
const defaultShimPath = "$(SHIMPATH)"
const pauseBinRelativePath = "$(PAUSEBINRELPATH)"

const defaultVCPUCount uint32 = $(DEFVCPUS)
const defaultMemSize uint32 = $(DEFMEMSZ) // MiB
const defaultDisableBlockDeviceUse bool = $(DEFDISABLEBLOCK)

var defaultRuntimeConfiguration = "$(DESTCONFIG)"
var defaultProxyPath = "$(PROXYPATH)"
endef

export GENERATED_CODE


GENERATED_FILES += config-generated.go

config-generated.go: Makefile VERSION
	$(QUIET_GENERATE)echo "$$GENERATED_CODE" >$@

$(TARGET): $(SOURCES) $(GENERATED_FILES) Makefile | show-summary
	$(QUIET_BUILD)go build -i -o $@ .

pause: pause/pause.go
	$(QUIET_BUILD)go build -o pause/pause $<

.PHONY: \
	check \
	check-go-static \
	check-go-test \
	coverage \
	default \
	install \
	install-git-hooks \
	pause \
	show-header \
	show-summary \
	show-variables

$(TARGET).coverage: $(SOURCES) $(GENERATED_FILES) Makefile
	$(QUIET_TEST)go test -o $@ -covermode count<commit_msg>build: Ensure version details correct for system build<commit_after># Copyright (c) 2017 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Determine the lower-case name of the distro
distro := $(shell \
for file in /etc/os-release /usr/lib/os-release; do \
    if [ -e $$file ]; then \
        grep ^ID= $$file|cut -d= -f2-|tr -d '"'; \
        break; \
    fi \
done)

# A "CC system build" is either triggered by specifying
# a special target or via an environment variable.
cc_system_build_requested := $(foreach f,\
    build-cc-system install-cc-system,\
    $(findstring $(f),$(MAKECMDGOALS)))
ifneq (,$(strip $(cc_system_build_requested)))
    cc_system_build = yes
else
    cc_system_build = no
endif

# If this environment variable is set to any value,
# enable the CC system build.
ifneq (,$(CC_SYSTEM_BUILD))
    cc_system_build = yes
endif

TARGET = cc-runtime
DESTDIR :=
CCDIR := clear-containers

installing = $(findstring install,$(MAKECMDGOALS))

ifeq ($(cc_system_build),yes)
    # Configure the build for a standard Clear Containers system that is
    # using OBS-generated packages.
    PREFIX        := /usr
    BINDIR        := $(PREFIX)/bin
    DESTBINDIR    := /usr/local/bin
    QEMUBINDIR    := $(BINDIR)
    SYSCONFDIR    := /etc
    LOCALSTATEDIR := /var

    ifeq (,$(installing))
        # Force a rebuild to ensure version details are correct
        # (but only for a non-install build phase).
        EXTRA_DEPS = clean
    endif
else
    PREFIX        := /usr/local
    BINDIR        := $(PREFIX)/bin
    DESTBINDIR    := $(DESTDIR)/$(BINDIR)
    QEMUBINDIR    := $(BINDIR)
    SYSCONFDIR    := $(PREFIX)/etc
    LOCALSTATEDIR := $(PREFIX)/var
endif

LIBEXECDIR := $(PREFIX)/libexec
SHAREDIR := $(PREFIX)/share

PKGDATADIR := $(SHAREDIR)/$(CCDIR)
PKGLIBDIR := $(LOCALSTATEDIR)/lib/$(CCDIR)
PKGRUNDIR := $(LOCALSTATEDIR)/run/$(CCDIR)
PKGLIBEXECDIR := $(LIBEXECDIR)/$(CCDIR)

KERNELPATH := $(PKGDATADIR)/vmlinuz.container
IMAGEPATH := $(PKGDATADIR)/clear-containers.img

KERNELPARAMS :=

# The CentOS/RHEL hypervisor binary is not called qemu-lite
ifeq (,$(filter-out centos rhel,$(distro)))
QEMUCMD := qemu-system-x86_64
else
QEMUCMD := qemu-lite-system-x86_64
endif

QEMUPATH := $(QEMUBINDIR)/$(QEMUCMD)
MACHINETYPE := pc

SHIMCMD := cc-shim
SHIMPATH := $(PKGLIBEXECDIR)/$(SHIMCMD)

PROXYCMD := cc-proxy
PROXYURL := unix://$(PKGRUNDIR)/proxy.sock
PROXYPATH := $(PKGLIBEXECDIR)/$(PROXYCMD)

PAUSEROOTPATH := $(PKGLIBDIR)/runtime/bundles/pause_bundle
PAUSEBINRELPATH := bin/pause

GLOBALLOGPATH := $(PKGLIBDIR)/runtime/runtime.log

# Default number of vCPUs
DEFVCPUS := 1
# Default memory size in MiB
DEFMEMSZ := 2048

DEFDISABLEBLOCK := false

SED = sed

SOURCES := $(shell find . 2>&1 | grep -E '.*\.(c|h|go)$$')
VERSION := ${shell cat ./VERSION}
COMMIT_NO := $(shell git rev-parse HEAD 2> /dev/null || true)
COMMIT := $(if $(shell git status --porcelain --untracked-files=no),${COMMIT_NO}-dirty,${COMMIT_NO})

CONFIG_FILE = configuration.toml
CONFIG = config/$(CONFIG_FILE)
CONFIG_IN = $(CONFIG).in

DESTTARGET := $(abspath $(DESTBINDIR)/$(TARGET))

DESTCONFDIR := $(DESTDIR)/$(SYSCONFDIR)/$(CCDIR)
DESTCONFIG := $(abspath $(DESTCONFDIR)/$(CONFIG_FILE))

PAUSEDESTDIR := $(abspath $(DESTDIR)/$(PAUSEROOTPATH)/$(PAUSEBINRELPATH))

# list of variables the user may wish to override
USER_VARS += BINDIR
USER_VARS += CC_SYSTEM_BUILD
USER_VARS += DESTCONFIG
USER_VARS += DESTDIR
USER_VARS += DESTTARGET
USER_VARS += GLOBALLOGPATH
USER_VARS += IMAGEPATH
USER_VARS += MACHINETYPE
USER_VARS += KERNELPATH
USER_VARS += KERNELPARAMS
USER_VARS += LIBEXECDIR
USER_VARS += LOCALSTATEDIR
USER_VARS += PAUSEBINRELPATH
USER_VARS += PAUSEROOTPATH
USER_VARS += PKGDATADIR
USER_VARS += PKGLIBDIR
USER_VARS += PKGLIBEXECDIR
USER_VARS += PKGRUNDIR
USER_VARS += PREFIX
USER_VARS += PROXYPATH
USER_VARS += PROXYURL
USER_VARS += QEMUBINDIR
USER_VARS += QEMUCMD
USER_VARS += QEMUPATH
USER_VARS += SHAREDIR
USER_VARS += SHIMPATH
USER_VARS += SYSCONFDIR
USER_VARS += PAUSEDESTDIR
USER_VARS += DEFVCPUS
USER_VARS += DEFMEMSZ
USER_VARS += DEFDISABLEBLOCK


V              = @
Q              = $(V:1=)
QUIET_BUILD    = $(Q:@=@echo    '     BUILD   '$@;)
QUIET_CHECK    = $(Q:@=@echo    '     CHECK   '$@;)
QUIET_CLEAN    = $(Q:@=@echo    '     CLEAN   '$@;)
QUIET_CONFIG   = $(Q:@=@echo    '     CONFIG  '$@;)
QUIET_GENERATE = $(Q:@=@echo    '     GENERATE '$@;)
QUIET_INST     = $(Q:@=@echo    '     INSTALL '$@;)
QUIET_TEST     = $(Q:@=@echo    '     TEST    '$@;)

default: $(TARGET) $(CONFIG) pause install-git-hooks
.DEFAULT: default

build: default
build-cc-system: default
install-cc-system: install

define GENERATED_CODE
// WARNING: This file is auto-generated - DO NOT EDIT!
//
// Note that some variables are "var" to allow them to be modified
// by the tests.
package main

// commit is the git commit the runtime is compiled from.
var commit = "$(COMMIT)"

// version is the runtime version.
var version = "$(VERSION)"

const defaultHypervisorPath = "$(QEMUPATH)"
const defaultImagePath = "$(IMAGEPATH)"
const defaultKernelPath = "$(KERNELPATH)"
const defaultKernelParams = "$(KERNELPARAMS)"
const defaultMachineType = "$(MACHINETYPE)"
const defaultPauseRootPath = "$(PAUSEROOTPATH)"
const defaultProxyURL = "$(PROXYURL)"
const defaultRootDirectory = "$(PKGRUNDIR)"
const defaultRuntimeLib = "$(PKGLIBDIR)"
const defaultRuntimeRun = "$(PKGRUNDIR)"
const defaultShimPath = "$(SHIMPATH)"
const pauseBinRelativePath = "$(PAUSEBINRELPATH)"

const defaultVCPUCount uint32 = $(DEFVCPUS)
const defaultMemSize uint32 = $(DEFMEMSZ) // MiB
const defaultDisableBlockDeviceUse bool = $(DEFDISABLEBLOCK)

var defaultRuntimeConfiguration = "$(DESTCONFIG)"
var defaultProxyPath = "$(PROXYPATH)"
endef

export GENERATED_CODE


GENERATED_FILES += config-generated.go

config-generated.go: Makefile VERSION
	$(QUIET_GENERATE)echo "$$GENERATED_CODE" >$@

$(TARGET): $(EXTRA_DEPS) $(SOURCES) $(GENERATED_FILES) Makefile | show-summary
	$(QUIET_BUILD)go build -i -o $@ .

pause: pause/pause.go
	$(QUIET_BUILD)go build -o pause/pause $<

.PHONY: \
	check \
	check-go-static \
	check-go-test \
	coverage \
	default \
	install \
	install-git-hooks \
	pause \
	show-header \
	show-summary \
	show-variables

$(TARGET).coverage: $(SOURCES) $(GENERATED_FILES) Makefile
	$(QUIET_TEST)go test -o $@ -covermode count
{'fraction_non_alphanumeric': 0.13695245226506927, 'fraction_numerical': 0.004492699363534257, 'mean_word_length': 4.131002689204764, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3641743', 'n_tokens_mistral': 4773, 'n_tokens_neox': 4701, 'n_words': 1197}