Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BSD Make and GNU Make compatible makefile

Tags:

makefile

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!

like image 807
Rita Henderson Avatar asked Oct 03 '10 04:10

Rita Henderson


People also ask

Does make need a makefile?

The make utility requires a file, Makefile (or makefile ), which defines set of tasks to be executed. You may have used make to compile a program from source code. Most open source projects use make to compile a final executable binary, which can then be installed using make install .

What is make in makefile?

Make is Unix utility that is designed to start execution of a makefile. A makefile is a special file, containing shell commands, that you create and name makefile (or Makefile depending upon the system).

Does makefile work on Linux?

Makefile is a program building tool which runs on Unix, Linux, and their flavors. It aids in simplifying building program executables that may need various modules. To determine how the modules need to be compiled or recompiled together, make takes the help of user-defined makefiles.

What is $* in make?

Here, $* is an automatic variable which will expand to the stem of the target (the text matching the % in the pattern). So, if you invoke make foobar. xyz , this rule would invoke make foobar clean : it would run a sub-make, build the foobar target, then build the clean target.


1 Answers

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.

like image 163
Jander Avatar answered Oct 20 '22 13:10

Jander