<div>That answered my questions perfectly, and your suggestion of using shell conditionals works excellently.</div><br><div><signature id="local-d4f4314a-a661"><table cellpadding="0" cellspacing="0"><tbody><tr><td style="vertical-align:top"><img alt="" src="https://user-generated.getmailspring.com/asset/NmY5Mjg2ODgtZWMyNy00YjMzLWFmNGItYTlmMDQ1OTAxNzZlL3NpZy1pbml0aWFsLnBuZw.png?t=1565960265401&amp;msw=246&amp;msh=249" width="59" height="60" style="max-width:60px;max-height:60px;margin-right:10px"></td><td><div>Elliot Wasem</div><div style="font-size:0.9em;border-top:1px solid gray;min-width:250px;max-width:300px;margin-top:4px;padding-top:4px"><div><div></div><div><a href="https://link.getmailspring.com/link/7EC77368-B9E5-4B02-9237-1F291374614D@getmailspring.com/0?redirect=https%3A%2F%2Felliot-wasem.github.io%2Fpersonal-website&amp;recipient=Y3M2MzFhcHVlQGxpc3RzLnN0ZXZlbnMuZWR1">https://elliot-wasem.github.io/personal-website</a></div><div><a href="https://link.getmailspring.com/link/7EC77368-B9E5-4B02-9237-1F291374614D@getmailspring.com/1?redirect=https%3A%2F%2Fwww.linkedin.com%2Fin%2Felliot-wasem%2F&amp;recipient=Y3M2MzFhcHVlQGxpc3RzLnN0ZXZlbnMuZWR1" title="LinkedIn" style="margin-right:8px"><img src="https://www.getmailspring.com/signature-assets/linkedin.gif" width="13" height="13" alt="LinkedIn"></a></div></div></div></td></tr></tbody></table></signature></div><div class="gmail_quote_attribution">On Sep 2 2019, at 3:24 pm, Jan Schaumann &lt;jschauma@stevens.edu&gt; wrote:</div><blockquote><div><div>Elliot Wasem &lt;ewasem@stevens.edu&gt; wrote:</div><br><blockquote><div>I've been playing around with writing code that is</div><div>trivially portable between Linux and NetBSD.</div></blockquote><br><div>That's a useful exercise, and we will discuss some of</div><div>those aspects in future lectures.</div><br><div>Portability may require accomodating not just</div><div>different headers or conditionally include code in</div><div>your sources, but may also require you to account for</div><div>the difference in the compiler or the build chain (as</div><div>you noticed here).</div><br><div>As noted earlier, the reference platform will be</div><div>NetBSD, so adding support for other platforms is</div><div>something that you may, but do not need to do.</div><br><div>Having said that...</div><br><blockquote><div>I realized that 'setprogname(...)' is only available</div><div>in BSD's &lt;stdlib.h&gt;, and so on Linux, I needed to</div><div>include &lt;bsd/stdlib.h&gt; in my code iff on a Linux</div><div>system.</div></blockquote><br><div>To conditionally include code in your source files,</div><div>use the '#ifdef' macro. Different constants are</div><div>defined for you by default on the platform on which</div><div>you're building your code. You can view the default</div><div>values by e.g., running</div><br><div>cc -E -dM - &lt;/dev/null | more</div><br><div>To conditionally include code only on Linux systems,</div><div>you'd then use</div><br><div>#ifdef __linux__</div><div>#include &lt;bsd/stdlib.h&gt;</div><div>#endif</div><br><blockquote><div>Now, it seems that NetBSD's Make does not play well</div><div>with the GNU way of creating makefiles (i.e.</div><div>conditional blocks in the makefile), however 'gmake'</div><div>on NetBSD works fine.</div></blockquote><br><div>Well, 'gmake' works fine on NetBSD if it was</div><div>installed. Out of the box, your reference system</div><div>should not have a 'gmake' installed anywhere. So your</div><div>Makefile will need to be made to work with the default</div><div>BSD make.</div><br><div>Like other tools, 'make' has diverged over the years</div><div>as well, and as so often, the GNU tools support</div><div>options either that are not supported on other</div><div>platforms at all or are supported differently.</div><br><div>BSD make(1) does have support for conditional variable</div><div>assignment, but it uses a different syntax from GNU</div><div>make(1) ('.if' vs. e.g. 'ifeq'). But creating a</div><div>platform-specific Makefile then doesn't provide real</div><div>portability, and you'd have to ship different Makefile</div><div>for the different target platforms etc.</div><br><div>Instead, it'd be best to write a Makefile that works</div><div>on all of your target platforms. To do that, you can</div><div>use shell-conditionals in the variable assignment.</div><br><div>The following Makefile snippet should help get you on</div><div>the right track:</div><br><div>---- 8&lt; ----- 8&lt; -----</div><br><div>UNAME = $$(uname -s)</div><br><div>EXTRA_LDFLAGS = $$(if [ x"${UNAME}" = x"Linux" ]; then echo "-lbsd"; fi)</div><br><div>all:</div><div>@echo "Platform is: ${UNAME}"</div><div>@echo "${CC} ${CFLAGS} ${EXTRA_LDFLAGS}"</div><br><div>---- 8&lt; ----- 8&lt; -----</div><br><div>(There are other ways to do this as well. Play around</div><div>with some of the ways that variables might be assigned</div><div>and how commands might be executed and see whether</div><div>there are functional differences or performance</div><div>reasons why one might want to do things one way over</div><div>the other.)</div><br><div>As I said, we'll discuss make(1) and portability of</div><div>code in more detail in future lectures, but hopefully</div><div>the above is enough to answer your question.</div><br><div>-Jan</div><div>_______________________________________________</div><div>cs631apue mailing list</div><div>cs631apue@lists.stevens.edu</div><div>https://lists.stevens.edu/mailman/listinfo/cs631apue</div></div></blockquote><img class="mailspring-open" alt="Sent from Mailspring" width="0" height="0" style="border:0; width:0; height:0;" src="https://link.getmailspring.com/open/7EC77368-B9E5-4B02-9237-1F291374614D@getmailspring.com?me=354e93c1&amp;recipient=Y3M2MzFhcHVlQGxpc3RzLnN0ZXZlbnMuZWR1">