CC = gcc CFLAGS = -std=c99 -O3 -Wall -Wextra -Wpedantic -Wstrict-aliasing CFLAGS += -Wfloat-equal -Wundef -Wshadow -Wpointer-arith -Wcast-align CFLAGS += -Wstrict-prototypes -Wstrict-overflow=5 -Wwrite-strings CFLAGS += -Wcast-qual -Wswitch-default -Wswitch-enum CFLAGS += -Wconversion -Wunreachable-code # for asprintf() and getline() CFLAGS += -D_GNU_SOURCE LDFLAGS = SRC = modfetch.c OBJ = $(BIN)/$(SRC:.c=.o) BIN = target TEMPMOD = $(wildcard modules/*.c) MOD = $(TEMPMOD:modules/%=%) PROGRAM = modfetch .PHONY: all clean all: dirs modules $(PROGRAM) modules: dirs $(MOD:.c=.so) dirs: mkdir -p ./$(BIN) $(PROGRAM): $(addprefix $(BIN)/, $(OBJ)) $(CC) -o $(BIN)/$(PROGRAM) $^ $(LDFLAGS) %.o: %.c $(CC) -o $(BIN)/$@ -c $< $(CFLAGS) %.so: modules/%.c $(CC) -o $(BIN)/$@ $^ -shared -fPIC $(CFLAGS) clean: clean_modules rm -rf $(OBJ) rm -rf $(PROGRAM) clean_modules: rm -rf $(wildcard $(BIN)/*.so)