help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Automatic variables and implicit rules


From: Jess Telford
Subject: Automatic variables and implicit rules
Date: Sun, 21 Dec 2008 11:01:28 +1100

Hello,

I currently have a make file set up to utilize implicit rules in
compiling my C source to object files.
All is well and works fine.

However, I am looking to have all the assembly output saved in .s files.
I have found out that the command line option to gcc -Wa,-ahl=file.s
will pass through the options I have
given it to AS. This works fine on its own when I directly call gcc
(with the -g flag).

It does not, however, work when gcc is called from an implicit rule.
The reason being that I can only put
these options in as parameters to gcc via the value of $(CFLAGS) which
does not know the name of the
file currently being processed.

Basically, I have the following relevant parts in my makefile;

CFLAGS          :=      -g -Wall -O2
CFILES          :=      $(foreach dir,$(SOURCES),$(notdir $(wildcard 
$(dir)/*.c)))
export OFILES   :=      $(CFILES:.c=.o)

where the final compiled and linked object depends on $(OFILES).

As far as I understand it, $(CC) should be invoked for every file in
$(OFILES) as an implicit rule to convert from
.c to .o. In this process, CFLAGS is passed as a variable when calling
$(CC). Logically, I figured that to include
the extra parameters for passing through to AS, I would simply add
them to CFLAGS which is where they should
belong to.

So, my modified CFLAGS looks like this;
CFLAGS          :=      -g -Wall -O2 -Wa,-ahl=file.s

As you can work out, every time $(CC) is called, a new file.s is
created (over-writing any previous file) which has
my desired output.

What I am trying to achieve is a list of all .s files which correspond
to every .c file which invoked $(CC).

The best option I can see for this is using the automatic variable 
address@hidden
Making CFLAGS look like;
CFLAGS          :=      -g -Wall -O2 -Wa,address@hidden

However, $@ always seems to be the empty string. I imagine this is
because CFLAGS itself has no "invoker"
which it can tell me about as it is simply a variable.

Short of manually invoking $(CC) with the options I want on every .c
file, is there a way to achieve what I am after?

Thank you for any and all help you can provide.

Cheers,
Jess - http://jt0.org




reply via email to

[Prev in Thread] Current Thread [Next in Thread]