[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Tinycc-devel] env executable examples
From: |
grischka |
Subject: |
Re: [Tinycc-devel] env executable examples |
Date: |
Fri, 11 May 2012 14:08:47 +0200 |
User-agent: |
Thunderbird 2.0.0.24 (Windows/20100228) |
Michael Matz wrote:
Hi,
On Thu, 10 May 2012, grischka wrote:
[1] See commit 27a428cd0fae475d7377e1dbe218c064ee217d85
Basically /usr/bin/env tcc -run will try to find "tcc -run" which is
then obviously not found. Should we go back to the solution proposed
in [2] or do you have another idea?
Why not use just
#!tcc -tun
Because shebangs are interpreted by the kernel VFS, which doesn't know
about $PATH, and hence won't find 'tcc' in any path (and therefore the
execution will fail). That's what env(1) was intended for, but the
linux kernel unfortunately supports only exactly one (optional) argument
for the interpreter, i.e. it breaks with two and more arguments like
when the shebang is "#!env firstarg secondarg". So, all in all, when
you use an meta-interpreter (like env) that somehow needs the name of
the real interpreter as argument (tcc in this case) you can't give
further arguments to that real interpreter (-run here).
Ok, thanks. I'm finally able to understand now the deal with the
'expand_args' stuff here:
case TCC_OPTION_run:
{
int argc1;
char **argv1;
argc1 = expand_args(&argv1, optarg);
if (argc1 > 0) {
parse_args(s, argc1, argv1);
}
multiple_files = 0;
output_type = TCC_OUTPUT_MEMORY;
break;
}
Otherwise I'd suggest to revert to the original
#!/usr/local/bin/tcc -tun
Which again would have the problem of hardcoding the path to tcc into
the "scripts". You need a meta-interpreter for finding the name of the
real interpreter, and you can't give further arguments to it. Hence the
best suggestion up to now was to create a wrapper script called tcc-run
(just calling "exec tcc -run $1" on its argument), which would be used
as argument to the 'env' shebang.
Of course, one could also decide to not care, but IMHO Davids above
suggestion (helper script) is the most satisfying one, given the sorry
circumstances.
Indeed it's sorry because my admittedly rather limited understanding
of shebang scripts is usage as simple as in
#!/usr/bin/perl
Now the examples ex1.c and ex4.c are meant to show off how tcc can be
used as an interpreter for C-scripts in a rather similar way, in
particular also with additional arguments such as in ex4.c:
#!/usr/local/bin/tcc -run -L/usr/X11R6/lib -lX11
Obviously the original intention (seen the 'expand_args' hack above)
is to make that possible without any additional wrapper script. The
point of the examples is to show that intention. If we provide a
wrapper script we would miss that point in the first place.
Also, if I'd install perl elsewhere, quite some things will stop to
work just as well. IMO it is not the point of our examples to show
how to escape from this system limitation.
My 2 cents.
--- grischka
Ciao,
Michael.