diff --git a/GNUmakefile b/GNUmakefile new file mode 100644 index 0000000..0b67f58 --- /dev/null +++ b/GNUmakefile @@ -0,0 +1,46 @@ +.POSIX: # Just kidding, use GNU Make + +# OVERRIDE ME # +PREFIX := . +PROGN := probotic + +CC := cc +CFLAGS := -std=c99 -Wall -Wextra -Wpedantic +CPPFLAGS := -I/usr/bin/ircclient/ +LDFLAGS := -lircclient + +SRC.DIR := src +OBJ.DIR := $(PREFIX)/obj +# INC.DIR := include + +OBJ := $(addprefix $(OBJ.DIR)/,fetch.o main.o) +# HDR := + +VPATH := $(INC.DIR) $(SRC.DIR) $(OBJ.DIR) + +ifeq ($(DEBUG),1) + CFLAGS += -Og -g3 +else + CFLAGS += -O3 -flto=auto -fomit-frame-pointer +endif + +ifdef SAN + CFLAGS += -fsanitize=$(SAN) +endif + +CPPFLAGS += -DPROGN="\"$(PROGN)\"" + +$(OBJ.DIR)/%.o: $(SRC.DIR)/%.c + $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< + +$(PREFIX)/$(PROGN): $(VPATH) $(PREFIX) $(HDR) | $(OBJ) + $(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $| $(LDFLAGS) + +# include/config.h: include/config.mk.h +# cp -f $< $@ + +$(VPATH) $(PREFIX): + mkdir -p $@ + +clean: + $(RM) $(OBJ) $(PROGN) diff --git a/Makefile b/Makefile index 0b67f58..85db634 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,4 @@ -.POSIX: # Just kidding, use GNU Make - # OVERRIDE ME # -PREFIX := . PROGN := probotic CC := cc @@ -10,37 +7,42 @@ CPPFLAGS := -I/usr/bin/ircclient/ LDFLAGS := -lircclient SRC.DIR := src -OBJ.DIR := $(PREFIX)/obj +OBJ.DIR := obj # INC.DIR := include -OBJ := $(addprefix $(OBJ.DIR)/,fetch.o main.o) +SRC := fetch.c main.c +OBJ := ${OBJ.DIR}/fetch.o ${OBJ.DIR}/main.o # HDR := -VPATH := $(INC.DIR) $(SRC.DIR) $(OBJ.DIR) +VPATH := ${INC.DIR}:${SRC.DIR}:${OBJ.DIR} -ifeq ($(DEBUG),1) - CFLAGS += -Og -g3 -else - CFLAGS += -O3 -flto=auto -fomit-frame-pointer -endif +.if "${DEBUG}" == "1" +CFLAGS := ${CFLAGS} -Og -g3 +.else +CFLAGS := ${CFLAGS} -O3 -flto=auto -fomit-frame-pointer +.endif -ifdef SAN - CFLAGS += -fsanitize=$(SAN) -endif +.ifdef SAN +CFLAGS := ${CFLAGS} -fsanitize=${SAN} +.endif -CPPFLAGS += -DPROGN="\"$(PROGN)\"" +CPPFLAGS := ${CPPFLAGS} -DPROGN="\"${PROGN}\"" -$(OBJ.DIR)/%.o: $(SRC.DIR)/%.c - $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< +all: ${PROGN} -$(PREFIX)/$(PROGN): $(VPATH) $(PREFIX) $(HDR) | $(OBJ) - $(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $| $(LDFLAGS) +${PROGN}: ${OBJ.DIR} ${PREFIX} ${HDR} ${OBJ} + ${CC} ${CFLAGS} ${CPPFLAGS} -o $@ ${OBJ} ${LDFLAGS} + +${OBJ.DIR}/main.o: ${SRC.DIR}/main.c + ${CC} ${CFLAGS} ${CPPFLAGS} -c -o $@ ${SRC.DIR}/main.c +${OBJ.DIR}/fetch.o: ${SRC.DIR}/fetch.c + ${CC} ${CFLAGS} ${CPPFLAGS} -c -o $@ ${SRC.DIR}/fetch.c # include/config.h: include/config.mk.h # cp -f $< $@ -$(VPATH) $(PREFIX): +${OBJ.DIR} ${PREFIX}: mkdir -p $@ clean: - $(RM) $(OBJ) $(PROGN) + ${RM} ${OBJ} ${PROGN}