Add generic machinery to dynamically create files in $(TOPDIR). The need arises because version controlled configuration files for linters are going to be introduced.
For that, this commit introduces a variable $(TD_GENERATE_FILES), which target all depends on, and which topdir.clean removes.
It defaults to another variable also introduced by this commit, $(TD_COPY_FILES), which in turn defaults to $(TOPDIR)/conf/topdir.
This commit also adds support for JW_PKG_TOPDIR_COPY_PATH. It supports a PATH-style syntax, which allows pointing to multiple directories to be checked for source files. If they exist, they will be appended to the files found in $(TOPDIR)/conf/topdir after copying. Defining arbitray files to copy is not supported before security implications during CI runs are better understood.
Having the copy prerequisites work comes at the cost of having to add .SECONDEXPANSION. Since it's limited to the toplevel Makefile, I suppose that's acceptable.
Signed-off-by: Jan Lindemann <jan@janware.com>
304 lines
8.2 KiB
Makefile
# Need second expansion for TD_COPY_XXX concatenation rule to work
|
|
.SECONDEXPANSION:
|
|
|
|
.PHONY: \
|
|
FORCE \
|
|
all \
|
|
format \
|
|
check-syntax \
|
|
check-format \
|
|
check \
|
|
install \
|
|
clean \
|
|
distclean \
|
|
config \
|
|
mrproper \
|
|
unlocal \
|
|
topdir.distclean \
|
|
topdir.clean \
|
|
topdir.mrproper \
|
|
topdir.install \
|
|
do-install-links \
|
|
install-links \
|
|
get-maintainer \
|
|
get-official \
|
|
get-pub \
|
|
git-init \
|
|
git-init-from-cvs \
|
|
git-config \
|
|
git-clone-to-remote \
|
|
git-import \
|
|
git-init-remote \
|
|
git-descr \
|
|
git-update-project-description \
|
|
install-deps-devel \
|
|
streamline \
|
|
git-ssh \
|
|
git-get-official \
|
|
git-get-maintainer \
|
|
git-get-pub \
|
|
pkg-manager-refresh \
|
|
pkg-install-build-deps \
|
|
pkg-install-release-deps \
|
|
pkg-install-testbuild-deps \
|
|
recache-vars \
|
|
canonicalize-remotes
|
|
|
|
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) pkg
|
|
|
|
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 = /$(JANWARE_USER)/$(REMOTE_GIT_FLAVOUR)/$(PROJECT)
|
|
REMOTE_GIT_URL = ssh://$(JANWARE_USER_PREFIX)devgit.janware.com$(REMOTE_GIT_DIR)
|
|
|
|
ifneq ($(DONT_CHECK_PREREQ_DONE),true)
|
|
ifndef PREREQ
|
|
PREREQ := $(call proj_query,pkg-requires --no-subpackages --subsections=jw --syntax names-only --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/pkg-dist.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))
|
|
|
|
TD_CONF_DIR ?= $(JW_PKG_CONF_BASE_DIR)/topdir
|
|
TD_COPY_SRC ?= $(TD_CONF_DIR)
|
|
TD_COPY_FILES ?= $(filter-out Makefile,$(notdir $(wildcard $(TD_COPY_SRC)/*)))
|
|
# -- Internal variables, define JW_PKG_TOPDIR_COPY_PATH if you want to
|
|
# add more files appended to the target files
|
|
TD_COPY_SRC_PATH = $(subst :,$(space),$(JW_PKG_TOPDIR_COPY_PATH))
|
|
TD_GENERATE_FILES += $(TD_COPY_FILES)
|
|
|
|
all: config
|
|
format:
|
|
check-syntax: topdir
|
|
check-format: topdir
|
|
check: check-syntax check-format
|
|
install: topdir.install
|
|
clean: topdir.clean
|
|
distclean: topdir.distclean
|
|
config:
|
|
mrproper:distclean topdir.mrproper
|
|
|
|
local-%: FORCE
|
|
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: $(TD_GENERATE_FILES)
|
|
topdir.clean:
|
|
$(RM) -rf *.done $(TD_GENERATE_FILES)
|
|
clean: topdir.clean
|
|
topdir.distclean: topdir.clean
|
|
$(RM) -rf dist *.dist
|
|
distclean: topdir.distclean
|
|
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
|
|
get-official: git-get-official
|
|
get-pub: git-get-pub
|
|
|
|
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 $(PKG_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)@devgit.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)@devgit.janware.com "/opt/jw-pkg/bin/git-srv-admin.sh $(OPT_JANWARE_PROJECT) update-descriptions $(PROJECT)"
|
|
|
|
projects-%: FORCE
|
|
$(PYTHON) $(JWB_SCRIPT_DIR)/jw-pkg.py projects build $* $(PROJECT)
|
|
|
|
install-deps-devel:
|
|
sudo zypper in $(shell echo $(PKG_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 "build" $(PROJECT))
|
|
|
|
git-ssh-%: FORCE
|
|
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-pub:
|
|
if git remote | grep -q "^pub$$"; then \
|
|
JW_PKG_SSH_EXTRA_OPTS="" git pull pub master ;\
|
|
fi
|
|
|
|
git-get-%: FORCE
|
|
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 $(shell $(proj_query_cmd) required-os-pkg --quote --skip-excluded "build" $(PROJECT))
|
|
|
|
pkg-install-release-deps:
|
|
$(PKG_MANAGER) install $(shell $(proj_query_cmd) required-os-pkg --quote --skip-excluded "build,run,release" $(PROJECT))
|
|
|
|
pkg-install-testbuild-deps:
|
|
$(PKG_MANAGER) install $(shell $(proj_query_cmd) pkg-requires --quote --skip-excluded --hide-self --syntax names-only --delimiter " " "build,run,devel,release" $(PROJECT))
|
|
|
|
recache-vars:
|
|
rm -f $(TOPDIR)/make clean-cache cache
|
|
|
|
canonicalize-remotes:
|
|
$(PYTHON) $(JWB_SCRIPT_DIR)/jw-pkg.py projects canonicalize-remotes
|
|
|
|
Makefile: ;
|
|
|
|
%: $(TD_COPY_SRC)/% $$(foreach path,$$(TD_COPY_SRC_PATH),$$(wildcard $$(addprefix $$(path)/,$$@))) $$(wildcard $$@.*)
|
|
cat $^ > $@.tmp
|
|
mv $@.tmp $@
|