[gambit-list] Is this the recommended way to inline shellscripts in |compile-file|'s cc/ld-options: arguments?

Adam adam.mlmb at gmail.com
Wed Jul 13 01:56:15 EDT 2016


Dear Marc,

I'm in a nasty environment where I not can know what exact "-I" and "-l"
arguments the C compiler and linker need.

For this reason, I need the pkg-config shell tool to figure it out for me!

It would have seemed logical to me that |compile-file|'s |cc-options:| and
|ld-options:| would be evaluated by the system shell by the gambc-cc
script, so that this would work:

echo '(print "Hello world\n")' > test.scm

GAMBC_CC_VERBOSE=yes gsc

(compile-file "test.scm"
              cc-options: "$(pkg-config --cflags \"libjpeg\")"
              ld-options: "$(pkg-config --libs \"libjpeg\")"
              )


However, it does not - but instead, the "$(p... strings are passed on
verbatim to the C compiler, leading to this output:

gcc [...] -o "test.o1" $(pkg-config --cflags "libjpeg")  test.c
$(pkg-config --libs "libjpeg")
gcc: error: $(pkg-config: No such file or directory
gcc: error: "libjpeg"): No such file or directory
gcc: error: $(pkg-config: No such file or directory
gcc: error: "libjpeg"): No such file or directory
gcc: error: unrecognized command line option ‘--cflags’
gcc: error: unrecognized command line option ‘--libs’
*** ERROR IN (console)@2.1 -- C compilation or link failed while compiling
"test.scm"


I.e. GCC actually gets a "$(pkg-config" argument, a "--cflags" argument and
a "\"libjpeg\"" argument, etc. .

So this test is a total catastrophe.

The question then comes, is this a bug or a feature?


I can totally see that it is your intended design of gsc+gambc-cc that
those arguments should be passed exactly verbatim all the way to the C
compiler, it makes sense, for instance as a correctness and a security
measure.

So what I am asking here is if you have any thoughts about the convenience
factor, or if you have any design thought here or this just design choice
just was arbitrary.


Anyhow in the absence of shell-evaluation of pkg-config anywhere else, I
need to add it explicitly, meaning then that the compile-file command
should be:

(compile-file "test.scm"
              cc-options: (myshellrun "pkg-config --cflags \"libjpeg\"")
              ld-options: (myshellrun "pkg-config --libs \"libjpeg\"")
              )


where myshellrun is a procedure that involves open-process and reads its
output to a string.

Please confirm that this indeed is the intended best practice for solving
this problem.

Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20160713/8a1670cb/attachment.htm>


More information about the Gambit-list mailing list