help-make
[Top][All Lists]
Advanced

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

Re: 'Generic' pattern rules


From: Lane Schwartz
Subject: Re: 'Generic' pattern rules
Date: Thu, 25 Aug 2011 10:22:33 -0400

You could use a recipe to dynamically create the rules you want:

define FOO

$1.req: $2.key
      $(OPENSSL) req -out $$@ -key $$< -subj $(SUBJECT) -new -batch

endef

$(eval $(call FOO,hydrogen,myrsa2048))


If there are a lot of such rules to create, you can wrap the above in
$(foreach ). If you need an example of doing this, let me know.

Does this help?




----BEGIN----

OPENSSL = openssl
KEYSIZE = 2048
SUBJECT = /CN=foobar

.EXPORT_ALL_VARIABLES:

define FOO

$1.req: $2.key
      $(OPENSSL) req -out $@ -key $< -subj $(SUBJECT) -new -batch

endef


%.key:
       $(OPENSSL) genrsa -out $@ $(KEYSIZE)

%.req: %.key
       $(OPENSSL) req -out $@ -key $< -subj $(SUBJECT) -new -batch

carbon.req: carbon.key

hydrogen.req: SUBJECT = /CN=hydrogen.example.com
hydrogen.req: myrsa2048.key

----END----


On Thu, Aug 25, 2011 at 10:07 AM,  <address@hidden> wrote:
> Sure. Here is a subset of the actual Makefile:
>
> ----BEGIN----
>
> OPENSSL = openssl
> KEYSIZE = 2048
> SUBJECT = /CN=foobar
>
> .EXPORT_ALL_VARIABLES:
>
> %.key:
>        $(OPENSSL) genrsa -out $@ $(KEYSIZE)
>
> %.req: %.key
>        $(OPENSSL) req -out $@ -key $< -subj $(SUBJECT) -new -batch
>
> carbon.req: carbon.key
>
> hydrogen.req: SUBJECT = /CN=hydrogen.example.com
> hydrogen.req: myrsa2048.key
>
> ----END----
>
> When 'make carbon.req' is executed, 'carbon.key' is first created if not
> already present (first pattern rule), and then 'carbon.req'
>
> However, when 'make hydrogen.req' is executed, 'myrsa2048.key' is not taken
> into account since the pattern rule is meant to match 'hydrogen.req:
> hydrogen.key'.
>
> The only solution I found so far is to use canned recipes instead of pattern
> rules. But that's not that elegant...
>
>> There is probably a complicated way to most (but not all) of what
>> you're trying to do. Can you give a more detailed example that's
>> closer to your actual use case?



reply via email to

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