mhd_append_flag_to_var.m4 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # SYNOPSIS
  2. #
  3. # MHD_APPEND_FLAG_TO_VAR([VARIABLE-TO-EXTEND], [FLAG-TO-APPEND])
  4. #
  5. # DESCRIPTION
  6. #
  7. # This macro sets VARIABLE-TO-EXTEND to the value of VARIABLE-TO-EXTEND with
  8. # appended FLAG-TO-APPEND. If current value of VARIABLE-TO-EXTEND and
  9. # FLAG-TO-APPEND are both non-empty strings then space is added between them.
  10. #
  11. # Example usage:
  12. #
  13. # MHD_APPEND_FLAG_TO_VAR([my_CFLAGS], [-Wall])
  14. #
  15. #
  16. # LICENSE
  17. #
  18. # Copyright (c) 2022 Karlson2k (Evgeny Grin) <k2k@narod.ru>
  19. #
  20. # Copying and distribution of this file, with or without modification, are
  21. # permitted in any medium without royalty provided the copyright notice
  22. # and this notice are preserved. This file is offered as-is, without any
  23. # warranty.
  24. #serial 2
  25. AC_DEFUN([MHD_APPEND_FLAG_TO_VAR],[dnl
  26. m4_ifblank([$1],[m4_fatal([$0: First macro argument must not be empty])])dnl
  27. m4_bmatch([$1], [\$], [m4_fatal([$0: First macro argument must not contain '$'])])dnl
  28. m4_bmatch([$1], [,], [m4_fatal([$0: First macro argument must not contain ','])])dnl
  29. m4_bmatch(_mhd_norm_expd([$1]), [\s],dnl
  30. [m4_fatal([$0: First macro argument must not contain whitespaces])])dnl
  31. m4_pushdef([varExtd],_mhd_norm_expd([$1]))dnl
  32. m4_bmatch([$2],[\$],dnl
  33. [dnl The second parameter is a variable value
  34. AS_IF([test -z "_mhd_norm_expd([$2])"],dnl
  35. [varExtd="${varExtd}"],dnl
  36. [test -z "${varExtd}"],dnl
  37. [varExtd="_mhd_norm_expd([$2])"],dnl
  38. [varExtd="${varExtd} _mhd_norm_expd([$2])"])
  39. ],dnl
  40. [dnl The second parameter is not a variable value
  41. m4_ifnblank(_mhd_norm_expd([$2]),dnl
  42. [AS_IF([test -z "${varExtd}"],[varExtd="_mhd_norm_expd([$2])"],[varExtd="${varExtd} _mhd_norm_expd([$2])"])
  43. ],dnl
  44. [m4_n([varExtd="${varExtd}"])])])dnl m4_ifnblank m4_bmatch
  45. m4_popdef([varExtd])dnl
  46. ])dnl AC_DEFUN