Questions tagged [make]

For questions pertaining to make, a utility that automates the build process by managing dependencies amongst targets. Use this tag for questions about make itself or questions about issues arising from using the make command-line utility.

The make utility is driven by optional configuration files (makefiles) and built-in rules that take components and create an output file, typically an executable file. The configuration files and built-in rules define how to create an output file from the given input files. The rules consist of a target, dependencies, and commands to execute to create the output file. If the output exists and is newer than all the dependency files, no action is taken.

For example, if creating an executable file hello.exe requires two source files, hello.c and hello.h then a makefile could look like this:

hello.exe: hello.c hello.h
    cc hello.c -i hello.h -o hello

If the timestamps for hello.c and hello.h are older than for hello.exe then the cc command is executed. There are numerous macros predefined that for simple tasks a simple makefile (or even no makefile) is needed.

Further reading

Why can't gcc find libevent when building tmux from source?

What is the purpose of the 'install' command?

make fatal error: openssl/sha.h: No such file or directory

External References

Tutorial

Wikipedia Makefile

make specification (The Open Group Base Specifications Issue 7, 2018 edition)

990 questions
42
votes
3 answers

How to list all targets in make?

Let's say you have a project structure with lots of Makefiles and there is a top level Makefile that includes all the other. How can you list all the possible targets? I know writing make and then tabbing to get the suggestions would generally do…
Sogartar
  • 581
31
votes
1 answer

What causes Make to delete intermediate files?

I wrote a Makefile and found out that when executing make command, an unexpected rm was executed, after all command in Mmakefile were done. But I didn't write the rm command in the Makefile. run-%: d/%.out $< d/%.out: d/%.c gcc -o $(subst…
z.h.
  • 994
28
votes
2 answers

.PHONY all rules in GNU make file?

Am I wrong in my interpretation that I should basically just put first before all make rules: .PHONY: all of my rules all: echo "Executing all ..." of: echo "Executing of ..." my: echo "Executing my ..." rules: echo "Executing…
tarabyte
  • 4,296
16
votes
2 answers

"No target" error using Make

I'm learning how to use make and makefiles, so I wrote this little file: %.markdown: %.html pandoc -o $< $@ But when I run make, all I get is make: *** No targets. Stop. What's going on?
ahmed
  • 263
16
votes
3 answers

How do I fix "make: No rule to make target `config'"?

When I type make config in the terminal, the system responds with: make: *** No rule to make target `config'. Stop. Any idea how to fix that problem?
MakaraPr
  • 263
15
votes
3 answers

Which shell is used in GNU Make files?

I've seen things like echo, mv, if, for, in makefile rules. Some kind of shell commands seem to be recognized. Is this bash? How can I figure out which shell is being used and full list of keywords available to me?
tarabyte
  • 4,296
12
votes
3 answers

How to remove trailing spaces from makefile variable?

Makefile does not require to bound variable values by quotes. For instance this will be accepted: a := ls -l -a > out.txt My problem is: If I want to do something like this: a := ls -l -a > out b := .txt c := $(a)$(b) If end of the line of…
user1985
  • 121
12
votes
2 answers

File function in makefile takes args prefixed by '@' symbol

This code excerpt is from Chapter 8.6 of GNU makefile manual. What does @$@.in for file function arg in a makefile mean? and why are shell commands like rm prefixed by '@' symbol program: $(OBJECTS) $(file >$@.in,$^) $(CMD) $(CMDFLAGS)…
user93868
11
votes
1 answer

Using a make rule to call another

I am writing a LaTeX project that I am using a makefile for. I have a clean function to clean the excess LaTeX files: .PHONY: clean clean: \rm *.aux *.blg *.out *.bbl *.log But in some cases I need to get rid of the generated files as well as…
10
votes
1 answer

What does this strange Makefile target ".PHONY" mean?

In this https://github.com/kubernetes/helm/blob/master/Makefile there are targets with a dot in front of them. What is this convention for ? .PHONY: all all: build .PHONY: build build: GOBIN=$(BINDIR) $(GO) install $(GOFLAGS) -tags '$(TAGS)'…
Bon Ami
  • 893
9
votes
1 answer

What does $(number) mean in a Makefile?

I have some script and I didn't understand a line which contains $(1): wget --retry-connrefused --waitretry=5 --read-timeout=30 --tries=50 --no-dns-cache https://dataverse.harvard.edu/api/access/datafile/:persistentId?persistentId=doi:$(1) -O…
9
votes
2 answers

Get top-level directory from makefile variable

What is the simplest code to get the top-level directory part of a makefile variable? Example: BUILD_DIR = dir/subdir/.../sub-a-dub-dir distclean: rm -rf PS: I don't mean $(dir $(dir…
l0b0
  • 51,350
9
votes
2 answers

What do $@ and $< in a makefile mean?

I am seeing a makefile and it has the symbols $@ and $< in it. I have never seen them, and Google does not show any results about them. Do you know what these commands do?
7
votes
1 answer

Where is make database located?

I don't know why Google searches aren't showing anything. From documentation: The make program uses the makefile data base and the last-modification times of the files to decide which of the files need to be updated. So, where is this database…
Utku
  • 1,433
6
votes
2 answers

What is the default jobs argument for make?

How many jobs does make use by default when you don't pass it the -j flag?
jsj
  • 1,410
1
2 3 4 5 6 7