I used perl today. It felt awesome.
Wednesday 25 March 2009 - Filed under Code
So, I’m switching toolchains for my embedded system, because the one I had chosen previously doesnt do floating-point quite right. Don’t ask – you don’t want to know the gory details.
Anyway, I now have a bunch of libs I want to rebuild for the new libc. They’re built via the normal UNIX incantation: ./configure; make; make install.
However, in the case of SDL, and particularly SDL_image, the options for ./configure are REALLY LONG (try 300 chars. maybe that’s not really long, but what the heck.)
I noticed that the previous options to ./configure are stored in config.log – why not extract them, flip the libc over, and throw it back at ./configure?
And why not use Perl to do it? (I admit I don’t know sed or awk, which might be better tools for the job)
So:
$ grep “$ ./configure” config.log
That gives me the previous incantation, but with some crap on the front. Note the "$ “ is actually needed, since “configure” turns up elsewhere.
Strip the crap:
$ grep “$ ./configure” config.log | cut –c 5-
That’s the command I invoked before, without any crap. We’re getting somewhere. Now just need to flip the libc:
$ grep “$ ./configure” config.log | cut –c 5- | perl –pe ‘s/uclibc/gnu/’
And we’re more or less done. Throw it back at the shell, via the means I know (which is probably less than optimal!)
$ grep “$ ./configure” config.log | cut –c 5- | perl –pe ‘s/uclibc/gnu/’ | xargs sh
And it works. One libc flipped. The next step (left as an exercise for the reader) is to make a generic target-flipper for reconfiguring cross builds.
I need to use this stuff more often, I think.
2009-03-25 » admin
25 March 2009 @ 5:12 pm
Piping the command straight into `sh` as the last step also works, of course. Xargs is just noise.