9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] trouble with include order using c compiler with ansi preprocessor
@ 2007-06-10 16:35 Kim Shrier
  2007-06-10 17:27 ` [9fans] trouble with include order using c compiler with ansi Charles Forsyth
  2007-06-10 18:10 ` [9fans] trouble with include order using c compiler with ansi preprocessor Martin Neubauer
  0 siblings, 2 replies; 13+ messages in thread
From: Kim Shrier @ 2007-06-10 16:35 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Hello,

I am exploring the tools on Plan 9 and I am having a problem
getting the correct files to be included.  My test setup is
that I have a directory with C source and headers.  In a sub-
directory, I have the plan 9 mkfile and a customized version
of one of the header files.  I would like the C compiler to
find my customized version of the header instead of the one
in the original source directory.

The desired results of running my test is:
cpu% cd source/plan9
cpu% mk
cpu% ./main
MSG = this is from plan9/inc1.h
MSG2 = this is from inc2.h
cpu%

However, everything I have tried results in:
cpu% ./main
MSG = this is from inc1.h
MSG2 = this is from inc2.h
cpu%

The files I am using for the test are:

source/
     inc1.h
     inc2.h
     main.c
     plan9/
         inc1.h
         mkfile


inc1.h:
#define MSG "this is from inc1.h"

inc2.h:
#define MSG2 "this is from inc2.h"

main.c:
#include <u.h>
#include <libc.h>

#include "inc1.h"
#include "inc2.h"

void
main (int argc, char *argv[])
{
	print ("MSG = %s\n", MSG);
	print ("MSG2 = %s\n", MSG2);

	exits (0);
}


plan9/inc1.h:
#define MSG "this is from plan9/inc1.h"

plan9/mkfile
</$objtype/mkfile

CFLAGS=-p -N -.
LDFLAGS=

main: main.$O
	$LD $LDFLAGS -o main main.$O

main.$O: ../main.c
	$CC $CFLAGS ../main.c

clean:V:
	rm -f main main.$O


I have tried many combinations of -N, -., -I., -I.., and nothing
seems to work.  I would expect that the above CFLAGS definition
would cause the compiler to not find either inc1.h or inc2.h.
However, even with CFLAGS=-p -N -., it finds both the header files
in source.

If I do not use the ANSI preprocessor, setting CFLAGS=-. -I. -I..
works.

I am running on a Plan 9 cpu server that I updated on May 18.

Any enlightenment would be appreciated.

Kim


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [9fans] trouble with include order using c compiler with ansi
  2007-06-10 16:35 [9fans] trouble with include order using c compiler with ansi preprocessor Kim Shrier
@ 2007-06-10 17:27 ` Charles Forsyth
  2007-06-10 17:44   ` Kim Shrier
  2007-06-10 18:10 ` [9fans] trouble with include order using c compiler with ansi preprocessor Martin Neubauer
  1 sibling, 1 reply; 13+ messages in thread
From: Charles Forsyth @ 2007-06-10 17:27 UTC (permalink / raw)
  To: 9fans

> Any enlightenment would be appreciated.

cpp doesn't understand -.



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [9fans] trouble with include order using c compiler with ansi
  2007-06-10 17:27 ` [9fans] trouble with include order using c compiler with ansi Charles Forsyth
@ 2007-06-10 17:44   ` Kim Shrier
  0 siblings, 0 replies; 13+ messages in thread
From: Kim Shrier @ 2007-06-10 17:44 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Jun 10, 2007, at 11:27 AM, Charles Forsyth wrote:

>> Any enlightenment would be appreciated.
>
> cpp doesn't understand -.
>

Yes, the reason I put -. in CFLAGS is because it is a
parameter to the C compiler.  However, I have tried it
with and without -. and with and without -N.  I have
also tried the following command:

cpp -N ../main.c

It correctly does not find any of the include files.  But,
if I try:

cpp -N -I/sys/include -I/386/include ../main.c

It finds all of the include files.  It should not be
finding inc1.h or inc2.h if I read the man page correctly.
It finds both of these files in ..

This seems like a bug to me.

Kim



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [9fans] trouble with include order using c compiler with ansi preprocessor
  2007-06-10 16:35 [9fans] trouble with include order using c compiler with ansi preprocessor Kim Shrier
  2007-06-10 17:27 ` [9fans] trouble with include order using c compiler with ansi Charles Forsyth
@ 2007-06-10 18:10 ` Martin Neubauer
  2007-06-10 19:24   ` Kim Shrier
  2007-06-10 19:26   ` erik quanstrom
  1 sibling, 2 replies; 13+ messages in thread
From: Martin Neubauer @ 2007-06-10 18:10 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

The way I understand the man page, the -N option just suppresses the
predefined include paths. What you seem to want ist the -. option which, as
Charles mentioned, cpp does not support. But as I see it all of those
options really should be necessary in but very isolated cases. You might
consider reorganising your header files. Otherwise you'll end up with those
horrible compiling commands that are so common in modern Unix[sic].

	Martin



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [9fans] trouble with include order using c compiler with ansi preprocessor
  2007-06-10 18:10 ` [9fans] trouble with include order using c compiler with ansi preprocessor Martin Neubauer
@ 2007-06-10 19:24   ` Kim Shrier
  2007-06-10 19:26   ` erik quanstrom
  1 sibling, 0 replies; 13+ messages in thread
From: Kim Shrier @ 2007-06-10 19:24 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Jun 10, 2007, at 12:10 PM, Martin Neubauer wrote:

> The way I understand the man page, the -N option just suppresses the
> predefined include paths. What you seem to want ist the -. option
> which, as
> Charles mentioned, cpp does not support. But as I see it all of those
> options really should be necessary in but very isolated cases. You
> might
> consider reorganising your header files. Otherwise you'll end up
> with those
> horrible compiling commands that are so common in modern Unix[sic].
>
> 	Martin

You're right.  I should approach this problem differently.
I need to get out of the UNIX mind set.

Kim



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [9fans] trouble with include order using c compiler with ansi preprocessor
  2007-06-10 18:10 ` [9fans] trouble with include order using c compiler with ansi preprocessor Martin Neubauer
  2007-06-10 19:24   ` Kim Shrier
@ 2007-06-10 19:26   ` erik quanstrom
  2007-06-10 20:07     ` Russ Cox
  2007-06-10 20:44     ` Kim Shrier
  1 sibling, 2 replies; 13+ messages in thread
From: erik quanstrom @ 2007-06-10 19:26 UTC (permalink / raw)
  To: 9fans

i think there is a real bug here.  -N is not really relevant.

cc/lex.c:51 includes the current directory to be first in the include
search path.  i think the loop at lex.c:237 should start with index 1,
not zero, so as not to confuse pcc, i.e.

			for(c = 0; c < ninclude; c++) {
				sprint(opt, "-I%s", include[c]);
				av[i++] = strdup(opt);
			}

should become

			for(c = 1; c < ninclude; c++) {
				sprint(opt, "-I%s", include[c]);
				av[i++] = strdup(opt);
			}

doing includes like you are is not quite the plan 9 style, but the point
of pcc is to accomidate.

- erik



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [9fans] trouble with include order using c compiler with ansi preprocessor
  2007-06-10 19:26   ` erik quanstrom
@ 2007-06-10 20:07     ` Russ Cox
  2007-06-10 20:44     ` Kim Shrier
  1 sibling, 0 replies; 13+ messages in thread
From: Russ Cox @ 2007-06-10 20:07 UTC (permalink / raw)
  To: 9fans

the best thing you could do is just

	rm inc1.h

and then use -Iplan9.  a more plan 9 like solution is to do one of

	bind plan9/inc1.h inc1.h
	bind -b plan9 .

but both of those are likely to confuse things in the future.

it turns out, accidentally i am sure, that you can also

	chmod 0 inc1.h

and then cpp will not be able to read it and it will move
on to plan9/inc1.h.

> cc/lex.c:51 includes the current directory to be first in the include
> search path.  i think the loop at lex.c:237 should start with index 1,
> not zero, so as not to confuse pcc, i.e.
>
> 			for(c = 0; c < ninclude; c++) {
> 				sprint(opt, "-I%s", include[c]);
> 				av[i++] = strdup(opt);
> 			}
>
> should become
>
> 			for(c = 1; c < ninclude; c++) {
> 				sprint(opt, "-I%s", include[c]);
> 				av[i++] = strdup(opt);
> 			}
>
> doing includes like you are is not quite the plan 9 style, but the point
> of pcc is to accomidate.

this will have no effect.
it will stop passing -I. to cpp,
but cpp already searches . first no matter what its options are.

#include <foo.h> means find foo.h in the -I directories or else in a standard directory.
#include "foo.h" means find foo.h in the current directory or else like <foo.h>

these rules are not specified by ansi, but it's what other unix compilers do too.

russ



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [9fans] trouble with include order using c compiler with ansi preprocessor
  2007-06-10 19:26   ` erik quanstrom
  2007-06-10 20:07     ` Russ Cox
@ 2007-06-10 20:44     ` Kim Shrier
  2007-06-10 22:02       ` Uriel
  2007-06-11  7:51       ` Steve Simon
  1 sibling, 2 replies; 13+ messages in thread
From: Kim Shrier @ 2007-06-10 20:44 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Jun 10, 2007, at 1:26 PM, erik quanstrom wrote:

> doing includes like you are is not quite the plan 9 style, but the
> point
> of pcc is to accomidate.

What I am experimenting with is porting a program, which I didn't write,
from UNIX to Plan 9.  The source is already littered with #if's and
#ifdef's
for various environments.  Because there are #if's, I wanted to use the
ANSI preprocessor.  In order to avoid adding to the conditional compile
nightmare, I thought I would make Plan 9 versions of the appropriate
header
files and set up the include path to find the Plan 9 versions instead of
the UNIX ones.

As has been mentioned in several emails, this is not the Plan 9 style.
Since one of the main goals of my experimentation is to learn the Plan 9
way of doing things, I would like to hear any recommendations regarding
this.  One recommendation mentioned in another email was to use bind to
alias the old include file to the Plan 9 version.  Is this the preferred
way?  Are there other, more desirable ways to accomplish this?

Thanks,
Kim


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [9fans] trouble with include order using c compiler with ansi preprocessor
  2007-06-10 20:44     ` Kim Shrier
@ 2007-06-10 22:02       ` Uriel
  2007-06-10 22:47         ` Kim Shrier
  2007-06-11  7:51       ` Steve Simon
  1 sibling, 1 reply; 13+ messages in thread
From: Uriel @ 2007-06-10 22:02 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> As has been mentioned in several emails, this is not the Plan 9 style.
> Since one of the main goals of my experimentation is to learn the Plan 9
> way of doing things, I would like to hear any recommendations regarding
> this.  One recommendation mentioned in another email was to use bind to
> alias the old include file to the Plan 9 version.  Is this the preferred
> way?  Are there other, more desirable ways to accomplish this?

The most desirable way is not to use (so called) 'UNIX software' at
all (which this days is little more than an euphemism for GNU/PoSix
mountains of crud).

Best wishes

uriel


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [9fans] trouble with include order using c compiler with ansi preprocessor
  2007-06-10 22:02       ` Uriel
@ 2007-06-10 22:47         ` Kim Shrier
  2007-06-11  0:10           ` Kris Maglione
  0 siblings, 1 reply; 13+ messages in thread
From: Kim Shrier @ 2007-06-10 22:47 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Jun 10, 2007, at 4:02 PM, Uriel wrote:

> The most desirable way is not to use (so called) 'UNIX software' at
> all (which this days is little more than an euphemism for GNU/PoSix
> mountains of crud).
>
> Best wishes
>
> uriel

I do agree with your assessment of GNU/Posix software.  However, I would
like to use this program that already runs on UNIX and (shudder)
Windows,
on Plan 9.  I always hate it when people use the expediency argument on
me but the quickest way to get this running on Plan 9 is to port it
over.
My intent, after I get it running, is to look at the software in detail
and see how I can adapt it to use Plan 9 idioms to get its job done.
Since
I won't need to port the Plan 9 updates back, I can be quite ruthless in
my rewriting.

Essentially, I am trying to go from accounting to lion taming via
banking.

Also, since the software is being maintained by other people, I will
want
to pick up current versions of the source from time to time and apply my
updates to it.  I was trying to isolate my source modifications to
make it
easier to keep track of what I changed vs. the original code without
having
to maintain a huge patch file.

Kim


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [9fans] trouble with include order using c compiler with ansi preprocessor
  2007-06-10 22:47         ` Kim Shrier
@ 2007-06-11  0:10           ` Kris Maglione
  2007-06-11  1:41             ` Kim Shrier
  0 siblings, 1 reply; 13+ messages in thread
From: Kris Maglione @ 2007-06-11  0:10 UTC (permalink / raw)
  To: 9fans

[-- Attachment #1: Type: text/plain, Size: 790 bytes --]

On Sun, Jun 10, 2007 at 04:47:52PM -0600, Kim Shrier wrote:
> I do agree with your assessment of GNU/Posix software.  However, I would
> like to use this program that already runs on UNIX and (shudder) Windows,
> on Plan 9.  I always hate it when people use the expediency argument on
> me but the quickest way to get this running on Plan 9 is to port it over.
> My intent, after I get it running, is to look at the software in detail
> and see how I can adapt it to use Plan 9 idioms to get its job done.  Since
> I won't need to port the Plan 9 updates back, I can be quite ruthless in
> my rewriting.

Are you trying for an APE or native port? If APE, what is it that needs 
modifications?

-- 
Kris Maglione

The deficiency will never show itself during the test runs.

[-- Attachment #2: Type: application/pgp-signature, Size: 194 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [9fans] trouble with include order using c compiler with ansi preprocessor
  2007-06-11  0:10           ` Kris Maglione
@ 2007-06-11  1:41             ` Kim Shrier
  0 siblings, 0 replies; 13+ messages in thread
From: Kim Shrier @ 2007-06-11  1:41 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Jun 10, 2007, at 6:10 PM, Kris Maglione wrote:
>
> Are you trying for an APE or native port? If APE, what is it that
> needs modifications?
>
> --
> Kris Maglione
>
> The deficiency will never show itself during the test runs.

I am trying for a native port.  If I rewrite the main header file and
the
main program file, I think that it will take care of 90% of the issues.
It's the other 10% that will take the second 90% of the porting effort.

Kim



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [9fans] trouble with include order using c compiler with ansi preprocessor
  2007-06-10 20:44     ` Kim Shrier
  2007-06-10 22:02       ` Uriel
@ 2007-06-11  7:51       ` Steve Simon
  1 sibling, 0 replies; 13+ messages in thread
From: Steve Simon @ 2007-06-11  7:51 UTC (permalink / raw)
  To: 9fans

The "plan9 way" to solve the problem of supporting different OSs in your
program is to factor out the os specific parts and put them in a single file
(eg macos.c linux.c, plan9.c etc) and a matching set of makefiles (make.macos, make.unix,
(plan9 would have a mkfile of course)).

The best example of this I know is portable version of the sam the editor
/sys/src/cmd/unix/sam - sadly the plan9 version has diverged from this
over the years but the principal is still valid.

-Steve


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2007-06-11  7:51 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-10 16:35 [9fans] trouble with include order using c compiler with ansi preprocessor Kim Shrier
2007-06-10 17:27 ` [9fans] trouble with include order using c compiler with ansi Charles Forsyth
2007-06-10 17:44   ` Kim Shrier
2007-06-10 18:10 ` [9fans] trouble with include order using c compiler with ansi preprocessor Martin Neubauer
2007-06-10 19:24   ` Kim Shrier
2007-06-10 19:26   ` erik quanstrom
2007-06-10 20:07     ` Russ Cox
2007-06-10 20:44     ` Kim Shrier
2007-06-10 22:02       ` Uriel
2007-06-10 22:47         ` Kim Shrier
2007-06-11  0:10           ` Kris Maglione
2007-06-11  1:41             ` Kim Shrier
2007-06-11  7:51       ` Steve Simon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).