如何在make中分割字符串? [英] How do I split a string in make?
本文介绍了如何在make中分割字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在我的Makefile中使用一个参数,该参数由以下形式的主机标识符组成:
I need to take a parameter in my Makefile that consists of a host identifier in the form
host[:port]
其中冒号和端口是可选的.因此,以下所有条件均有效:
where the colon and port are optional. So all of the following are valid:
foo.example.com
ssl.example.com:443
localhost:5000
等
我想在可选冒号上分割字符串并将值分配给变量,以便HOST
包含foo.example.com
,ssl.example.com
,localhost
等,而PORT
包含80(默认值端口),443和500.
I want to split the string on the optional colon and assign the values to variables, so that HOST
contains foo.example.com
, ssl.example.com
, localhost
, etc., and PORT
contains 80 (the default port), 443, and 500 respectively.
推荐答案
# Retrieves a host part of the given string (without port).
# Param:
# 1. String to parse in form 'host[:port]'.
host = $(firstword $(subst :, ,$1))
# Returns a port (if any).
# If there is no port part in the string, returns the second argument
# (if specified).
# Param:
# 1. String to parse in form 'host[:port]'.
# 2. (optional) Fallback value.
port = $(or $(word 2,$(subst :, ,$1)),$(value 2))
用法:
$(call host,foo.example.com) # foo.example.com
$(call port,foo.example.com,80) # 80
$(call host,ssl.example.com:443) # ssl.example.com
$(call port,ssl.example.com:443,80) # 443
这篇关于如何在make中分割字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文