simple problem with mk on osx: MKSHELL and other environment variables

38 views
Skip to first unread message

ron minnich

unread,
Apr 19, 2012, 8:04:30 PM4/19/12
to plan9port
I hope it's simple. Looking at the source I thought this ought to work:

rminnich-macbookair:libc rminnich$ echo $objtype
amd64
rminnich-macbookair:libc rminnich$ echo $MKSHELL
/usr/local/plan9/bin/rc
rminnich-macbookair:libc rminnich$ mk
for(i in 9sys 9syscall fmt port thr $objtype)@{
echo $i
cd $i
mk $MKFLAGS install
}
sh: line 1: syntax error near unexpected token `('
mk: for(i in 9sys ... : exit status=exit(2)

Noce it did not pick up MKSHELL: it used rc. But it also is not
getting objtype (you can only see it failing with dtruss).

Is there some simple thing I'm missing here?

ron

David du Colombier

unread,
Apr 20, 2012, 4:03:32 AM4/20/12
to plan9p...@googlegroups.com
I don't really understand your question.

In my sense, the MKSHELL is a definition of the mkfile,
not your environment.

It is defined in $PLAN9/src/cmd/mk/shell.c.

Why should the MKSHELL variable be imported from your
environment?

However, the other variables are correctly imported
into the mkfile, as expected.

% cat mkfile
<$PLAN9/src/mkhdr
all:
echo $objtype
% mk
echo $objtype

% objtype=386 mk
echo $objtype
386

--
David du Colombier

ron minnich

unread,
Apr 20, 2012, 11:51:36 AM4/20/12
to 0in...@gmail.com, plan9p...@googlegroups.com
On Fri, Apr 20, 2012 at 1:03 AM, David du Colombier <0in...@gmail.com> wrote:
> I don't really understand your question.
>
> In my sense, the MKSHELL is a definition of the mkfile,
> not your environment.

It is a variable. Why should it be different from any other mkfile
variable? I printed out the variables read in by code in env.c and
there is nothing special. It is inserted as any other variable.

>
> Why should the MKSHELL variable be imported from your
> environment?

Because it's a variable. Because I need mk to use rc and I'm on OSX. I
am not in a situation where I can change the mkfile in question as it
needs to work on Plan 9 and unix-like systems. So it has to come from
the environment.

Anyway, if someone else has looked at the code I'd be curious as to
what you think.


ron

David du Colombier

unread,
Apr 20, 2012, 1:49:14 PM4/20/12
to plan9p...@googlegroups.com
> It is a variable. Why should it be different from any other mkfile
> variable? I printed out the variables read in by code in env.c and
> there is nothing special. It is inserted as any other variable.

Yes, but it is overwritten by setvar("MKSHELL", shellcmd)
in $PLAN9/src/cmd/mk/shell.c.

The value of shellcmd is set to sh by default, then it can
be modified every time "MKSHELL=" is parsed in the mkfile.

> Because it's a variable. Because I need mk to use rc and I'm on OSX. I
> am not in a situation where I can change the mkfile in question as it
> needs to work on Plan 9 and unix-like systems. So it has to come from
> the environment.

I think I understand your problem a little better.
The following patch should do what you want.

It will set the default shell to rc if you set the
environment variable MKSHELL to rc, and sh otherwise.

diff -r 8c55dad4023c src/cmd/mk/shell.c
--- a/src/cmd/mk/shell.c
+++ b/src/cmd/mk/shell.c
@@ -5,7 +5,7 @@
&shshell
};

-Shell *shelldefault = &shshell;
+Shell *shelldefault = nil;

Shell *shellt;
Word *shellcmd;
@@ -41,6 +41,16 @@
void
initshell(void)
{
+ char *sh;
+
+ if(shelldefault == nil){
+ sh = getenv("MKSHELL");
+ if(sh && strcmp(sh, "rc") == 0)
+ shelldefault = &rcshell;
+ else
+ shelldefault = &shshell;
+ }
+
shellcmd = stow(shelldefault->name);
shellt = shelldefault;
setvar("MKSHELL", shellcmd);

Does it answer your question?

--
David du Colombier

ron minnich

unread,
Apr 20, 2012, 1:58:00 PM4/20/12
to 0in...@gmail.com, plan9p...@googlegroups.com
On Fri, Apr 20, 2012 at 10:49 AM, David du Colombier <0in...@gmail.com> wrote:

> Does it answer your question?

I'll try it later today, but I think your patch would be the right way to go.

ron

ron minnich

unread,
Apr 20, 2012, 2:09:52 PM4/20/12
to 0in...@gmail.com, plan9p...@googlegroups.com
That patch does the trick. Thanks!

ron

Russ Cox

unread,
Apr 20, 2012, 5:36:29 PM4/20/12
to rmin...@gmail.com, plan9port
MKSHELL is not like other variables.
it shouldn't matter what your environment says:
whether a mkfile expects sh or rc is a property of
the mkfile, not the execution environment.

put MKSHELL=rc at the top of your mkfile.

if you want a more plan 9-like mk, change
mk/shell.c's shelldefault to be &rcshell instead
of &shshell.

russ

ron minnich

unread,
Apr 20, 2012, 5:38:04 PM4/20/12
to Russ Cox, plan9port
On Fri, Apr 20, 2012 at 2:36 PM, Russ Cox <r...@swtch.com> wrote:

> if you want a more plan 9-like mk, change
> mk/shell.c's shelldefault to be &rcshell instead
> of &shshell.

ok. that's what I had started to do anyway.

thanks

ron

Reply all
Reply to author
Forward
0 new messages