Doco for (.if condition1 && condition2 &&... --Or-- How does it work?

Status
Not open for further replies.

Dennis Jensen

Dabbler
Joined
May 26, 2016
Messages
37
Okay been digging through the various documentation for FreeNAS, FreeBSD, and GNU Make and I cannot find specific documentation that fully covers the ".if" statement especially in conjunction with the "&&" operator. This .if appears to be either an addition to "make" by FreeBSD and/or FreeNAS as there seems to be no reference to this in GNU Make whatsoever and I have found minimal references to it in both FreeBSD and FreeNAS -- the key word here being "minimal" -- My current question (which could probably be answered by full documentation covering this ".if" statement but that I have not found and I am not sure it even exists -- so the specific question is as follows:

In the FreeNAS 9.10 Build (and presumably earlier versions as well) there is the following line:

.if !make(remote) && !make(sync) && !make(bootstrap-pkgs)

In most of the programming languages that I have dealt with (which are based mostly off of C to one degree or another) would execute this from left to right and sometimes quit executing if one of the conditions proved to be false (but not always). However -- in examining the components of this if -- it does not seem to make any sense unless I execute this from right to left -- as make(remote) is dependent on make(sync) and make(sync) is dependent on make(bootstrap-pkgs) thus strongly implying that for this if to work properly and efficiently the order of operations would be:

1) make(bootstrap-pkgs)
2) if (1) is successful then make(sync)
3) if (2) is successful then make(remote)
4) if (3) is successful then this if is successful

So does this .if && statement combination execute from right to left as it seems or is there something else going on here that I am not fully understanding??

Or even better is there full documentation on how the .if statement works??
 

wblock

Documentation Engineer
Joined
Nov 14, 2014
Messages
1,506
It is not GNU make. FreeBSD uses its own version of make that is a fair bit different from gmake. The most recent one is called "bmake" internally. Here is the man page, which does briefly mention .if:
https://www.freebsd.org/cgi/man.cgi....3-RELEASE+and+Ports&arch=default&format=html

It does evaluate left to right, short-circuiting when possible. My guess is that those targets might not do what their names suggest at first look.
 

Dennis Jensen

Dabbler
Joined
May 26, 2016
Messages
37
Okay thanks on the version of "make" that is being used.

As for the .if statement's targets in question I am pretty sure that we dissected those correctly.

The .if statement resides within the Makefile found in the root of FreeNAS-Build and is the first executable statement after setting and exporting variables. The recipe for make(bootstrap-pkgs) is declared within Makefile and simply installs the various packages that are needed on a virgin system -- one of those being the Python language which is required by both make(remote) and make(sync) to be executed. The other 2 recipes are outlined in Makefile.inc1 also located within the root directory of FreeNAS-Build and they are both pretty straight forward with the remote: recipe clearly dependent upon the sync: recipe being run prior to it at some point within the same shell

Thus make(remote) is dependent upon make(sync) which is dependent upon make(bootstrap-pkgs) -- but with the .if statement's execution being from left to right you get:
1) make(remote)
2) make(sync)
3) make(bootstrap-pkg)

And I see no other interpretation for this .if statement and that means it makes absolutely no sense because if it is a virgin system you would REALLY NEED to run them in this order:
1) make(bootstrap-pkg)
2) make(sync)
3) make(remote)

As you cannot successfully execute the remote: recipe without first successfully running the sync: recipe which cannot be successfully executed without first successfully running the bootstrap-pkg: recipe and thus if the .if statement executes from left to right it should be structured as follows:

.if !make(bootstrap-pkgs) && !make(sync) && !make(remote)

This way if for some reason the make(bootstrap-pkgs) fails then it does not try to execute its 2 dependents and if make(sync) fails it does not try to execute its dependent and make(remote) would only be executed if the other two that it is dependent upon were executed successfully.

Of course if there is something about this that I am not understanding that makes the reverse precedence important I would really like to hear this -- otherwise I will probably report this a bad code
 

wblock

Documentation Engineer
Joined
Nov 14, 2014
Messages
1,506
If you'll post a link to what you're looking at, I'll look.

It might be bad, but if it didn't work at all, it probably would have been discovered before now.
 

Dennis Jensen

Dabbler
Joined
May 26, 2016
Messages
37
Okay I am digging into this a bit more using the make documentation and I will post a reply when I have either figured it out or if I still have a question -- thanks for the help thus far thou -- looking at the correct make documentation I am sure will help.
 

Dennis Jensen

Dabbler
Joined
May 26, 2016
Messages
37
Okay assuming the FreeBSD Man Pages are a reliable source (see below) I have determined what the initial issue was and its not an issue and I will post a full explanation once I have finished my research.

HOWEVER....

I examined the FreeBSD Man Pages: Make(1) document which points to the "PMake - A Tutorial" document which references making the call using pmake instead of make ... and at first I thought FreeBSD/FreeNAS simply shortened pmake to just make but in reading the 2 separate documents I have come into a situation where the FreeBSD Man Page Make(1) does not sync up with the "PMake - A Tutorial" -- so my question is does:

FreeBSD Man Pages: Make(1) == PMake - A Tutorial

In other words are they talking about the same "Make" process or are they actually talking about Make and PMake separately ??

If they are supposed to be the same then which source document is more reliable??

To be specific about where I have encountered the discrepancies in:

FreeBSD Man Pages: Make(1) under Description it outlines (very early on) all the Flags and what they do

"PMake - A Tutorial" in "Chapter 2.7 Invoking PMake" it outlines all the Flags and what they do

This is where the beginnings of my issue are -- aka this is what raised my question. While I can see one or two discrepancies between these -- I found quite a few -- in fact enough to make me think that perhaps these to documents are not talking about the same thing.

Could someone clarify this.
 

wblock

Documentation Engineer
Joined
Nov 14, 2014
Messages
1,506

Dennis Jensen

Dabbler
Joined
May 26, 2016
Messages
37
Okay yes the FreeBSD Man Page: Make(1) I was speaking about is:
https://www.freebsd.org/cgi/man.cgi....3-RELEASE+and+Ports&arch=default&format=html

And yes the "PMake - A Tutorial" I was speaking about and that the the above Man Page points to is indeed
https://www.freebsd.org/doc/en_US.ISO8859-1/books/pmake/index.html

Yes thank you for that explanation BUT -- does that mean the FreeBSD Man Page is correct and is the documentation for BMake and even though it says go read PMake - A Tutorial this latter document is actually the documentation on PMake which is not the same as BMake and therefore is wrong ???
 
Status
Not open for further replies.
Top