Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable make builtin rules and variables from inside the make file

I want to disable builtin rules and variables as per passing the -r and -R options to GNU make, from inside the make file. Other solutions that allow me to do this implicitly and transparently are also welcome.

I've found several references to using MAKEFLAGS, and had similar problems.

like image 886
Matt Joiner Avatar asked Nov 08 '10 10:11

Matt Joiner


People also ask

What is $@ in make file?

The variable $@ represents the name of the target and $< represents the first prerequisite required to create the output file.

What is Obj in makefile?

The third variable used in this file is OBJS. In this makefile, this variable specifies all the object files required to construct the main program.

What is makefile rule?

A rule appears in the makefile and says when and how to remake certain files, called the rule's targets (most often only one per rule). It lists the other files that are the prerequisites of the target, and the recipe to use to create or update the target.

What is implicit rule in makefile?

Implicit rules tell make how to use customary techniques so that you do not have to specify them in detail when you want to use them. For example, there is an implicit rule for C compilation. File names determine which implicit rules are run. For example, C compilation typically takes a . c file and makes a .o file.


1 Answers

Disabling the built-in rules is done by writing an empty rule for .SUFFIXES:

.SUFFIXES: 

Having erased the built-in rules, I'm not sure that erasing the built-in variables helps you much more than just remembering to set them yourself or not use them, but you could use something like

$(foreach V,     $(shell make -p -f/dev/null 2>/dev/null | sed -n '/^[^:#= ]* *=/s/ .*//p'),     $(if $(findstring default,$(origin $V)),$(eval $V=))) 

...which is admittedly fairly crazy. If there is a way to get a list of the defined variables from within make (instead of shelling out to another make), it would be viable. As it is, it's not really much better than

CC= CXX= # etc, for each likely built-in variable 
like image 66
John Marshall Avatar answered Nov 27 '22 18:11

John Marshall