help-make
[Top][All Lists]
Advanced

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

Re: Expandable dependencies variables


From: Miguel Guedes
Subject: Re: Expandable dependencies variables
Date: Sat, 10 Nov 2012 16:26:34 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121028 Thunderbird/16.0.2

On 10/11/12 15:06, Paul Smith wrote:
On Sat, 2012-11-10 at 11:27 +0000, Miguel Guedes wrote:
There's one thing I would simply love to accomplish with Automake
though: the ability to extend rules without overriding them. For
instance, how would one print a custom message in a specific format
(i.e. color) each time a source file is compiled and then linked?

I suspect you'll need to ask questions like these on the automake
mailing lists.  Cheers!


You're right of course! (though I'd done so already :)

I've ditched Automake and am instead using Autoconf and handcrafted Makefile.in files instead, as I find they confer a much higher degree of customization. Using your brilliant suggestion, I find setting up projects is now effortless. The basic mechanics is as follows:

-- Makefile.in:
PROGRAMS    = foo bar
foo_SOURCES = foo.c foobar.c
bar_SOURCES = bar.c foobar.c

include @srcdir@/build.mk

-- build.mk:
# construct list of objects per program
$(foreach I,$(PROGRAMS),$(eval $(I)_OBJECTS := $($(I)_SOURCES:%.cpp=%.o)))

# make each program dependent on required objects
$(foreach I,$(PROGRAMS),$(eval $(I): $($(I)_OBJECTS)))

$(PROGRAMS):
        @echo "\033[1;32m[L] `basename address@hidden"
        @LINK_LOG="/tmp/`basename address@hidden"; \
                [ -f $$LINK_LOG ] && rm $$LINK_LOG; \
                echo $(CXX) $(CXX_FLAGS) -o $@ $(^) $(LD_FLAGS) 2>$$LINK_LOG ; \
                $(CXX) $(CXX_FLAGS) -o $@ $(^) $(LD_FLAGS) 2>$$LINK_LOG ; \
                EXIT_CODE=$$?; \
                if [ ! $$? -eq 0 ]; then \
                        cat "$$LINK_LOG"; \
                        exit $$EXIT_CODE; \
                fi;

%.o: $(srcdir)/%.c $(OUTPUT_PCH)
        @echo "\033[0;32m[C] $<\033[0m"
        @$(CC) $(C_FLAGS) -c $< -o $@


-----

Thank you for the invaluable help, Paul!

Miguel



reply via email to

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