[clue-tech] Portability of shell expressions in a Makefile
Keith Hellman
khellman at mcprogramming.com
Sun May 8 23:20:03 MDT 2005
On Sun, May 08, 2005 at 10:32:44PM -0600, Matt Gushee wrote:
> Hello, all--
>
> I am using the following to set a variable in a Makefile:
>
> SOLID=$(shell \
> version=`ocamlc -version`; \
> major=$${version:0:4}; \
> minor=$${version:5}; \
> if [ $$major = "3.08" ] && [ $$minor ] && \
> [ $$minor -ge 3 ]; then \
> echo "-DSOLID_RELIEF"; \
> else \
> echo ""; \
> fi )
>
> This has the desired effect in bash. Can anyone tell me if it will work
> with other Bourne-compatible shells? And while we're at it, how about
> non-GNU make implementations?
I can't comment on non-GNU make implementations cause I've haven't used
one for years. I wouldn't be surprised that most people do have it
installed if they use any amount of FOSS software.
According to
http://www.linuxselfhelp.com/gnu/bash/html_chapter/bashref_4.html
the ${var:offset:len} is not a standard in sh. You could avoid
worrying about it (and require people to at least have bash
on their systems) by doing this:
SOLID=$(shell bash -c '\
version=3.08.6 ; \
major=$${version:0:4}; \
minor=$${version:5}; \
if [ $$major = "3.08" ] && [ $$minor ] && \
[ $$minor -ge 3 ]; then \
echo >&2 yeah $$major $$minor ; \
echo "-DSOLID_RELIEF"; \
else \
echo >&2 boohoo $$major ; \
echo >&2 boohoo $$minor ; \
echo ""; \
fi' )
This above snippit worked on my machine (debian sarge, gmake 3.80).
Note that worked around not having ocaml installed :^)
HTH
--
Keith Hellman #include <disclaimer.h>
khellman at mcprogramming.com from disclaimer import standard
public key @ www.mcprogramming.com
"While it might seem that a simple increment operator is an atomic
operation, there's no gaurantee that it is. It's actually possible for
Thread 1 to update half of a 32-bit x while Thread 2 reads the full 32
bits, getting a mishmash instead of a valid integer. (And that's only
one thing that can go wrong. Another is that compiler optimization might
leave the integer in a register. You really can't ever let threads
simultaneously access data without protection.)"
-- Marc J. Rochkind, *Advanced Unix Programming*, Second Ed.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://cluedenver.org/pipermail/clue-tech/attachments/20050508/a2ffb6c9/attachment.bin
More information about the clue-tech
mailing list