make
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| make [2021/03/22 09:58] – [Examples] utedass | make [2022/09/12 00:30] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Overview ====== | ====== Overview ====== | ||
| [[https:// | [[https:// | ||
| + | |||
| + | <code bash> | ||
| + | # Print without running | ||
| + | $ make --just-print | ||
| + | or | ||
| + | $ make -n | ||
| + | |||
| + | # Print lot of stuff | ||
| + | $ make --print-data-base | ||
| + | </ | ||
| + | |||
| + | ====== Magic symbols ====== | ||
| + | [[https:// | ||
| + | |||
| + | | $@ | Target | | ||
| + | | $%%^%% | All prerequisites (excluding duplicates) | | ||
| + | | $+ | All prerequisites (including duplicates) | | ||
| + | | $? | All prerequisites newer than target | | ||
| + | | $< | First prerequisite | | ||
| + | | $(@D) | Directory part of target with trailing slash | | ||
| + | | $(@F) | File part of target without directory path | | ||
| + | | $* | The stem of the target match in implicit rules | | ||
| ====== Examples ====== | ====== Examples ====== | ||
| Line 14: | Line 36: | ||
| DEPS=main.o cbuf.o event_system.o fsm.o | DEPS=main.o cbuf.o event_system.o fsm.o | ||
| OUTFILE=main.exe | OUTFILE=main.exe | ||
| - | |||
| - | # This will populate TEXTEN with the output from the shell command ls | ||
| - | TEXTEN = $(lsoutput) | ||
| - | TEXTEN2 := $(lsoutput) | ||
| - | lsoutput = $(shell ls) # Hereafter $(lsoutput) will evaluate to what ls returns | ||
| # VPATH tells make to search the following directories for targets and dependencies. Separated with : | # VPATH tells make to search the following directories for targets and dependencies. Separated with : | ||
| Line 42: | Line 59: | ||
| </ | </ | ||
| + | Evaluation time of variables | ||
| + | <code make> | ||
| + | # This will populate TEXTEN with the output from the shell command ls | ||
| + | TEXTEN = $(lsoutput) | ||
| + | TEXTEN2 := $(lsoutput) | ||
| + | lsoutput = $(shell ls) # Hereafter $(lsoutput) will evaluate to what ls returns | ||
| + | </ | ||
| + | <code make> | ||
| + | # Substitutions when referencing variables, only the ending is substituted | ||
| + | SOURCES = a.c b.c c.c | ||
| + | OBJECTS = $(SOURCES: | ||
| + | </ | ||
| + | |||
| + | <code make> | ||
| + | # A make file that compiles all c files and places object files | ||
| + | # in the same tree-structure that the sources were found | ||
| + | CC = gcc | ||
| + | CFLAGS = -std=c99 -Wall -Wextra -pedantic -O0 -I. -I utils -I protocol -I command -I driver | ||
| + | OUTFILE = main.exe | ||
| + | |||
| + | OBJDIR | ||
| + | SOURCES := $(shell find * -type f -name " | ||
| + | OBJECTS := $(addprefix $(OBJDIR)/, | ||
| + | |||
| + | run: $(OUTFILE) | ||
| + | @echo ""; | ||
| + | @./ | ||
| + | |||
| + | $(OUTFILE): $(OBJECTS) | ||
| + | $(CC) -o $@ $^ $(CFLAGS) | ||
| + | |||
| + | $(OBJECTS): $(OBJDIR)/ | ||
| + | mkdir -p $(@D) | ||
| + | $(CC) -c -o $@ $^ $(CFLAGS) | ||
| + | |||
| + | .PHONY: clean | ||
| + | clean: | ||
| + | @rm -f $(OUTFILE) *.mk *.o *.pp *.s listing.txt | ||
| + | @rm -rf $(OBJDIR) | ||
| + | </ | ||
make.1616407113.txt.gz · Last modified: 2022/09/12 00:30 (external edit)
