wiki

Help! I'm trapped in a wiki!

Site Tools


programs:make

make

make can automate commands. People mostly use it to avoid typing compiler commands. You can use it for all sorts of things though.

See http://cholla.mmto.org/esp8266/make to get started on makefiles. For a comprehensive tutorial, check out Makefile tutorial at https://makefiletutorial.com/#first-functions

The gist of it is this:

TARGET: SOURCES
	COMMANDS

make builds targets based on the sources provided by running the commands.

You can also specify a target without any sources, for example:

clean:
	rm main main.o extra.o

make clean will run the commands as is.

Starting point

A good starting point is Chris Wellons' (nullprogram) tutorial on portable makefiles found here: https://nullprogram.com/blog/2017/08/20/

It essentially looks like this:

.POSIX:
CC     = cc
CFLAGS = -W -O
LDLIBS = -lm
PREFIX = /usr/local
 
all: game
install: game
	mkdir -p $(DESTDIR)$(PREFIX)/bin
	mkdir -p $(DESTDIR)$(PREFIX)/share/man/man1
	cp -f game $(DESTDIR)$(PREFIX)/bin
	gzip < game.1 > $(DESTDIR)$(PREFIX)/share/man/man1/game.1.gz
game: graphics.o physics.o input.o
	$(CC) $(LDFLAGS) -o game graphics.o physics.o input.o $(LDLIBS)
graphics.o: graphics.c graphics.h
physics.o: physics.c physics.h
input.o: input.c input.h graphics.h physics.h
clean:
	rm -f game graphics.o physics.o input.o
programs/make.txt · Last modified: by 127.0.0.1