# contrib/credential/osxkeychain: Makefile should allow to set CFLAGS

5 messages from 2012-05-22 to 2012-05-24. Participants: Samuel John, Junio C Hamano, Jeff King.
Thread: https://gitlist.dev/t/30594

## Samuel John, 2012-05-22 20:25

Subject: contrib/credential/osxkeychain: Makefile should allow to set CFLAGS
Message-ID: <AB628C35-FEC2-4425-B3D8-EEC7F8D6A66B@samueljohn.de>
URL: https://gitlist.dev/e/AB628C35-FEC2-4425-B3D8-EEC7F8D6A66B%40samueljohn.de

```
Hi there,

the contrib/credential/osxkeychain/Makefile goes like this

> CC = gcc
> RM = rm -f
> CFLAGS = -g -Wall
> 
> git-credential-osxkeychain: git-credential-osxkeychain.o
> 	$(CC) -o $@ $< -Wl,-framework -Wl,Security
> 


and does not allow me to pass CFLAGS to build git-credential-osxkeychain.o.
My hack is to call: make CC="$CC $CFLAGS"
That is ugly.

Would you mind to add the CFLAGS to that CC call?

bests,
 Samuel

```

## Junio C Hamano, 2012-05-22 21:00

Subject: Re: contrib/credential/osxkeychain: Makefile should allow to set CFLAGS
Message-ID: <7vtxz82ap6.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vtxz82ap6.fsf%40alter.siamese.dyndns.org
In-Reply-To: <AB628C35-FEC2-4425-B3D8-EEC7F8D6A66B@samueljohn.de>

```
Samuel John <mail@samueljohn.de> writes:

> Hi there,
>
> the contrib/credential/osxkeychain/Makefile goes like this
>
>> CC = gcc
>> RM = rm -f
>> CFLAGS = -g -Wall
>> 
>> git-credential-osxkeychain: git-credential-osxkeychain.o
>> 	$(CC) -o $@ $< -Wl,-framework -Wl,Security
>
> and does not allow me to pass CFLAGS to build git-credential-osxkeychain.o.
> My hack is to call: make CC="$CC $CFLAGS"
> That is ugly.

Yeah, that is ugly.

It however seems to me that git-credential-osxkeychain.o does honor
$(CFLAGS), either from the user "make CFLAGS=..." or the default the
Makefile in question supplies.

The line you quoted is not using $(CC) as the compiler, but is using it to
link the final build product.  It may not hurt to have $(CFLAGS) on that
line, but shouldn't the line also have $(LDFLAGS) on it?

```

## Jeff King, 2012-05-23 17:36

Subject: Re: contrib/credential/osxkeychain: Makefile should allow to set CFLAGS
Message-ID: <20120523173653.GA29458@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20120523173653.GA29458%40sigill.intra.peff.net
In-Reply-To: <7vtxz82ap6.fsf@alter.siamese.dyndns.org>

```
On Tue, May 22, 2012 at 02:00:05PM -0700, Junio C Hamano wrote:

> It however seems to me that git-credential-osxkeychain.o does honor
> $(CFLAGS), either from the user "make CFLAGS=..." or the default the
> Makefile in question supplies.
> 
> The line you quoted is not using $(CC) as the compiler, but is using it to
> link the final build product.  It may not hurt to have $(CFLAGS) on that
> line, but shouldn't the line also have $(LDFLAGS) on it?

I think so. Why don't we do this?

-- >8 --
Subject: osxkeychain: pull make config from top-level directory

The default compiler and cflags were mostly "works for me"
when I built the original version. We need to be much less
careful here than usual, because we know we are building
only on OS X.  But it's only polite to at least respect the
CFLAGS and CC definitions that the user may have provided
earlier.

While we're at it, let's update our definitions and rules to
be more like the top-level Makefile; default our CFLAGS to
include -O2, and make sure we use CFLAGS and LDFLAGS when
linking.

Signed-off-by: Jeff King <peff@peff.net>
---
 contrib/credential/osxkeychain/Makefile | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/contrib/credential/osxkeychain/Makefile b/contrib/credential/osxkeychain/Makefile
index 75c07f8..4b3a08a 100644
--- a/contrib/credential/osxkeychain/Makefile
+++ b/contrib/credential/osxkeychain/Makefile
@@ -2,10 +2,13 @@ all:: git-credential-osxkeychain
 
 CC = gcc
 RM = rm -f
-CFLAGS = -g -Wall
+CFLAGS = -g -O2 -Wall
+
+-include ../../../config.mak.autogen
+-include ../../../config.mak
 
 git-credential-osxkeychain: git-credential-osxkeychain.o
-	$(CC) -o $@ $< -Wl,-framework -Wl,Security
+	$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) -Wl,-framework -Wl,Security
 
 git-credential-osxkeychain.o: git-credential-osxkeychain.c
 	$(CC) -c $(CFLAGS) $<
-- 
1.7.9.7.35.gbeaaf11

```

## Junio C Hamano, 2012-05-24 17:35

Subject: Re: contrib/credential/osxkeychain: Makefile should allow to set CFLAGS
Message-ID: <7vaa0xxz14.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vaa0xxz14.fsf%40alter.siamese.dyndns.org
In-Reply-To: <20120523173653.GA29458@sigill.intra.peff.net>

```
Jeff King <peff@peff.net> writes:

> On Tue, May 22, 2012 at 02:00:05PM -0700, Junio C Hamano wrote:
>
>> It however seems to me that git-credential-osxkeychain.o does honor
>> $(CFLAGS), either from the user "make CFLAGS=..." or the default the
>> Makefile in question supplies.
>> 
>> The line you quoted is not using $(CC) as the compiler, but is using it to
>> link the final build product.  It may not hurt to have $(CFLAGS) on that
>> line, but shouldn't the line also have $(LDFLAGS) on it?
>
> I think so. Why don't we do this?

I am OK with that.

CFLAGS/LDFLAGS that come from ../../../config.mak _might_ not be suitable
for this binary, but I do not think of a concrete example how that could
be.  Besides, this is just an example in contrib/ so I'd not worry about
it too much.

Thanks.

> -- >8 --
> Subject: osxkeychain: pull make config from top-level directory
>
> The default compiler and cflags were mostly "works for me"
> when I built the original version. We need to be much less
> careful here than usual, because we know we are building
> only on OS X.  But it's only polite to at least respect the
> CFLAGS and CC definitions that the user may have provided
> earlier.
>
> While we're at it, let's update our definitions and rules to
> be more like the top-level Makefile; default our CFLAGS to
> include -O2, and make sure we use CFLAGS and LDFLAGS when
> linking.
>
> Signed-off-by: Jeff King <peff@peff.net>
> ---
>  contrib/credential/osxkeychain/Makefile | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/contrib/credential/osxkeychain/Makefile b/contrib/credential/osxkeychain/Makefile
> index 75c07f8..4b3a08a 100644
> --- a/contrib/credential/osxkeychain/Makefile
> +++ b/contrib/credential/osxkeychain/Makefile
> @@ -2,10 +2,13 @@ all:: git-credential-osxkeychain
>  
>  CC = gcc
>  RM = rm -f
> -CFLAGS = -g -Wall
> +CFLAGS = -g -O2 -Wall
> +
> +-include ../../../config.mak.autogen
> +-include ../../../config.mak
>  
>  git-credential-osxkeychain: git-credential-osxkeychain.o
> -	$(CC) -o $@ $< -Wl,-framework -Wl,Security
> +	$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) -Wl,-framework -Wl,Security
>  
>  git-credential-osxkeychain.o: git-credential-osxkeychain.c
>  	$(CC) -c $(CFLAGS) $<

```

## Jeff King, 2012-05-24 17:51

Subject: Re: contrib/credential/osxkeychain: Makefile should allow to set CFLAGS
Message-ID: <20120524175143.GD3161@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20120524175143.GD3161%40sigill.intra.peff.net
In-Reply-To: <7vaa0xxz14.fsf@alter.siamese.dyndns.org>

```
On Thu, May 24, 2012 at 10:35:35AM -0700, Junio C Hamano wrote:

> > I think so. Why don't we do this?
> 
> I am OK with that.
> 
> CFLAGS/LDFLAGS that come from ../../../config.mak _might_ not be suitable
> for this binary, but I do not think of a concrete example how that could
> be.  Besides, this is just an example in contrib/ so I'd not worry about
> it too much.

Yeah, I considered that, but I figured that what you have in config.mak
is _at least_ as sensible as the random defaults I stuck in the
Makefile.  And overriding with "make CFLAGS=..." is still available.

-Peff

```
