threads / patch / 1977

patchSupport SPARSE in Makefile, better SPARSE_FLAGS

Subject: [PATCH] Support SPARSE in Makefile, better SPARSE_FLAGS

## tl;dr

7 messages between Sep 29, 2005 and Oct 1, 2005. Diffs are folded; open one to read it.

replies: 6people: 3as markdown or json

Pavel Roskin· Sep 29, 2005, 20:46 UTC · lore
Support SPARSE in Makefile, better SPARSE_FLAGS

This patch makes it possible to use some other program instead of sparse (e.g. a wrapper around sparse). It also provides a better default for SPARSE_FLAGS. __BIG_ENDIAN__ should not be needed.

Signed-off-by: Pavel Roskin <proski@gnu.org>
Show changes to Makefile +4 −3
diff --git a/Makefile b/Makefile
--- a/Makefile
+++ b/Makefile
@@ -66,8 +66,9 @@ INSTALL = install
 RPMBUILD = rpmbuild
 
 # sparse is architecture-neutral, which means that we need to tell it
-# explicitly what architecture to check for. Fix this up for yours..
-SPARSE_FLAGS = -D__BIG_ENDIAN__ -D__powerpc__
+# explicitly what architecture to check for.
+SPARSE = sparse
+SPARSE_FLAGS = -D__$(shell uname -i)__
 
 
 
@@ -335,7 +336,7 @@ test-delta: test-delta.c diff-delta.o pa
 	$(CC) $(ALL_CFLAGS) -o $@ $^
 
 check:
-	for i in *.c; do sparse $(ALL_CFLAGS) $(SPARSE_FLAGS) $$i; done
+	for i in *.c; do $(SPARSE) $(ALL_CFLAGS) $(SPARSE_FLAGS) $$i; done
 
 
 
-- 
Regards,
Pavel Roskin
Junio C Hamano· Sep 30, 2005, 05:46 UTC · re: Pavel Roskin · lore

Re: [PATCH] Support SPARSE in Makefile, better SPARSE_FLAGS

Pavel Roskin <proski@gnu.org> writes:
> +# explicitly what architecture to check for.
> +SPARSE = sparse
> +SPARSE_FLAGS = -D__$(shell uname -i)__
        : siamese; uname --version
        uname (coreutils) 5.2.1
        Written by David MacKenzie.
        Copyright (C) 2004 Free Software Foundation, Inc.
        This is free software; see the source for copying conditions.
        There is NO
        warranty; not even for MERCHANTABILITY or FITNESS FOR A
        PARTICULAR PURPOSE.
        : siamese; uname -i
        Try `uname --help' for more information.
Better alternatives?
Pavel Roskin· Sep 30, 2005, 13:41 UTC · re: Junio C Hamano · lore

Re: [PATCH] Support SPARSE in Makefile, better SPARSE_FLAGS

On Thu, 2005-09-29 at 22:46 -0700, Junio C Hamano wrote:
Show 9 quoted lines
> Pavel Roskin <proski@gnu.org> writes:
> 
> > +# explicitly what architecture to check for.
> > +SPARSE = sparse
> > +SPARSE_FLAGS = -D__$(shell uname -i)__
> 
>         : siamese; uname --version
>         uname (coreutils) 5.2.1
>         Written by David MacKenzie.

Apparently my uname 5.2.1 was heavily patched by Fedora. Note that "uname -m" is not good enough, as it would give us i686 when i386 is really needed.

Show 9 quoted lines
>         Copyright (C) 2004 Free Software Foundation, Inc.
>         This is free software; see the source for copying conditions.
>         There is NO
>         warranty; not even for MERCHANTABILITY or FITNESS FOR A
>         PARTICULAR PURPOSE.
>         : siamese; uname -i
>         Try `uname --help' for more information.
> 
> Better alternatives?

I hate to say that, but a better alternative is to fix sparse to act like the native compiler by default (possibly with options to imitate other architectures or to be fully arch-neutral).

I have some hacks in mind, but I don't really like them:

Not good for i686 with unpatched uname: SPARSE_FLAGS = __$(shell uname -i 2>/dev/null || uname -m)__

gcc specific: SPARSE_FLAGS = __$(shell $CC -dumpmachine | sed 's/-.*//')__

bash specific: SPARSE_FLAGS = __$(shell echo $$HOSTTYPE)__

In any case, having SPARSE variable would be convenient.
-- 
Regards,
Pavel Roskin
H. Peter Anvin· Sep 30, 2005, 19:19 UTC · re: Pavel Roskin · lore

Re: [PATCH] Support SPARSE in Makefile, better SPARSE_FLAGS

Pavel Roskin wrote:
Show 5 quoted lines
> 
> I hate to say that, but a better alternative is to fix sparse to act
> like the native compiler by default (possibly with options to imitate
> other architectures or to be fully arch-neutral).
> 
$(CC) $(CFLAGS) -E -dM -x c /dev/null -o builtin.h

... will output a file containing all the buildin macros that you can feed to sparse with -include.

Replacing -x c with, say, -x c++ gives you the builtins for C++; including $(CFLAGS) gives the appropriate set of macros for any particular combination of options (which can affect the builtin macro set.)

	-hpa
Pavel Roskin· Sep 30, 2005, 22:14 UTC · re: H. Peter Anvin · lore

Re: [PATCH] Support SPARSE in Makefile, better SPARSE_FLAGS

On Fri, 2005-09-30 at 12:19 -0700, H. Peter Anvin wrote:
Show 11 quoted lines
> Pavel Roskin wrote:
> > 
> > I hate to say that, but a better alternative is to fix sparse to act
> > like the native compiler by default (possibly with options to imitate
> > other architectures or to be fully arch-neutral).
> > 
> 
> $(CC) $(CFLAGS) -E -dM -x c /dev/null -o builtin.h
> 
> ... will output a file containing all the buildin macros that you can 
> feed to sparse with -include.

I know. That's what I'm using in the wrapper (plus -m64 and some warnings). But it should be the default. Until then, hassle-free sparse support in the Makefile is only possible for the projects that already know the architecture (e.g. the Linux kernel).

-- 
Regards,
Pavel Roskin
H. Peter Anvin· Sep 30, 2005, 22:16 UTC · re: Pavel Roskin · lore

Re: [PATCH] Support SPARSE in Makefile, better SPARSE_FLAGS

Pavel Roskin wrote:
Show 6 quoted lines
> 
> I know.  That's what I'm using in the wrapper (plus -m64 and some
> warnings).  But it should be the default.  Until then, hassle-free
> sparse support in the Makefile is only possible for the projects that
> already know the architecture (e.g. the Linux kernel).
> 

I think that's debatable. It introduces main-compiler dependencies into sparse which is undesirable.

A much simpler option would be to write a "sparsegcc" script which would be invoked just like gcc, extract the appropriate macro information based on options, and then invoke sparse.

	-hpa
Pavel Roskin· Oct 1, 2005, 04:13 UTC · re: H. Peter Anvin · lore

Re: [PATCH] Support SPARSE in Makefile, better SPARSE_FLAGS

Quoting "H. Peter Anvin" <hpa@zytor.com>:
Show 10 quoted lines
> Pavel Roskin wrote:
> >
> > I know.  That's what I'm using in the wrapper (plus -m64 and some
> > warnings).  But it should be the default.  Until then, hassle-free
> > sparse support in the Makefile is only possible for the projects that
> > already know the architecture (e.g. the Linux kernel).
> >
>
> I think that's debatable.  It introduces main-compiler dependencies into
> sparse which is undesirable.

I see sparse is already moving in this direction. Right now, it's somewhere in the middle, which is quite inconvenient. It hardcodes gcc version numbers but not the architecture.

> A much simpler option would be to write a "sparsegcc" script which would
> be invoked just like gcc, extract the appropriate macro information
> based on options, and then invoke sparse.

I guess that's what cgcc is trying to be. Since it also runs the compiler, no special support for cgcc should be needed in Makefile other than using $(CC).

-- Regards, Pavel Roskin

← back to recent threads