[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
handling nested AM_CONDITIONAL via m4 vars
From: |
Mike Frysinger |
Subject: |
handling nested AM_CONDITIONAL via m4 vars |
Date: |
Mon, 13 May 2013 00:26:57 -0400 |
User-agent: |
KMail/1.13.7 (Linux/3.8.3; KDE/4.6.5; x86_64; ; ) |
the AM_CONDITIONAL documentation states it must always be executed. that's
fine. but what if i want to be lazy?
for example, i have code like so:
AC_DEFUN([_FOKER_DEFINE], [dnl
AC_DEFINE([FOKER_]$1[_]m4_toupper($3), [1], [Define is the ]$2[ is ]$3)
])
AC_DEFUN([_FOKER_ARCH], [_FOKER_DEFINE([ARCH], [architecture], $1)])
AS_CASE([$host_cpu],
[alpha*], [_FOKER_ARCH([Alpha])],
[aarch64*], [_FOKER_ARCH([AArch64])],
[arm*], [_FOKER_ARCH([ARM])],
[bfin], [_FOKER_ARCH([bfin])],
[ia64], [_FOKER_ARCH([IA64])],
[mips*], [_FOKER_ARCH([MIPS])],
[hppa*], [_FOKER_ARCH([PARISC])],
[i?86], [_FOKER_ARCH([X86])],
[powerpc*], [_FOKER_ARCH([PowerPC])],
[s390*], [_FOKER_ARCH([s390])],
[sh*], [_FOKER_ARCH([SH])],
[sparc*], [_FOKER_ARCH([SPARC])],
[x86_64], [_FOKER_ARCH([x86_64])],
[*], [AC_MSG_WARN([unsupported architecture])],
)
i want each branch to expand into both an AC_DEFINE and an AM_CONDITIONAL.
rather than rewrite this, i thought why not use m4 vars to accumulate at
aclocal time, and then expand them afterwards. this way i don't have to give
up my pretty case statement.
what i have now is:
dnl Setup AC_DEFINE with FOKER_ARCH_$ARCH, set the shell var FOKER_ARCH
dnl to $ARCH, and push $ARCH onto the _FOKER_CONDS stack.
AC_DEFUN([_FOKER_DEFINE], [dnl
AC_DEFINE([FOKER_]$1[_]m4_toupper($3), [1], [Define is the ]$2[ is ]$3)
[FOKER_]$1=[FOKER_]$1[_]m4_toupper($3)
pushdef([_FOKER_CONDS], [FOKER_]$1[_]m4_toupper($3))
])
AC_DEFUN([_FOKER_ARCH], [_FOKER_DEFINE([ARCH], [architecture], $1)])
dnl Initialize the shell var FOKER_ARCH=unknown
AC_DEFUN([_FOKER_CONDS_INIT], [dnl
AC_MSG_CHECKING([for known host ]$1)
[FOKER_]$1='unknown'
])
dnl Pop all the arches off the _FOKER_CONDS stack and call AM_CONDITIONAL for
dnl each one.
AC_DEFUN([_FOKER_CONDS_EXPAND], [dnl
ifdef([_FOKER_CONDS], [dnl
AM_CONDITIONAL(_FOKER_CONDS, test $[FOKER_]$1 = _FOKER_CONDS)
popdef([_FOKER_CONDS])
_FOKER_CONDS_EXPAND($1)
], [dnl
AC_MSG_RESULT($[FOKER_]$1)
])
])
_FOKER_CONDS_INIT([ARCH])
...existing AS_CASE as above...
_FOKER_CONDS_EXPAND([ARCH])
this seems to accomplish what i want -- AM_CONDITIONAL is expanded outside of
the case statement w/out having to duplicate every entry. however, my m4
skills are beginner at best, so i'm wondering if people have suggestions for
how to do this better. i also wouldn't be surprised if my quoting is off.
not exactly an automake question, but close enough :)
-mike
signature.asc
Description: This is a digitally signed message part.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- handling nested AM_CONDITIONAL via m4 vars,
Mike Frysinger <=