Wiki/Cheatsheets/makefile.md
2025-05-05 02:26:57 +02:00

1.3 KiB

title, description, published, date, tags, editor, dateCreated
title description published date tags editor dateCreated
makefile true 2023-04-28T02:38:18.678Z markdown 2023-04-28T02:22:37.379Z

Makefile

VARIABLE	=	VALUE

RULE: Dependency $(FUNCTION)
	$(FUNCTION)
	Task




VAR		= value						#normale value assignment
VAR		:= $(VAR).o					#value assignment with expansion
VAR		!= uname					#add output of command
VAR		:= $(sh uname)				#alternative way to add output
VAR		+= -Wall -Werror -Wextra	#Append to value
VAR		?= $(VAR)					#only sets if not defined

Text functions
$(SRC:.c=.o)						#Changes all suffixes from .c to .o

Filename functions
$(addprefix obj/,$(OBJ))			#Adds a directory to the filenames

conditional functions
if
ifeq
ifdef
else
or
and
endif
foreach

value function
$(value (VAR))						#print value without expanding

shell function
$(shell COMMAND)					#insert output here

control functions
$(error Something went wrong)		#Makefile will stop here
$(warning This is a warning)		#Display a warning
$(info This is some info)			#Display some info

$@		#is the rule name
$<		#is the first dependancy
$^		#are all dependancies
$?		#only dependencies that have changed
$|		#If anything changed, rebuild everything
%		#acts as a wildcard in the rule


.PHONY: all clean fclean re bonus	#Doesn't create a file named after the target