help-make
[Top][All Lists]
Advanced

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

Re: gcc -M deficiencies; workaround?


From: gk
Subject: Re: gcc -M deficiencies; workaround?
Date: Wed, 15 Jan 2003 15:32:10 -0800

At 04:58 PM 1/15/2003 -0500, Paul D. Smith wrote:
%% gk <address@hidden> writes:

  g> Since gcc -M only returns prerequisite files included with #include
  g> directive, it cannot list prerequisite files accessed by fopen(),
  g> etc.

Why in the world would you want to recompile a C file because a file that
it fopen()s had changed?

Good question. I guess I shouldn't have said 'gcc -M deficiencies'
I didn't mean to imply that gcc -M SHOULD include any other files, just that there is a need of some way to determine additional prerequisites of the OUTPUT sometimes.

Sometimes if foo.o is part of a chain of makefile rules, the output target that depends on foo.o needs to know what files the OUTPUT of foo.o depends on.

Strictly speaking foo.o does not depend on a file opened by fopen(), but the OUTPUT that is produced by executing foo.o may depend on the files used, which could be determinable automatically if foo.c 'registered' the files it's output depends on, as in my PHP example in previous post.

I think perhaps the answer to my question is to build the functionality I'm seeking into foo.o But this imposes requires foo.c to process options, which isn't always what I want:
$foo.o -M
foo.txt

Simple example:
'foo.c' reads a file 'foo.txt' and writes the contents to /dev/stdout
'foo.o' outputs the contents of file: 'foo.txt'

# makefile
.PHONY: result
CC=gcc

# Command to generate a list of dependencies from a source file (including the source file)
# $(1) - source file
# remove the leading 'outputFile.o :'
define prerequisites
$(filter-out \,$(patsubst %:,,$(shell $(CC) -M $(1))))
endef

# IS THE THE ANSWER?
# $(1) - binary file
define get_prerequisites
$(1) -M
endef

foo.result: foo.o $(call get_prerequisites,foo.o)
        @$< > $@
foo.o: $(call prerequisites,foo.c)
        $(CC) -o $@ $<
# eof



- Greg Keraunen
http://www.xmake.org
http://www.xmlmake.com





reply via email to

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