help-make
[Top][All Lists]
Advanced

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

Re: 'Generic' pattern rules


From: Semen Trygubenko
Subject: Re: 'Generic' pattern rules
Date: Thu, 25 Aug 2011 15:53:17 +0100
User-agent: Mutt/1.5.20 (2009-06-14)

On Thu, Aug 25, 2011 at 04:07:08PM +0200, 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...

Noticed an issue with my previous solution ... How about :

----BEGIN----

OPENSSL = openssl
KEYSIZE = 2048
SUBJECT = /CN=foobar
.EXPORT_ALL_VARIABLES:

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

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

hydrogen.req: SUBJECT = /CN=hydrogen.example.com
hydrogen.req: myrsa2048.key
        ${key2req}

----END----


$ make hydrogen.req carbon.req lawrencium.req -n
openssl genrsa -out myrsa2048.key 2048
openssl req -out hydrogen.req -key myrsa2048.key -subj /CN=hydrogen.example.com 
-new -batch
openssl genrsa -out carbon.key 2048
openssl req -out carbon.req -key carbon.key -subj /CN=foobar -new -batch
openssl genrsa -out lawrencium.key 2048
openssl req -out lawrencium.req -key lawrencium.key -subj /CN=foobar -new -batch
rm lawrencium.key carbon.key

HTH,

--
Semen

Attachment: signature.asc
Description: Digital signature


reply via email to

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