Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Computers don't actually think. You just think they think. (We think.)


devel / comp.unix.programmer / Re: on gcc, make and CFLAGS

SubjectAuthor
* on gcc, make and CFLAGSMeredith Montgomery
+- Re: on gcc, make and CFLAGSBen Bacarisse
+- Re: on gcc, make and CFLAGSJames Kuyper
+- Re: on gcc, make and CFLAGSJorgen Grahn
`* Re: on gcc, make and CFLAGSScott Lurndal
 `- Re: on gcc, make and CFLAGSKeith Thompson

1
on gcc, make and CFLAGS

<86sfvrj0w6.fsf@levado.to>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16819&group=comp.unix.programmer#16819

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!aioe.org!A5viUP7ZdBSpM8+So1ywOw.user.46.165.242.75.POSTED!not-for-mail
From: mmontgomery@levado.to (Meredith Montgomery)
Newsgroups: comp.unix.programmer
Subject: on gcc, make and CFLAGS
Date: Fri, 19 Nov 2021 18:23:05 -0300
Organization: Aioe.org NNTP Server
Message-ID: <86sfvrj0w6.fsf@levado.to>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="9804"; posting-host="A5viUP7ZdBSpM8+So1ywOw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
Cancel-Lock: sha1:HhF544t9MJsXC14mukGPBsG05Tg=
X-Notice: Filtered by postfilter v. 0.9.2
 by: Meredith Montgomery - Fri, 19 Nov 2021 21:23 UTC

It seems to me that gcc by default doesn't read CFLAGS.

%echo $CFLAGS
-Wall

%cat hello.c
int main(void) {}

%gcc -c hello.c
%

Maybe it did read CFLAGS, maybe it didn't. I don't know. Does gcc care
at all about CFLAGS?

But it seems that make does look at CFLAGS by default. I have no
written Makefile (at this moment), then I say:

%make hello
cc -Wall hello.c -o hello
%

It did read CFLAGS. Nice.

Now let me write a Makefile.

%cat Makefile
hello: hello.o
gcc -o hello hello.o

hello.o: hello.c
gcc -c hello.c

%make hello
gcc -c hello.c
gcc -o hello hello.o
%

So my conclusion I must explicitly write $(CFLAGS) in the Makefile.
This makes sense --- if I tell make that the command is ``gcc -c
hello.c'', it should respect me and not add anything else.

Re: on gcc, make and CFLAGS

<87a6hzk6zj.fsf@bsb.me.uk>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16820&group=comp.unix.programmer#16820

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.usenet@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.unix.programmer
Subject: Re: on gcc, make and CFLAGS
Date: Sat, 20 Nov 2021 00:26:08 +0000
Organization: A noiseless patient Spider
Lines: 67
Message-ID: <87a6hzk6zj.fsf@bsb.me.uk>
References: <86sfvrj0w6.fsf@levado.to>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: reader02.eternal-september.org; posting-host="e4ec6f8cee676bc3835ecd7a344c2f63";
logging-data="14495"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19zl3nR5L6rOvZCkcp+hJy6pLRRCXDqUTo="
Cancel-Lock: sha1:ekSI/cVO8pqaDhrwuewNRTPflc8=
sha1:xrJLSyEp9aI7z+Vbfm6mwXjTYfk=
X-BSB-Auth: 1.5d55fdd55fca0bf650cd.20211120002608GMT.87a6hzk6zj.fsf@bsb.me.uk
 by: Ben Bacarisse - Sat, 20 Nov 2021 00:26 UTC

Meredith Montgomery <mmontgomery@levado.to> writes:

> It seems to me that gcc by default doesn't read CFLAGS.
>
> %echo $CFLAGS
> -Wall
>
> %cat hello.c
> int main(void) {}
>
> %gcc -c hello.c
> %
>
> Maybe it did read CFLAGS, maybe it didn't. I don't know.

You could make sure by introducing a mistake that -Wall would catch:

$ cat h.c
int main(void) { int x; }
$ gcc -Wall -c h.c
h.c: In function ‘main’:
h.c:1:22: warning: unused variable ‘x’ [-Wunused-variable]
1 | int main(void) { int x; }
| ^
$ gcc -c h.c
$ echo $CFLAGS
-Wall

> Does gcc care at all about CFLAGS?

No.

> But it seems that make does look at CFLAGS by default. I have no
> written Makefile (at this moment), then I say:
>
> %make hello
> cc -Wall hello.c -o hello
> %
>
> It did read CFLAGS. Nice.

GNU make's default rule (for this case) uses $(CC) $(CPPFLAGS) $(CFLAGS) -c

> Now let me write a Makefile.
>
> %cat Makefile
> hello: hello.o
> gcc -o hello hello.o
>
> hello.o: hello.c
> gcc -c hello.c
>
> %make hello
> gcc -c hello.c
> gcc -o hello hello.o
> %
>
> So my conclusion I must explicitly write $(CFLAGS) in the Makefile.
> This makes sense --- if I tell make that the command is ``gcc -c
> hello.c'', it should respect me and not add anything else.

Yup. And if you just define CFLAGS in the makefile, the default rule
will use it, but you can also ask that the value from the environment be
used instead with the -e flag to make.

--
Ben.

Re: on gcc, make and CFLAGS

<sna0bi$8ss$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16821&group=comp.unix.programmer#16821

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jameskuyper@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.unix.programmer
Subject: Re: on gcc, make and CFLAGS
Date: Sat, 20 Nov 2021 00:16:34 -0500
Organization: A noiseless patient Spider
Lines: 40
Message-ID: <sna0bi$8ss$1@dont-email.me>
References: <86sfvrj0w6.fsf@levado.to>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 20 Nov 2021 05:16:35 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="857da513e3320641dbd921ee60b3925a";
logging-data="9116"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19zzeWBRhv0gq5FBajb9m5jBnHeE3BkgRQ="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
Cancel-Lock: sha1:4zFEpkN8SlrB1E9c1zSBBQg+stI=
In-Reply-To: <86sfvrj0w6.fsf@levado.to>
Content-Language: en-US
 by: James Kuyper - Sat, 20 Nov 2021 05:16 UTC

On 11/19/21 4:23 PM, Meredith Montgomery wrote:
> It seems to me that gcc by default doesn't read CFLAGS.

Assuming you're using a unix-like system, run "man gcc" and search for
"ENVIRONMENT". It lists all of the environment variables that gcc pays
attention to, and there's quite a few of them, but CFLAGS isn't one of
them.

> But it seems that make does look at CFLAGS by default.

make automatically creates a make macro corresponding to each
environment variable that is set at the time it is run, with the same
value, unless make is invoked with a makefile, in which case make macros
that are explicitly defined by the makefile take precedence over the
values of corresponding environment variables.

> ... I have no
> written Makefile (at this moment), then I say:
>
> %make hello
> cc -Wall hello.c -o hello

Even with no makefile present, make has a fairly large number of default
rules. The set of default rules is, in general, configurable by whoever
installed make. You can execute "make -p -f /dev/null" to find out what
they are. However, a certain minimum set of rules is mandatory according
to POSIX, and those include the following:

CC=c99
CFLAGS=-O 1
LDFLAGS=

..c:
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $<

..c.o:
$(CC) $(CFLAGS) -c $<

Knowing what the default rules are can greatly simplify your use of make.

Re: on gcc, make and CFLAGS

<slrnspiqc4.1rfm.grahn+nntp@frailea.sa.invalid>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16822&group=comp.unix.programmer#16822

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.mixmin.net!news2.arglkargh.de!news.karotte.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: grahn+nntp@snipabacken.se (Jorgen Grahn)
Newsgroups: comp.unix.programmer
Subject: Re: on gcc, make and CFLAGS
Date: 20 Nov 2021 21:32:52 GMT
Lines: 86
Message-ID: <slrnspiqc4.1rfm.grahn+nntp@frailea.sa.invalid>
References: <86sfvrj0w6.fsf@levado.to>
X-Trace: individual.net NXtdJfwGJaosIyVerUXOKQ7ENDSiz38tCvlYUV2fQzEmLMkIg8
Cancel-Lock: sha1:eKKlkxOyiSpwhKdYaMHLBum6oVU=
User-Agent: slrn/1.0.3 (OpenBSD)
 by: Jorgen Grahn - Sat, 20 Nov 2021 21:32 UTC

On Fri, 2021-11-19, Meredith Montgomery wrote:
> It seems to me that gcc by default doesn't read CFLAGS.
>
> %echo $CFLAGS
> -Wall
>
> %cat hello.c
> int main(void) {}
>
> %gcc -c hello.c
> %
>
> Maybe it did read CFLAGS, maybe it didn't. I don't know. Does gcc care
> at all about CFLAGS?
>
> But it seems that make does look at CFLAGS by default. I have no
> written Makefile (at this moment), then I say:
>
> %make hello
> cc -Wall hello.c -o hello
> %
>
> It did read CFLAGS. Nice.
>
> Now let me write a Makefile.
>
> %cat Makefile
> hello: hello.o
> gcc -o hello hello.o
>
> hello.o: hello.c
> gcc -c hello.c
>
> %make hello
> gcc -c hello.c
> gcc -o hello hello.o
> %
>
> So my conclusion I must explicitly write $(CFLAGS) in the Makefile.
> This makes sense --- if I tell make that the command is ``gcc -c
> hello.c'', it should respect me and not add anything else.

It's a bit unclear what you want to do, if you need to use old make
implementations or can stick to GNU Make, and if you've read the
documentation.

What I always do is put something like this in the Makefile:

CFLAGS=-W -Wall -pedantic -ansi -g -Os
CXXFLAGS=-W -Wall -pedantic -std=c++14 -g -Os
CPPFLAGS=-Isome/where -Dsomething

With the builtin GNU Make rules, that's enough to compile C and C++
to object code. Note that I split cpp[1] stuff into CPPFLAGS.

If I want to override things and I don't want to edit the Makefile --
and this happens very rarely -- I tend not to use the environment, but
this syntax:

% make CFLAGS=-std=c99 foo.o

Oddly, I cannot find that in the GNU Make manual. Not where it should
be, anyway.

I know there are rules for when GNU Make picks stuff from the
environment, and when it doesn't. Those /are/ documented.

I never could figure out how to use the builtin rules for linking,
so I write that rule explicitly.

Lastly, I actually override the whole .o: .c rule, since I enable
automatic dependency generation with the help of gcc. But that's
orthogonal to the CFLAGS stuff.

There's an example here (the code is mostly C++ but that doesn't
matter):

https://github.com/kjgrahn/gavia

/Jorgen

[1] That's the C preprocessor, not an alternative name for C++.

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .

Re: on gcc, make and CFLAGS

<3PtmJ.116414$IW4.102934@fx48.iad>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16823&group=comp.unix.programmer#16823

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.ams4!peer.am4.highwinds-media.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx48.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: scott@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: on gcc, make and CFLAGS
Newsgroups: comp.unix.programmer
References: <86sfvrj0w6.fsf@levado.to>
Lines: 29
Message-ID: <3PtmJ.116414$IW4.102934@fx48.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Sun, 21 Nov 2021 15:43:59 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Sun, 21 Nov 2021 15:43:59 GMT
X-Received-Bytes: 1495
 by: Scott Lurndal - Sun, 21 Nov 2021 15:43 UTC

Meredith Montgomery <mmontgomery@levado.to> writes:
>It seems to me that gcc by default doesn't read CFLAGS.

gcc knows nothing about CFLAGS, nor does it generally
use environment variables.

CFLAGS is a make variable that is part of the default rule
for compling C source files.

$ make -p

will print the default rules. The default rule for C is:

CC = cc
COMPILE.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c

%.o: %.c
# recipe to execute (built-in):
$(COMPILE.c) $(OUTPUT_OPTION) $<

One can always override such rules in the Makefile, for example:

%.o $(OBJDIR)/%.o: %.c
@$(QUIET) || echo " COMPILE $<"
$(HUSHCOMPILE)$(CC) $(CFLAGS) -MMD -MP -o $@ -c $<

QUIET can be either "true" or "false".
HUSHCOMPILE can be not present or set to "@".

Re: on gcc, make and CFLAGS

<87y25hi3vx.fsf@nosuchdomain.example.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16824&group=comp.unix.programmer#16824

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S.Thompson+u@gmail.com (Keith Thompson)
Newsgroups: comp.unix.programmer
Subject: Re: on gcc, make and CFLAGS
Date: Sun, 21 Nov 2021 13:40:34 -0800
Organization: None to speak of
Lines: 21
Message-ID: <87y25hi3vx.fsf@nosuchdomain.example.com>
References: <86sfvrj0w6.fsf@levado.to> <3PtmJ.116414$IW4.102934@fx48.iad>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="a1aa0dcd5f82470090faf86702e2798a";
logging-data="30671"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19q/lmW14ONqa9X77q86zXZ"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:TB5fxN3o2nYOwQv7jzQt6TcqeAU=
sha1:+s3MFX9uxcbIvH8Osu9SDsomVgA=
 by: Keith Thompson - Sun, 21 Nov 2021 21:40 UTC

scott@slp53.sl.home (Scott Lurndal) writes:
> Meredith Montgomery <mmontgomery@levado.to> writes:
>>It seems to me that gcc by default doesn't read CFLAGS.
>
> gcc knows nothing about CFLAGS,

True.

> nor does it generally
> use environment variables.

Not quite true.

https://gcc.gnu.org/onlinedocs/gcc-11.2.0/gcc/Environment-Variables.html

[...]

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor