MAKE
In a Makefile, command lines must begin with a tab character, not spaces, or make will fail with an error such as “missing separator.” This is because the Makefile format distinguishes targets and dependencies from the shell commands that run beneath them, and a leading tab is the required signal that a line contains a command. Although modern versions of GNU Make offer advanced features that can emulate tab behavior, the standard and universally expected practice is to use a real tab for all recipe lines. Using spaces instead of tabs is one of the most common mistakes beginners run into, so it’s important to ensure your editor is configured to keep actual tabs in Makefiles.
root@dev:~$ nano makefile
# usage:
# make test
# make clean
# make debug
# make release
# VARIABLES
GCC = gcc
CFLAGS = -Wall -Wshadow
SRCS = file1.c file2.c # <-- replace with your actual .c files
OBJS = $(SRCS:.c=.o)
TARGET = program # <-- replace with the intended program name
$(TARGET): $(OBJS)
<TAB>$(GCC) $(CFLAGS) $(OBJS) -o $(TARGET)
%.o: %.c
<TAB>$(GCC) $(CFLAGS) -c $< -o $@
test: $(TARGET)
<TAB>for case in 0 1 2 3 4; do \
<TAB><TAB>echo input$$case; \
<TAB><TAB>./$(TARGET) inputs/input$$case > output$$case; \
<TAB><TAB>diff output$$case expected/expected$$case; \
<TAB>done
clean:
<TAB>/bin/rm -f *.o $(TARGET) *~ *bak output*
# debugging build
debug: CFLAGS += -g
debug: $(TARGET)
# release build
release: CFLAGS += -O1 -s
release: $(TARGET)
Last updated