#!/usr/bin/make -f

DH_VERBOSE=1
DH_GOPKG=github.com/opencontainers/runc
BUILDDIR := $(shell pwd)
DESTDIR := $(BUILDDIR)/debian/tmp
SBINDIR := /usr/lib/cri-o-runc/sbin
LDFLAGS=-extldflags '-Wl,-z,relro -Wl,--as-needed -Wl,-z,now'
BUILD_INFO=$(shell date +%s)
ifneq (,$(wildcard /usr/lib/go-1.19/bin/go))
        GO_BINARY := /usr/lib/go-1.19/bin/go
else
        GO_BINARY := /usr/bin/go
endif
CGO_CFLAGS='-g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -ffat-lto-objects -fexceptions -fasynchronous-unwind-tables -fstack-protector-strong -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64'
GO := GOPATH=$(BUILDDIR) GO111MODULE=off $(GO_BINARY)
GO_BUILD := CGO_CFLAGS=$(CGO_CFLAGS) $(GO) build -buildmode pie -ldflags "$(LDFLAGS)"
UPSTREAM_TAG=v1.1.12

%:
	dh_clean
	rm -rf $(BUILDDIR)/src
	dh $@ --buildsystem=golang --with=golang

override_dh_auto_configure:
	# Include vendored dependencies.
	cp -rp $(BUILDDIR)/vendor $(BUILDDIR)/src
	mkdir -p $(BUILDDIR)/src/github.com/opencontainers
	ln -s $(BUILDDIR) $(BUILDDIR)/src/$(DH_GOPKG)

override_dh_auto_build:
	$(GO_BUILD) -tags "apparmor seccomp" -o runc $(DH_GOPKG)
	rm -rf $(BUILDDIR)/obj-*-linux-gnu

override_dh_auto_install:
	install -dp $(DESTDIR)$(SBINDIR)
	make BINDIR=$(DESTDIR)$(SBINDIR) install

override_dh_auto_test:

override_dh_golang:
