# Copyright (C) 2012-2018, 2024  Luke T. Shumaker <lukeshu@parabola.nu>
#
# SPDX-License-Identifier: GPL-2.0-or-later
#
# This file is part of Parabola Libretools.
#
# Libretools is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# Libretools 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/>.

include $(dir $(lastword $(MAKEFILE_LIST)))/../../config.mk
include $(topsrcdir)/build-aux/Makefile.head.mk

pkglibexecdir = $(libexecdir)/libretools/chroot
pkglibdir = $(libdir)/libretools/chroot

libretools.src.devtools = makechrootpkg.in mkarchroot.in arch-nspawn.in
libretools.out.bins     = librechroot libremakepkg
libretools.out.libexecs = arch-nspawn chcleanup distcc-tool mkarchroot
libretools.out.libs     = $(libretools.src.sh) makechrootpkg.sh
files.out.int          += chcleanup.lib
files.sys.libretools   += $(bindir)/chcleanup # not in libretools.out.bins because explicit rule

$(srcdir)/makechrootpkg.sh.in: $(srcdir)/makechrootpkg.in
	sed -e '1s^.*^#!/hint/bash -euE^' -e '/^\s*main "$$@"\s*$$/d' < $< > $@

$(outdir)/chcleanup: $(srcdir)/chcleanup.in $(call at.path,$(outdir)/../lib/embedlib.sh)
	sed $$'/@EMBEDLIB.SH@/{r $(word 2,$^)\nd;}' < $< | $(libretools.edit) | install -m755 /dev/stdin $@

$(outdir)/distcc-tool.pot: LIBREXGETTEXT_FLAGS+=--simple=errusage

$(DESTDIR)$(bindir)/chcleanup: $(var.)bindir $(var.)libexecdir
	$(MKDIR_P) $(@D)
	ln -srfT $(DESTDIR)$(libexecdir)/libretools/chroot/chcleanup $@

at.subdirs += ../lib

include $(topsrcdir)/build-aux/Makefile.tail.mk
