%% "Jay Vaishnav" <[EMAIL PROTECTED]> writes:
jv> I am enclosing the rule for making a target from a GNU make
jv> file that I have written.
jv> SHELL = /bin/sh
jv> # Check if the present working directory contains any Java sources.
jv> local:
jv> listjava='$(wildcard *.java)';if test -f $(firstword $$listjava); \
jv> then javac $$listjava; fi
This won't work because you're mixing shell commands and make functions.
You have to remember that make expands all the make functions and
variables in the script, _then_ sends the results to the shell. You
can't use make functions to operate on values which make sense only in
the subshell.
In particular, here you say: "$(firstword $$listjava)". This can't
work, because "$$listjava" is a shell variable which doesn't have any
value until you run the shell script, while $(firstword ...) is a make
function which must be expanded before the shell script is invoked.
Since the $$ escapes the variable, the expansion of that function is
_always_ just $$listjava, regardless. IOW, you can just take out the
firstword invocation and get the same results.
jv> If the present working directory does not contain any files
jv> with the extension '.java', then listjava evaluates to the
jv> empty string and gnu make gives the following error.
jv> /bin/sh: test: argument expected
jv> gmake: *** [local] Error 1
jv> While gmake does continue the execution of the recursive tree
jv> walk, the presence of this error for all those non-leaf level
jv> directories that do not contain Java sources is distracting.
jv> If this is a feature of gnu make, would you be kind enough to
jv> suggest a workaround that eliminates this unsightly error from
jv> the log file generated for the make?
This has nothing to do with GNU make. It's a shell issue. This is the
shell script that make invokes when $(wildcard *.java) is empty:
listjava=''; if test -f $listjava; then javac $listjava; fi
If you run that by hand you'll see that it gives the exact error you're
seeing. After the shell expands $listjava to empty, you're running
"test -f", and test -f requires an argument.
I think you really just want to know if there are any files in
$listjava, and if so you should just use something like:
local:
listjava='$(wildcard *.java)';if [ x"$$listjava" != x ]; \
then javac $$listjava; fi
to find out whether the value of $listjava is empty or not.
Again, this is a shell issue, not a make issue; consult your shell
manual for help with how the shell expands variables, and the possible
arguments to "test".
--
-------------------------------------------------------------------------------
Paul D. Smith <[EMAIL PROTECTED]> Find some GNU make tips at:
http://www.gnu.org http://www.paulandlesley.org/gmake/
"Please remain calm...I may be mad, but I am a professional." --Mad Scientist