jw-pkg/make/topdir.mk
Jan Lindemann 3e897f4df8 lib.Distro, ExecContext: Add classes, refactor lib.distro
The code below lib.distro, as left behind by the previous commit, is
geared towards being directly used as a command-line API. This commit
introduces the abstract base class Distro, a proxy for
distribution-specific interactions. The proxy abstracts distro
specifics into an API with proper method prototypes, not
argparse.Namespace contents, and can thus be more easily driven by
arbitrary code.

The Distro class is initialized with a member variable of type
ExecContext, another new class introduced by this commit. It is
designed to abstract the communication channel to the distribution
instance.  Currently only one specialization exists, Local, which
interacts with the distribution and root file system it is running
in, but is planned to be subclassed to support interaction via SSH,
serial, chroot, or chains thereof.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-03-06 14:56:46 +01:00

230 lines
6.4 KiB
Makefile

all: config
install: topdir.install
clean: topdir.clean
distclean: topdir.distclean
config:
mrproper:distclean topdir.mrproper
ifeq ($(ORDERED_SUBDIRS),)
SUBDIRS ?= $(dir $(wildcard $(addsuffix /Makefile,\
inst/pre make scripts contrib src libsrc \
tools include lib bin util exe plugins conf config cfg \
images htdocs tmpl doc test inst/post)))
endif
ifeq ($(USE_USER_URL),true)
JANWARE_USER_PREFIX = $(JANWARE_USER)@
endif
PROJECT_DESCR = $(TOPDIR)/make/project.conf
GIT_DESCR = $(TOPDIR)/.git/description
GIT_MAIN_BRANCH ?= master
OPT_JANWARE_PROJECT ?= -j
INTERACTIVE ?= auto
PKG_MANAGER ?= $(JW_PKG_PY) --interactive=$(INTERACTIVE) distro
ifeq ($(OPT_JANWARE_PROJECT),-j)
REMOTE_GIT_FLAVOUR ?= proj
else
OPT_JANWARE_PROJECT =
REMOTE_GIT_FLAVOUR ?= priv
endif
ifneq ($(wildcard $(TOPDIR)/make/defs.mk),)
include $(TOPDIR)/make/defs.mk
endif
include $(JWBDIR)/make/defs.mk
REMOTE_GIT_DIR = /srv/git/$(JANWARE_USER)/$(REMOTE_GIT_FLAVOUR)/$(PROJECT)
REMOTE_GIT_URL = ssh://$(JANWARE_USER_PREFIX)git.janware.com$(REMOTE_GIT_DIR)
ifneq ($(DONT_CHECK_PREREQ_DONE),true)
ifndef PREREQ
PREREQ := $(call proj_query,pkg-requires --no-version --no-subpackages --subsections=jw --delimiter=' ' build $(PROJECT))
endif
ifndef PREREQ_DIRS
PREREQ_DIRS := $(call proj_query,proj-dir $(PREREQ))
endif
PREREQ_DIRS_DONE := $(addsuffix /dirs-all.done,$(filter-out $(TOPDIR) /opt/%,$(PREREQ_DIRS)))
endif
ifneq ($(SUBDIRS_TO_ITERATE),)
ifeq ($(MAKECMDGOALS),)
SUBDIR_TARGETS = all
else
SUBDIR_TARGETS = $(filter $(ALLOWED_SUBDIR_TARGETS),$(MAKECMDGOALS))
endif
endif
include $(JWBDIR)/make/dirs.mk
include $(JWBDIR)/make/rpmdist.mk
include $(JWBDIR)/make/rules.mk
include $(JWBDIR)/make/doc-rules.mk
include $(JWBDIR)/make/list-files.mk
include $(JWBDIR)/make/projects+project.mk
STREAMLINE_PROJECT ?= bash $(JWB_SCRIPT_DIR)/streamline-project.sh
INSTALLED_TOPDIR_FILES = $(addprefix $(INSTALL_DOCDIR)/, $(DOCS))
local-%:
find . -name $@.mk | \
while read f; do (\
cd `dirname $$f` ;\
$(RM) -f local.mk ;\
ln -s `basename $$f` local.mk ;\
) done
unlocal:
$(RM) -f $(shell find . -name local.mk)
topdir.distclean: topdir.clean
$(RM) -rf dist *.dist
topdir.clean:
$(RM) -rf *.done
topdir.mrproper: topdir.distclean
find . -name '*.rep' | xargs -r $(RM) -f
topdir.install: prefix.done $(INSTALLED_TOPDIR_FILES)
do-install-links:
$(Q)@cwd=$(shell $(PWD)); \
echo "o in $(INSTALL_LIBDIR):" ;\
find lib -name '*.so' -o -name '*.so.*' -o -name '*.a' -o -name '*.dll' | \
$(SED) 's%^\./%%' | \
while read f; do \
cd $(INSTALL_LIBDIR) && { \
echo " sudo ln -sf $$cwd/$$f" ; \
sudo ln -sf $$cwd/$$f; \
}; \
done; \
echo "o in $(INSTALL_EXEDIR):" ;\
find bin -type f -a -perm -u+x | \
$(SED) 's%^\./%%' | \
while read f; do \
cd $(INSTALL_EXEDIR) && { \
echo " sudo ln -sf $$cwd/$$f" ; \
sudo ln -sf $$cwd/$$f; \
}; \
done ;\
echo "o in $(INSTALL_HDRDIR):" ;\
find include -name '*.h' | \
$(SED) 's%^\./%%' | \
while read f; do \
cd $(INSTALL_HDRDIR) && { \
echo " sudo ln -sf $$cwd/$$f" ; \
sudo ln -sf $$cwd/$$f; \
}; \
done; \
echo "o in $(INSTALL_MAKEDIR):" ;\
find make -name '*.mk' | \
$(SED) 's%^\./%%' | \
while read f; do \
cd $(INSTALL_MAKEDIR) && { \
echo " sudo ln -sf $$cwd/$$f" ; \
sudo ln -sf $$cwd/$$f; \
}; \
done; \
install-links:
DEVELOPMENT=false make do-install-links
get-maintainer: git-get-maintainer
git-init: git-init.done $(GIT_DESCR)
git-init-from-cvs: git-init
$(LIST_VCS_FILES) -f | xargs git add
git commit -m "First commit of $(RPM_VERSION)"
git-config:
git config --global user.name || git config --global user.name "$(FULL_NAME)"
git config --global user.email || git config --global user.email $(JANWARE_USER)@janware.com
git remote -v | grep -q '^origin' || git remote add origin $(REMOTE_GIT_URL)
git remote -v | grep -q "^origin *$(REMOTE_GIT_URL)" || git remote set-url --push origin $(REMOTE_GIT_URL)
git-clone-to-remote:
ssh $(JANWARE_USER)@git.janware.com "/opt/jw-pkg/bin/git-srv-admin.sh $(OPT_JANWARE_PROJECT) create-personal-project $(PROJECT)"
make git-config
git push --set-upstream origin $(GIT_MAIN_BRANCH)
git push --all $(REMOTE_GIT_URL)
make git-update-project-description
git-import: git-init git-config
git add -A
git status
git commit -am "First commit"
git-init-remote: git-import git-clone-to-remote
git-descr: $(GIT_DESCR)
git-update-project-description:
ssh $(JANWARE_USER)@git.janware.com "/opt/jw-pkg/bin/git-srv-admin.sh $(OPT_JANWARE_PROJECT) update-descriptions $(PROJECT)"
projects-%:
$(PYTHON) $(JWB_SCRIPT_DIR)/jw-pkg.py projects build $* $(PROJECT)
install-deps-devel:
sudo zypper in $(shell echo $(RPM_REQUIRES_DEVEL) | sed "s/ *= */-/g; s/ [^ ]\+-__NEXT_VERSION__//")
streamline:
$(STREAMLINE_PROJECT)
$(GIT_DESCR): $(PROJECT_DESCR_FILE)
/bin/bash $(JWB_SCRIPT_DIR)/ini-section.sh summary $< | tee $@.tmp
mv $@.tmp $@
git-init.done:
$(Q)if [ -e .git ]; then \
echo $(TOPDIR)/.git already exists, not running git init ;\
else \
@echo git init ;\
git init; \
fi
touch $@
prefix.done:
mkdir -p $(PREFIX)
touch $@
echo-build-deps:
$(Q)echo $(call proj_query, required-os-pkg --quote --flavours "build" $(PROJECT))
git-ssh-%:
bash -c "`git remote get-url --push $* | sed 's|ssh://||; s|\([^/]\+\)/\(.*\)|LC_CDPATH=/\2 ssh -o SendEnv=LC_CDPATH \1|'`"
git-ssh: git-ssh-origin
git-get-official:
make git-get-devops
git-get-maintainer:
make git-get-$(call proj_query,getval global jw-maintainer)
git-get-%:
PGIT_SH_PROJECTS=. $(PGIT_SH) get --refspec $*:$(GIT_MAIN_BRANCH):current-branch
get-%: git-get-%
@:
pkg-manager-refresh:
$(PKG_MANAGER) refresh
pkg-install-build-deps:
$(PKG_MANAGER) install $(BASE_PKGS) $(shell $(proj_query_cmd) required-os-pkg --quote --skip-excluded --flavours "build" $(PROJECT))
pkg-install-release-deps:
$(PKG_MANAGER) install $(BASE_PKGS) $(shell $(proj_query_cmd) required-os-pkg --quote --skip-excluded --flavours "build run release" $(PROJECT))
pkg-install-testbuild-deps:
$(PKG_MANAGER) install $(BASE_PKGS) $(shell $(proj_query_cmd) pkg-requires --delimiter=' ' --no-version build,run,release $(PROJECT))
echo-hash:
$(Q)/bin/bash $(PKG_SH_EXE) hash
recache-vars:
rm -f $(TOPDIR)/make clean-cache cache