help-make
[Top][All Lists]
Advanced

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

Re: How to define rule of rules?


From: Stephan Beal
Subject: Re: How to define rule of rules?
Date: Sun, 2 May 2010 00:52:25 +0200

On Sun, May 2, 2010 at 12:08 AM, Peng Yu <address@hidden> wrote:
I need to define many rules like RData_rule, png_rule, csv_rule, ....

Is there a way to define a macro that can define these rules (with the
parameter like RData and png)?

You're looking for $(call). Here's an example, taken from a makefile i've got laying around:

########################################################################
# ShakeNMake.EVAL.RULES.BIN is intended to be called like so:
# $(eval $(call ShakeNMake.EVAL.RULES.BIN,MyApp))
#
# It builds a binary named $(1) by running $(CXX) and passing it:
#
# LDFLAGS, $(1).BIN.LDFLAGS
# $(1).BIN.OBJECTS
define ShakeNMake.EVAL.RULES.BIN
$(1).BIN = $(1)$(ShakeNMake.EXTENSIONS.EXE)
$(1).BIN: $$($(1).BIN)
# Many developers feel that bins should not be cleaned by 'make
# clean', but instead by distclean, but i'm not one of those
# developers. i subscribe more to the school of thought that distclean
# is for cleaning up configure-created files. That said, shake-n-make
# isn't designed to use a configure-like process, so that is probably
# moot here and we probably (maybe?) should clean up bins only in
# distclean. As always: hack it to suit your preference:
CLEAN_FILES += $$($(1).BIN)
$$($(1).BIN): $$($(1).BIN.OBJECTS)
       address@hidden x = "x$$($(1).BIN.OBJECTS)" && { \
        echo "$(1).BIN.OBJECTS is undefined!"; exit 1; }; \
        $(call ShakeNMake.CALL.SETX,"CXX address@hidden ..."); \
        $$(CXX) -o $$@ \
                $$(CXXFLAGS) $$($(1).BIN.CXXFLAGS) \
                $$($(1).BIN.OBJECTS) \
                $$(LDFLAGS) $$($(1).BIN.LDFLAGS)
# note about 'set -x': i do this because it normalizes backslashed
# newline, extra spaces, and other oddities of formatting.
endef
########################################################################

--
----- stephan beal
http://wanderinghorse.net/home/stephan/

reply via email to

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