2011-12-16 2 views
19

나는 형태 콜론과 포트는 선택 사항입니다make에서 문자열을 어떻게 분할합니까?

host[:port] 

에서 호스트 식별자로 구성되어 내 메이크 파일의 매개 변수를 사용합니다. 그래서 다음은 모두 유효합니다

foo.example.com 
ssl.example.com:443 
localhost:5000 

나는, 옵션 대장에 문자열을 분할 변수에 값을 할당 할 HOST 포함하도록 foo.example.com, ssl.example.com, localhostPORT은 각각 80 (기본 포트), 443 및 500을 포함합니다.

답변

34
# 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 
관련 문제