{"id":11,"date":"2006-01-10T12:36:04","date_gmt":"2006-01-10T16:36:04","guid":{"rendered":"http:\/\/thesmithfam.org\/blog\/?p=11"},"modified":"2019-08-12T07:16:33","modified_gmt":"2019-08-12T13:16:33","slug":"make-and-the-operator","status":"publish","type":"post","link":"https:\/\/thesmithfam.org\/blog\/2006\/01\/10\/make-and-the-operator\/","title":{"rendered":"Make and the ?= operator"},"content":{"rendered":"<p>The GNU crew improved Make with lots of handy stuff. One such gem that I found today is the <code>?=<\/code> operator, which only defines a macro if it is not already defined (like as an environment variable). It behaves <em>almost<\/em> like wrapping the assignment in <code>ifndef<\/code>. John Gramm-Cunning has a <a href=\"http:\/\/www.cmcrossroads.com\/ubbthreads\/showflat.php?Number=45201\">good explanation<\/a> of this subtle difference.<\/p>\n<p>Here&#8217;s an example of <code>?=<\/code> in action.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">INSTALL_HOST ?= root@myhost.example.com<\/pre>\n<p>The INSTALL_HOST macro will have the value &#8220;root@myhost.example.com&#8221; unless someone specifies it as an environment variable when invoking make. This makes its value easily overridable by users calling your Makfile, like this:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">$ INSTALL_HOST=root@foobar.com make install<\/pre>\n<p>I find it pretty handy.<\/p>\n<p>However, I have one gripe. Make in general is tough to learn because its keywords and operators are not Googlable. Say I find the <code>?=<\/code> operator in a Makefile and I want to look it up. Normally, I would just punch it into  Google, but that just gives you a bunch of <a href=\"http:\/\/www.google.com\/search?q=make+?=\">junk results<\/a>. Not a huge deal, but it&#8217;s tough to find good docs out there for this reason<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The GNU crew improved Make with lots of handy stuff. One such gem that I found today is the ?= operator, which only defines a macro if it is not already defined (like as an environment variable). It behaves almost like wrapping the assignment in ifndef. John Gramm-Cunning has a good explanation of this subtle [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-11","post","type-post","status-publish","format-standard","hentry","category-code-and-cruft"],"_links":{"self":[{"href":"https:\/\/thesmithfam.org\/blog\/wp-json\/wp\/v2\/posts\/11","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thesmithfam.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thesmithfam.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thesmithfam.org\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/thesmithfam.org\/blog\/wp-json\/wp\/v2\/comments?post=11"}],"version-history":[{"count":1,"href":"https:\/\/thesmithfam.org\/blog\/wp-json\/wp\/v2\/posts\/11\/revisions"}],"predecessor-version":[{"id":1622,"href":"https:\/\/thesmithfam.org\/blog\/wp-json\/wp\/v2\/posts\/11\/revisions\/1622"}],"wp:attachment":[{"href":"https:\/\/thesmithfam.org\/blog\/wp-json\/wp\/v2\/media?parent=11"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thesmithfam.org\/blog\/wp-json\/wp\/v2\/categories?post=11"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thesmithfam.org\/blog\/wp-json\/wp\/v2\/tags?post=11"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}