7

I have a BSDmakefile and GNUmakefile that are pretty much identical except for dependency management.

The GNUmakefile:

ifneq ($(MAKECMDGOALS), "clean")
-include $(dependencies)
endif

The BSDmakefile:

.for i in $(dependencies)
.sinclude "${i}"
.endfor

Is there a way to make it so that I can detect if I am running under gmake or bsdmake and then execute the appropriate include statements based off of that? I remember seeing someone take advantage of a quirk in both makefile processors so that they could achieve a similar effect.

Alternatively, if there is a better approach than this, I would like to know! (switching to SCons or CMake is not appropriate!)

Thanks!

  • 2
    I'm not sure why you'd want to do this: why not just require `gmake` or `bmake` everywhere? If you want to be portable, you could use `automake` and leave the details to it. Many projects have a hard enough time getting a single build system right, let alone 2. – Jack Kelly Oct 03 '10 at 23:26

1 Answers1

10

You could put your GNU-specific stuff in GNUmakefile, your BSD-specific stuff in BSDmakefile, and your common stuff in a file named Makefile.common or similar. Then include Makefile.common at the very beginning of each of the other two. Downside is, now you have 3 makefiles instead of 2. Upside, you'll only be editing 1.

Jander
  • 5,359
  • 1
  • 22
  • 21
  • 3
    Your "downside" is like saying that splitting a 10,000 LOC file into logically related units has the downside of producing more than one source file. – Jack Kelly Oct 03 '10 at 23:24