1# file : build/meta/common.m4 2# copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC 3# license : GNU GPL v2; see accompanying LICENSE file 4 5# m4_strip(STRING) 6# ---------------- 7# Expands into STRING with tabs and spaces singled out into a single 8# space, and removing leading and trailing spaces. 9# 10m4_define([m4_strip], 11[m4_patsubst(m4_patsubst([ $1 ], [[ ]+], [ ]), [^ \(.*\) $], [[[\1]]])]) 12 13 14# m4_normalize(STRING) 15# -------------------- 16# Apply m4_strip to STRING. 17# 18m4_define([m4_normalize], [m4_strip([$1])]) 19 20# m4_split(STRING, [REGEXP]) 21# -------------------------- 22# Split STRING into an m4 list of quoted elements. The elements are 23# quoted with ] and ]. Beginning spaces and end spaces *are kept*. 24# Use m4_strip to remove them. 25# 26# REGEXP specifies where to split. Default is [\t ]+. 27# 28# If STRING is empty, the result is an empty list. 29# 30 31m4_define([m4_split], 32[m4_ifelse([$1], [], [], 33 [$2], [ ], [m4_ifelse(m4_index([$1], [ ]), [-1], [[$1]], 34 [_$0([$1], [$2], [, ])])], 35 [$2], [], [_$0([$1], [[ ]+], [, ])], 36 [_$0([$1], [$2], [, ])])]) 37 38m4_define([_m4_split], [m4_patsubst([$1], [$2], [$3])]) 39 40 41# Simple foreach implementation. The list elements are expected to 42# be fully expanded. 43# 44m4_define([m4_foreach], [m4_ifelse([$2], [], [], 45 [m4_pushdef([$1])_$0([$1], [$3], [], $2)m4_popdef([$1])])]) 46m4_define([_m4_foreach], [m4_ifelse([$#], [3], [], 47 [m4_define([$1], [$4])$2[]$0([$1], [$2], 48 m4_shift(m4_shift(m4_shift($@))))])]) 49 50# m4_foreach_w(VARIABLE, LIST, EXPRESSION) 51# ---------------------------------------- 52# Like m4_foreach, but the list is whitespace separated. 53# 54m4_define([m4_foreach_w], 55[m4_foreach([$1], m4_split(m4_normalize([$2]), [ ]), [$3])]) 56 57# m4_strip_nl(STRING) 58# ---------------------------------------- 59# Remove newlines 60# 61m4_define([m4_strip_nl], [m4_patsubst([$1], [ 62], [])]) 63 64# Enable/disable quoting. 65# 66m4_define([m4_equote], [m4_changequote([,])]) 67m4_define([m4_dquote], [m4_changequote([])]) 68 69# 70# 71m4_define([__ifelse__], 72 [m4_equote()m4_ifelse( 73 [$1], 74 [$2], 75 [m4_dquote()$3m4_equote()], 76 [m4_dquote()$4m4_equote()])[]m4_dquote()]) 77 78m4_define([__foreach__], 79 [m4_equote()m4_foreach( 80 [$1],[$2],[m4_dquote()$3m4_equote()])[]m4_dquote()]) 81 82m4_define([__foreach_w__], 83 [m4_equote()m4_foreach_w( 84 $1,$2,[m4_dquote()$3m4_equote()])[]m4_dquote()]) 85 86# 87# 88m4_define([__env_impl__], [m4_esyscmd([/bin/echo -n $$1])]) 89m4_define([__env__], [m4_equote()__env_impl__([$1])[]m4_dquote()]) 90 91m4_define([__value_impl__], [__env_impl__([$1])]) 92m4_define([__value__], [m4_equote()__value_impl__([$1])[]m4_dquote()]) 93 94m4_define([__uuid_impl__], 95 [m4_translit(m4_strip_nl(m4_esyscmd([uuidgen])), [a-z], [A-Z])]) 96m4_define([__uuid__], [m4_equote()__uuid_impl__([$1])[]m4_dquote()]) 97 98m4_define([__upcase_impl__], [m4_translit([$1], [a-z], [A-Z])]) 99m4_define([__upcase__], [m4_equote()__upcase_impl__([$1])[]m4_dquote()]) 100 101m4_define([__xml_impl__], 102[m4_patsubst( 103 m4_patsubst( 104 m4_patsubst( 105 [$1], 106 [&], 107 [&]), 108 [<], 109 [<]), 110 ["], 111 ["])]) 112 113m4_define([__xml__], [m4_equote()__xml_impl__([$1])[]m4_dquote()]) 114