diff --git a/tool/ports/list b/tool/ports/list new file mode 100755 index 0000000000..06b67698cf --- /dev/null +++ b/tool/ports/list @@ -0,0 +1,27 @@ +#!/usr/bin/make -f + +# +# \brief Tool for listing ports +# \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 +# +GENODE_DIR := $(realpath $(dir $(MAKEFILE_LIST))/../..) + +include $(GENODE_DIR)/tool/ports/mk/front_end.inc + +usage: + @$(ECHO) + @$(ECHO) "--- list available ports ---" + @$(ECHO) "usage: list" + @$(ECHO) + +include $(PORT) + +$(TARGET): + $(VERBOSE)for i in $(sort $(notdir $(_PORTS:.port=))); do\ + echo $$i; done diff --git a/tool/ports/mk/check_port_arg.inc b/tool/ports/mk/check_port_arg.inc new file mode 100644 index 0000000000..b0c23f96a5 --- /dev/null +++ b/tool/ports/mk/check_port_arg.inc @@ -0,0 +1,24 @@ +# +# \brief Check validity of user input +# \author Norman Feske +# \date 2014-05-27 +# + +ifeq ($(ARGUMENT),) +$(TARGET): missing_argument +missing_argument: usage + @$(ECHO) "Error: Missing port name as argument"; false +endif + +ifneq ($(words $(ARGUMENT)),1) +$(TARGET): too_many_arguments +too_many_arguments: usage + @$(ECHO) "Error: Too many arguments specified, expecting one argument"; false +endif + +ifeq ($(PORT),) +$(TARGET): nonexisting_port +nonexisting_port: + @$(ECHO) "Error: Port $(PORT_NAME) does not exist"; false +endif + diff --git a/tool/ports/mk/common.inc b/tool/ports/mk/common.inc new file mode 100644 index 0000000000..5117747c85 --- /dev/null +++ b/tool/ports/mk/common.inc @@ -0,0 +1,23 @@ +# +# \brief Common environment +# \author Norman Feske +# \date 2014-05-27 +# + +SHELL := bash +VERBOSE ?= @ +ECHO := echo -e +HASHSUM := sha1sum + +BRIGHT_COL ?= \033[01;33m +DARK_COL ?= \033[00;33m +DEFAULT_COL ?= \033[0m + +MSG_PREFIX := $(ECHO) "$(DARK_COL)$(notdir $(PORT:.port=)) $(DEFAULT_COL)" +MSG_DOWNLOAD := $(MSG_PREFIX)"download " +MSG_APPLY := $(MSG_PREFIX)"apply " +MSG_UPDATE := $(MSG_PREFIX)"update " +MSG_INSTALL := $(MSG_PREFIX)"install " +MSG_GENERATE := $(MSG_PREFIX)"generate " +MSG_EXTRACT := $(MSG_PREFIX)"extract " + diff --git a/tool/ports/mk/front_end.inc b/tool/ports/mk/front_end.inc new file mode 100644 index 0000000000..577bfe4acd --- /dev/null +++ b/tool/ports/mk/front_end.inc @@ -0,0 +1,51 @@ +# +# \brief Common front-end code shared among different ports tools +# \author Norman Feske +# \date 2014-05-27 +# + +include $(GENODE_DIR)/tool/ports/mk/common.inc + +# +# Always execute the $(TARGET) rule regardless of the supplied command-line +# argument +# +TARGET := $(MAKECMDGOALS) default +$(MAKECMDGOALS) default: + +# the single argument is the name of the port to prepare +ARGUMENT := $(MAKECMDGOALS) +PORT_NAME := $(firstword $(ARGUMENT)) + +# compound directory where all 3rd-party source codes are installed +CONTRIB_DIR ?= $(GENODE_DIR)/contrib + +# list of all repositories located at '/repos/' +REPOSITORIES ?= $(shell find $(GENODE_DIR)/repos -follow -mindepth 1 -maxdepth 1 -type d) + +# list of all repositories that contain ports of 3rd-party source code +_REP_PORTS_DIRS := $(wildcard $(addsuffix /ports,$(REPOSITORIES))) + +# list of all available ports +_PORTS := $(foreach DIR,$(_REP_PORTS_DIRS),$(wildcard $(DIR)/*.port)) + +# port file to use +PORT := $(filter %/$(PORT_NAME).port,$(_PORTS)) + +# repository that contains the port description, used to look up patch files +REP_DIR := $(realpath $(dir $(PORT))/..) + +# read hash that uniquely identifies the version to install +HASH_FILE := $(wildcard $(PORT:.port=.hash)) +HASH := $(if $(HASH_FILE),$(shell cat $(HASH_FILE)),) + +# path to hash file relative to '/repos', used for error messages +_REL_HASH_FILE := $(notdir $(REP_DIR))/ports/$(notdir $(PORT)) + +# directory where to install the port +PORT_DIR := $(CONTRIB_DIR)/$(PORT_NAME)-$(HASH) + +# path to hash file generated during installation +PORT_HASH_FILE := $(PORT_DIR)/$(PORT_NAME).hash + +# vi: set ft=make : diff --git a/tool/ports/mk/hash.inc b/tool/ports/mk/hash.inc new file mode 100644 index 0000000000..57e92b5bec --- /dev/null +++ b/tool/ports/mk/hash.inc @@ -0,0 +1,35 @@ +# +# \brief Utilities for generating and checking port hashes +# \author Norman Feske +# \date 2014-05-27 +# + +# +# The hash depends on the content of the port description file and the +# patches originating from REP_DIR. Patches that are downloaded are already +# captured by the hash sums of the downloaded files, which are declared in the +# port description file. +# +# During development when the files of MAKEFILE_LIST often change, the +# keeping all port hashes up to date is an inconvenience. By setting +# STRICT_HASH to 'no', the MAKEFILE_LIST can be exluded. +# + +_PATCHES_IN_REP_DIR := $(foreach P,$(PATCHES),$(wildcard $(REP_DIR)/$(P))) + +HASH_INPUT += $(_PATCHES_IN_REP_DIR) $(PORT) +ifneq ($(STRICT_HASH),no) +HASH_INPUT += $(MAKEFILE_LIST) +endif + +$(_DST_HASH_FILE): $(HASH_INPUT) $(MAKEFILE_LIST) + @$(MSG_GENERATE)$(notdir $@) + $(VERBOSE)cat $(HASH_INPUT) | $(HASHSUM) | sed "s/ .*//" > $@ + +_check_hash: $(_DST_HASH_FILE) +ifneq ($(CHECK_HASH),no) + $(VERBOSE)diff $< $(HASH_FILE) > /dev/null ||\ + ($(ECHO) "Error: $(_REL_HASH_FILE) is out of date, expected" `cat $<` ""; false) +endif + + diff --git a/tool/ports/mk/install.mk b/tool/ports/mk/install.mk index 161fa0b1ba..4ae22aacff 100644 --- a/tool/ports/mk/install.mk +++ b/tool/ports/mk/install.mk @@ -41,24 +41,9 @@ _prefer = $(if $1,$1,$2) include $(PORT) # -# Common environment +# Include common definitions # -SHELL := bash -VERBOSE ?= @ -ECHO := echo -e -HASHSUM := sha1sum - -BRIGHT_COL ?= \033[01;33m -DARK_COL ?= \033[00;33m -DEFAULT_COL ?= \033[0m - -MSG_PREFIX := $(ECHO) "$(DARK_COL)$(notdir $(PORT:.port=)) $(DEFAULT_COL)" -MSG_DOWNLOAD := $(MSG_PREFIX)"download " -MSG_APPLY := $(MSG_PREFIX)"apply " -MSG_UPDATE := $(MSG_PREFIX)"update " -MSG_INSTALL := $(MSG_PREFIX)"install " -MSG_GENERATE := $(MSG_PREFIX)"generate " -MSG_EXTRACT := $(MSG_PREFIX)"extract " +include $(GENODE_DIR)/tool/ports/mk/common.inc # # Assertion for the presence of a LICENSE and VERSION declarations in the port @@ -76,9 +61,6 @@ version_undefined: @$(ECHO) "Error: Version undefined"; false endif - -_PATCHES_IN_REP_DIR := $(foreach P,$(PATCHES),$(wildcard $(REP_DIR)/$(P))) - _DST_HASH_FILE := $(notdir $(PORT:.port=)).hash @@ -94,30 +76,7 @@ _dirs: $(DOWNLOADS) ## Generate the HASH file ## -# The hash depends on the content of the port description file and the -# patches originating from REP_DIR. Patches that are downloaded are already -# captured by the hash sums of the downloaded files, which are declared in the -# port description file. -# -# During development when the files of MAKEFILE_LIST often change, the -# keeping all port hashes up to date is an inconvenience. By setting -# STRICT_HASH to 'no', the MAKEFILE_LIST can be exluded. -# - -HASH_INPUT += $(_PATCHES_IN_REP_DIR) $(PORT) -ifneq ($(STRICT_HASH),no) -HASH_INPUT += $(MAKEFILE_LIST) -endif - -$(_DST_HASH_FILE): $(HASH_INPUT) $(MAKEFILE_LIST) - @$(MSG_GENERATE)$(notdir $@) - $(VERBOSE)cat $(HASH_INPUT) | $(HASHSUM) | sed "s/ .*//" > $@ - -_check_hash: $(_DST_HASH_FILE) -ifneq ($(CHECK_HASH),no) - $(VERBOSE)diff $< $(HASH_FILE) > /dev/null ||\ - ($(ECHO) "Error: $(_REL_HASH_FILE) is out of date, expected" `cat $<` ""; false) -endif +include $(GENODE_DIR)/tool/ports/mk/hash.inc ## diff --git a/tool/ports/prepare_port b/tool/ports/prepare_port index 20a24e6d62..07e5179d31 100755 --- a/tool/ports/prepare_port +++ b/tool/ports/prepare_port @@ -6,77 +6,14 @@ # \date 2014-05-07 # -VERBOSE ?= @ -ECHO := echo -e - -# -# Always execute the $(TARGET) rule regardless of the supplied command-line -# argument -# -TARGET := $(MAKECMDGOALS) default -$(MAKECMDGOALS) default: - -# the single argument is the name of the port to prepare -ARGUMENT := $(MAKECMDGOALS) -PORT_NAME := $(firstword $(ARGUMENT)) - # # Determine Genode base directory based on the known location of the # 'create_builddir' tool within the Genode source tree # -GENODE_DIR ?= $(realpath $(dir $(MAKEFILE_LIST))/../..) +export GENODE_DIR := $(realpath $(dir $(MAKEFILE_LIST))/../..) -# compound directory where all 3rd-party source codes are installed -CONTRIB_DIR ?= $(GENODE_DIR)/contrib - -# list of all repositories located at '/repos/' -REPOSITORIES ?= $(shell find $(GENODE_DIR)/repos -follow -mindepth 1 -maxdepth 1 -type d) - -# list of all repositories that contain ports of 3rd-party source code -_REP_PORTS_DIRS := $(wildcard $(addsuffix /ports,$(REPOSITORIES))) - -# list of all available ports -_PORTS := $(foreach DIR,$(_REP_PORTS_DIRS),$(wildcard $(DIR)/*.port)) - -# port file to use -PORT := $(filter %/$(PORT_NAME).port,$(_PORTS)) - -# repository that contains the port description, used to look up patch files -REP_DIR := $(realpath $(dir $(PORT))/..) - -# read hash that uniquely identifies the version to install -HASH_FILE := $(wildcard $(PORT:.port=.hash)) -HASH := $(if $(HASH_FILE),$(shell cat $(HASH_FILE)),) - -# path to hash file relative to '/repos', used for error messages -_REL_HASH_FILE := $(notdir $(REP_DIR))/ports/$(notdir $(PORT)) - -# directory where to install the port -PORT_DIR := $(CONTRIB_DIR)/$(PORT_NAME)-$(HASH) - -# path to hash file generated during installation -PORT_HASH_FILE := $(PORT_DIR)/$(PORT_NAME).hash - -# -# Check validity of user input -# -ifeq ($(ARGUMENT),) -$(TARGET): missing_argument -missing_argument: usage - @$(ECHO) "Error: Missing port name as argument"; false -endif - -ifneq ($(words $(ARGUMENT)),1) -$(TARGET): too_many_arguments -too_many_arguments: usage - @$(ECHO) "Error: Too many arguments specified, expecting one argument"; false -endif - -ifeq ($(PORT),) -$(TARGET): nonexisting_port -nonexisting_port: - @$(ECHO) "Error: Port $(PORT_NAME) does not exist"; false -endif +include $(GENODE_DIR)/tool/ports/mk/front_end.inc +include $(GENODE_DIR)/tool/ports/mk/check_port_arg.inc ifeq ($(HASH),) $(TARGET): nonexisting_hash diff --git a/tool/ports/update_hash b/tool/ports/update_hash new file mode 100755 index 0000000000..279942a1c8 --- /dev/null +++ b/tool/ports/update_hash @@ -0,0 +1,36 @@ +#!/usr/bin/make -f + +# +# \brief Tool for updating the hash file of a port +# \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 +# +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 + +usage: + @$(ECHO) + @$(ECHO) "--- update hash file of a port ---" + @$(ECHO) "usage: update_hash " + @$(ECHO) + +include $(PORT) + +_DST_HASH_FILE := $(HASH_FILE) + +# XXX remove this line when the tool has stabilized +STRICT_HASH ?= no + +include $(GENODE_DIR)/tool/ports/mk/hash.inc + +.PHONY: $(_DST_HASH_FILE) + +$(TARGET): $(_DST_HASH_FILE) +