Aqui está o makefile:
.PHONY: all clean
CC = gcc
CFLAGS = -g -m32 -std=c17
BIN = bin
ALG_SRCS = $(wildcard alg/*.c)
COMMON_SRCS = $(wildcard *.c)
ALG_OBJS = $(patsubst alg/%.c, $(BIN)/%.o, $(ALG_SRCS))
COMMON_OBJS = $(patsubst %.c, $(BIN)/%.o, $(COMMON_SRCS))
ALG_EXES = $(patsubst alg/%.c, $(BIN)/%, $(ALG_SRCS))
all: $(ALG_EXES)
$(BIN)/%: $(BIN)/%.o $(COMMON_OBJS) | $(BIN)
$(CC) $(CFLAGS) -o $@ $^ -lncursesw
$(BIN)/%.o: %.c | $(BIN)
$(CC) $(CFLAGS) -c $< -o $@
$(BIN)/%.o: alg/%.c | $(BIN)
$(CC) $(CFLAGS) -c $< -o $@
$(BIN):
mkdir -p $(BIN)
clean:
rm -rf $(BIN)
Exemplo de execução:
$ make
mkdir -p bin
gcc -g -m32 -std=c17 -c alg/basic.c -o bin/basic.o
gcc -g -m32 -std=c17 -c graph.c -o bin/graph.o
gcc -g -m32 -std=c17 -c grid.c -o bin/grid.o
gcc -g -m32 -std=c17 -c main.c -o bin/main.o
gcc -g -m32 -std=c17 -o bin/basic bin/basic.o bin/graph.o bin/grid.o bin/main.o -lncursesw
gcc -g -m32 -std=c17 -c alg/colors.c -o bin/colors.o
gcc -g -m32 -std=c17 -o bin/colors bin/colors.o bin/graph.o bin/grid.o bin/main.o -lncursesw
rm bin/main.o bin/graph.o bin/basic.o bin/colors.o bin/grid.o
Eu não pedi para que os arquivos de objeto fossem removidos, nem chamei "clean". Por que isso rm bin/main.o bin/graph.o bin/basic.o bin/colors.o bin/grid.o
ainda acontece?