How to get current relative directory of your Makefile?

The shell function. You can use shell function: current_dir = $(shell pwd). Or shell in combination with notdir, if you need not absolute path: current_dir = $(notdir $(shell pwd)). Update. Given solution only works when you are running make from the Makefile’s current directory. As @Flimm noted: Note that this returns the current working directory, … Read more

Passing the argument to CMAKE via command prompt

In the CMakeLists.txt file, create a cache variable, as documented here: SET(FAB “po” CACHE STRING “Some user-specified option”) Source: http://cmake.org/cmake/help/v2.8.8/cmake.html#command:set Then, either use the GUI (ccmake or cmake-gui) to set the cache variable, or specify the value of the variable on the cmake command line: cmake -DFAB:STRING=po Source: http://cmake.org/cmake/help/v2.8.8/cmake.html#opt:-Dvar:typevalue Modify your cache variable to a … Read more

Create directories using make file

In my opinion, directories should not be considered targets of your makefile, either in technical or in design sense. You should create files and if a file creation needs a new directory then quietly create the directory within the rule for the relevant file. If you’re targeting a usual or “patterned” file, just use make‘s … Read more

How to use LDFLAGS in makefile

Your linker (ld) obviously doesn’t like the order in which make arranges the GCC arguments so you’ll have to change your Makefile a bit: CC=gcc CFLAGS=-Wall LDFLAGS=-lm .PHONY: all all: client .PHONY: clean clean: $(RM) *~ *.o client OBJECTS=client.o client: $(OBJECTS) $(CC) $(CFLAGS) $(OBJECTS) -o client $(LDFLAGS) In the line defining the client target change … Read more