prepare_port: prepare multiple ports at once

The tool/prepare_port tool is now able to handle a list of ports that
shall be prepared. Additionally, one may state the number of ports that
shall be prepared in parallel at a max by using the -j parameter. If -j
is not set by the user, the tool acts as with -j1. The previous
implementation of the tool that prepares only a single port was moved to
tool/ports/mk/prepare_single_port.mk and acts as back end to the new
prepare_port tool. The interface of the new prepare_port tool is
backwards compatible. When called for one port only, the behavior is the
same as when calling tool/ports/mk/prepare_single_port.mk directly.

Removes "usage" rule from prepare_single_port.mk. Removes shebang line
from prepare_single_port.mk.

Ref #1872
This commit is contained in:
Martin Stein 2016-02-03 17:48:54 +01:00 committed by Christian Helmuth
parent 74342ca2fc
commit b039608e95
3 changed files with 86 additions and 59 deletions

View File

@ -27,6 +27,8 @@ check_tool = $(if $(shell which $(1)),,$(error Need to have '$(1)' installed.))
default:
.NOTPARALLEL: default
# repository that contains the port description, used to look up patch files
REP_DIR := $(realpath $(dir $(PORT))/..)

View File

@ -0,0 +1,62 @@
#
# \brief Tool for downloading and patching 3rd-party source code
# \author Norman Feske
# \date 2014-05-07
#
#
# Determine Genode base directory based on the known location of the
# 'create_builddir' tool within the Genode source tree
#
export GENODE_DIR := $(realpath $(dir $(MAKEFILE_LIST))/../../..)
include $(GENODE_DIR)/tool/ports/mk/front_end.inc
include $(GENODE_DIR)/tool/ports/mk/check_port_arg.inc
ifeq ($(HASH),)
$(TARGET): nonexisting_hash
nonexisting_hash:
@$(ECHO) "Error: Port $(PORT_NAME) lacks a valid hash"; false
endif
#
# Default rule that triggers the actual preparation steps
#
$(TARGET): _check_integrity
_check_integrity : _install_in_port_dir
ifneq ($(CHECK_HASH),no)
$(VERBOSE)diff $(PORT_HASH_FILE) $(HASH_FILE) > /dev/null ||\
($(ECHO) "Error: $(_REL_HASH_FILE) is out of date, expected" `cat $(PORT_HASH_FILE)` ""; false)
endif
#
# During the preparatio steps, the port directory is renamed. We use the suffix
# ".incomplete" to mark this transient state of the port directory.
#
_install_in_port_dir: $(PORT_DIR)
@#\
# if the transient directory already exists, reuse it as it may contain\
# finished steps such as downloads. By reusing it, we avoid downloading\
# the same files again and again while working on a port. However, in this\
# case, we already have created an empty port directory via the $(PORT_DIR)\
# rule below. To avoid having both the port directory and the transient\
# port directory present, remove the just-created port directory.\
#
$(VERBOSE)(test -d $(PORT_DIR).incomplete && rmdir $(PORT_DIR)) || true
@#\
# If no transient directory exists, rename the port directory accordingly.\
#
$(VERBOSE)test -d $(PORT_DIR).incomplete || mv --force $(PORT_DIR) $(PORT_DIR).incomplete
$(VERBOSE)$(MAKE) --no-print-directory \
-f $(GENODE_DIR)/tool/ports/mk/install.mk \
-C $(PORT_DIR).incomplete \
PORT=$(PORT) VERBOSE=$(VERBOSE)
@#\
# The preparation finished successfully. So we can rename the transient\
# directory to the real one.\
#
$(VERBOSE)mv $(PORT_DIR).incomplete $(PORT_DIR)
$(PORT_DIR):
$(VERBOSE)mkdir -p $@

View File

@ -1,70 +1,33 @@
#!/usr/bin/make -f
#
# \brief Tool for downloading and patching 3rd-party source code
# \author Norman Feske
# \date 2014-05-07
# \brief Tool for preparing and updating ports
# \author Martin Stein
# \date 2016-02-03
#
#
# Determine Genode base directory based on the known location of the
# 'create_builddir' tool within the Genode source tree
#
ifndef VERBOSE
MAKEFLAGS += --no-print-directory
endif
export GENODE_DIR := $(realpath $(dir $(MAKEFILE_LIST))/../..)
include $(GENODE_DIR)/tool/ports/mk/front_end.inc
include $(GENODE_DIR)/tool/ports/mk/check_port_arg.inc
ifeq ($(HASH),)
$(TARGET): nonexisting_hash
nonexisting_hash:
@$(ECHO) "Error: Port $(PORT_NAME) lacks a valid hash"; false
endif
usage:
@$(ECHO)
@$(ECHO) "--- download and patch 3rd-party source code ---"
@$(ECHO) "usage: prepare_port <port-name> [CHECK_HASH=no]"
@$(ECHO)
@echo
@echo "Tool for preparing and updating ports"
@echo
@echo "usage:"
@echo
@echo " $(notdir $(MAKEFILE_LIST)) [-j<n>] <ports>"
@echo
@echo " -j<n> prepare <n> ports in parallel at a max, default is 1"
@echo
@echo " <ports> whitespace-separated list of ports"
@echo
#
# Default rule that triggers the actual preparation steps
#
$(TARGET): _check_integrity
TARGETS = $(sort $(MAKECMDGOALS))
_check_integrity : _install_in_port_dir
ifneq ($(CHECK_HASH),no)
$(VERBOSE)diff $(PORT_HASH_FILE) $(HASH_FILE) > /dev/null ||\
($(ECHO) "Error: $(_REL_HASH_FILE) is out of date, expected" `cat $(PORT_HASH_FILE)` ""; false)
endif
.PHONY: $(TARGETS)
#
# During the preparatio steps, the port directory is renamed. We use the suffix
# ".incomplete" to mark this transient state of the port directory.
#
_install_in_port_dir: $(PORT_DIR)
@#\
# if the transient directory already exists, reuse it as it may contain\
# finished steps such as downloads. By reusing it, we avoid downloading\
# the same files again and again while working on a port. However, in this\
# case, we already have created an empty port directory via the $(PORT_DIR)\
# rule below. To avoid having both the port directory and the transient\
# port directory present, remove the just-created port directory.\
#
$(VERBOSE)(test -d $(PORT_DIR).incomplete && rmdir $(PORT_DIR)) || true
@#\
# If no transient directory exists, rename the port directory accordingly.\
#
$(VERBOSE)test -d $(PORT_DIR).incomplete || mv --force $(PORT_DIR) $(PORT_DIR).incomplete
$(VERBOSE)$(MAKE) --no-print-directory \
-f $(GENODE_DIR)/tool/ports/mk/install.mk \
-C $(PORT_DIR).incomplete \
PORT=$(PORT) VERBOSE=$(VERBOSE)
@#\
# The preparation finished successfully. So we can rename the transient\
# directory to the real one.\
#
$(VERBOSE)mv $(PORT_DIR).incomplete $(PORT_DIR)
$(PORT_DIR):
$(VERBOSE)mkdir -p $@
$(TARGETS):
@$(MAKE) -f $(GENODE_DIR)/tool/ports/mk/prepare_single_port.mk $@