From 4fb829af7e5e9cb2837a052f34d789faf9f3cda9 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 16 Feb 2016 06:20:40 +0100 Subject: Makefile: parse target --- Makefile | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 384c872a..a73a1aaf 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,30 @@ ifndef system $(error unbound variable: system) endif +# target = [target_user@]target_host[:target_port][/target_path] +ifdef target +_target_user != echo $(target) | sed -n 's/@.*//p' +_target_path != echo $(target) | sed -n 's/^[^/]*//p' +_target_port != echo $(target) | sed -En 's|^.*:([^/]*)(/.*)?$$|\1|p' +_target_host != echo $(target) | sed -En 's/^(.*@)?([^:/]*).*/\2/p' +ifneq ($(_target_host),) +$(if $(target_host),$(error cannot define both, target_host and host in target)) +target_host ?= $(_target_host) +endif +ifneq ($(_target_user),) +$(if $(target_user),$(error cannot define both, target_user and user in target)) +target_user ?= $(_target_user) +endif +ifneq ($(_target_port),) +$(if $(target_port),$(error cannot define both, target_port and port in target)) +target_port ?= $(_target_port) +endif +ifneq ($(_target_path),) +$(if $(target_path),$(error cannot define both, target_path and path in target)) +target_path ?= $(_target_path) +endif +endif + export target_host ?= $(system) export target_user ?= root export target_port ?= 22 -- cgit v1.2.3