What is ?= in Makefile

?= indicates to set the KDIR variable only if it’s not set/doesn’t have a value. For example: KDIR ?= “foo” KDIR ?= “bar” test: echo $(KDIR) Would print “foo” GNU manual: http://www.gnu.org/software/make/manual/html_node/Setting.html

DESTDIR and PREFIX of make

./configure –prefix=*** Number 1 determines where the package will go when it is installed, and where it will look for its associated files when it is run. It’s what you should use if you’re just compiling something for use on a single host. make install DESTDIR=*** Number 2 is for installing to a temporary directory … Read more

Multi-line bash commands in makefile

You can use backslash for line continuation. However note that the shell receives the whole command concatenated into a single line, so you also need to terminate some of the lines with a semicolon: foo: for i in `find`; \ do \ all=”$$all $$i”; \ done; \ gcc $$all But if you just want to … Read more

How to pass argument to Makefile from command line?

You probably shouldn’t do this; you’re breaking the basic pattern of how Make works. But here it is: action: @echo action $(filter-out $@,$(MAKECMDGOALS)) %: # thanks to chakrit @: # thanks to William Pursell EDIT: To explain the first command, $(MAKECMDGOALS) is the list of “targets” spelled out on the command line, e.g. “action value1 … Read more

Using local makefile for CLion instead of CMake

Update: If you are using CLion 2020.2, then it already supports Makefiles. If you are using an older version, read on. Even though currently only CMake is supported, you can instruct CMake to call make with your custom Makefile. Edit your CMakeLists.txt adding one of these two commands: add_custom_target add_custom_command When you tell CLion to … Read more

What’s the difference between := and = in Makefile?

Simple assignment := A simple assignment expression is evaluated only once, at the very first occurrence. For example, if CC :=${GCC} ${FLAGS} during the first encounter is evaluated to gcc -W then each time ${CC} occurs it will be replaced with gcc -W. Recursive assignment = A Recursive assignment expression is evaluated everytime the variable … Read more

How do I check if file exists in Makefile so I can delete it?

It’s strange to see so many people using shell scripting for this. I was looking for a way to use native makefile syntax, because I’m writing this outside of any target. You can use the wildcard function to check if file exists: ifeq ($(UNAME),Darwin) SHELL := /opt/local/bin/bash OS_X := true else ifneq (,$(wildcard /etc/redhat-release)) OS_RHEL … Read more

makefile execute another target

Actually you are right: it runs another instance of make. A possible solution would be: .PHONY : clearscr fresh clean all all : compile executable clean : rm -f *.o $(EXEC) fresh : clean clearscr all clearscr: clear By calling make fresh you get first the clean target, then the clearscreen which runs clear and … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)