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 $@`\033[0m"
        @LINK_LOG="/tmp/`basename $@`.link.log"; \
                [ -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

_______________________________________________
Help-make mailing list
Help-make@gnu.org
https://lists.gnu.org/mailman/listinfo/help-make

Reply via email to