tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: bmake: how about :tr/CHARS/REPL/[1g]



> Another proposal (now minor) for bmake.

> How about adding new variable substitution :tr/CHARS/REPLS/[1g]
> similar to tr(1).

> It is close to sequence of :S/SUBSTR/REPL/[1g] but sometimes
> cannot be emulated easily, for example :tr/-./.-/g

I'll explain why I propose this.
In my wip/mk-configure the following construct is used many (>10) times.

----------------------------------------------
# Somewhere in user's Makefile
MKC_CHECK_SIZEOF+= int long long-long void* size_t:string.h
...
.include <configure.mk>
...
----------------------------------------------
# configure.mk

...
.for t in ${MKC_CHECK_SIZEOF}
SIZEOF.${t:S|.|_|g:S|-|_|g:S|*|P|g:S|/|_|g:S|:|.|g}   !=   env ${mkc.environ} 
${MKC_SHELL} mkc_check_sizeof ${t:S/:/ /g}
MKC_CFLAGS  +=  -DSIZEOF_${t:S/-/_/g:S| 
|_|g:S|*|P|g:S|:|_|g:S|.|_|g:tu}=${SIZEOF.${t:S|.|_|g:S|-|_|g:S|*|P|g:S|/|_|g:S|:|.|g}}
.endfor
...

----------------------------------------------
This code should "generate" something like

SIZEOF.int  = 4
SIZEOF.long = 4
SIZEOF.long_long = 8
SIZEOF.voidP = 8
SIZEOF.size_t.string_h = 4
MKC_CFLAGS += -DSIZEOF_INT=4
MKC_CFLAGS += -DSIZEOF_LONG=4
MKC_CFLAGS += -DSIZEOF_LONG_LONG=8
MKC_CFLAGS += -DSIZEOF_VOIDP=8
MKC_CFLAGS += -DSIZEOF_SIZE_T_STRING_H=4
----------------------------------------------

As you can see configure.mk code has lots of sequences of :S/// modifiers.
In the future I'd like to replace long constructs like

    ${t:S|.|_|g:S|-|_|g:S|*|P|g:S|/|_|g:S|:|.|g}

with more natural, much shorter, easier to read and faster

    ${t:tr|.-/:*|___.P|g}

If nobody objects I think I can prepare a patch for this.

-- 
Best regards, Aleksey Cheusov.


Home | Main Index | Thread Index | Old Index