Created
October 10, 2016 20:04
-
-
Save gciruelos/40018197fc02828fac362b3907dd6a82 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ifndef $(CC) | |
CC = gcc | |
endif | |
WARNINGS = -Wall -Wextra -Werror -Wshadow -Wstrict-prototypes -Wpointer-arith \ | |
-Wcast-qual | |
OPT_FLAGS = -O2 -flto -ffast-math | |
CFLAGS = $(WARNINGS) -Werror -std=c99 -pedantic | |
LFLAGS = -lm | |
TEST_DIR = test/ | |
SRC_DIR = src/ | |
UI_SRC_DIR = $(SRC_DIR)ui/ | |
OBJ_DIR = obj/ | |
TEST_OBJ_DIR = $(OBJ_DIR)test/ | |
SRCS = $(wildcard $(SRC_DIR)*.c) | |
OBJS = $(addprefix $(OBJ_DIR),$(notdir $(SRCS:.c=.o))) | |
TEST_SRCS = $(wildcard $(TEST_DIR)*.c) | |
TEST_OBJS = $(addprefix $(TEST_OBJ_DIR),$(notdir $(TEST_SRCS:.c=.o))) | |
EXECUTABLE = termplot | |
TEST_EXECUTABLE = testbin | |
MKDIR_P = mkdir -p | |
DEFAULT = termbox | |
ncurses: TERMBOX = false | |
ncurses: SRCS+=src/ui/ui_ncurses.c | |
ncurses: LFLAGS+=-lncurses | |
ncurses: $(OBJ_DIR) $(EXECUTABLE) | |
termbox: TERMBOX = true | |
termbox: CFLAGS+=-DINCL_TERMBOX | |
termbox: SRCS+=src/ui/ui_termbox.c | |
termbox: LFLAGS+=-ltermbox | |
termbox: $(OBJ_DIR) $(EXECUTABLE) | |
.PHONY: all clean debug travis ncurses termbox | |
clean: | |
rm -f $(OBJS) $(TEST_OBJS) $(EXECUTABLE) $(TEST_EXECUTABLE) | |
debug: OPT_FLAGS = -ggdb -O2 | |
debug: termbox | |
travis: ncurses test | |
$(OBJ_DIR): | |
${MKDIR_P} $@ | |
$(TEST_OBJ_DIR): | |
${MKDIR_P} $@ | |
$(OBJ_DIR)%.o: $(SRC_DIR)%.c | |
$(CC) $(CFLAGS) $(OPT_FLAGS) -c -o $@ $< | |
$(OBJ_DIR)%.o: $(UI_SRC_DIR)%.c | |
$(CC) $(CFLAGS) $(OPT_FLAGS) -c -o $@ $< | |
$(OBJ_DIR)%.o: $(TESD_DIR)%.c | |
$(CC) $(CFLAGS) -c -o ? | |
$(EXECUTABLE): $(OBJS) | |
$(CC) $(OPT_FLAGS) $^ -o $@ $(LFLAGS) | |
$(TEST_OBJ_DIR)%.o: $(TEST_DIR)%.c | |
$(CC) $(CFLAGS) $(OPT_FLAGS) -c -o $@ $< | |
$(TEST_EXECUTABLE): OBJS := $(filter-out obj/termplot.o, $(OBJS)) | |
$(TEST_EXECUTABLE): $(OBJS) $(TEST_OBJS) | |
$(CC) $(OPT_FLAGS) $(OBJS) $(TEST_OBJS) -o $@ $(LFLAGS) | |
test: $(TEST_OBJ_DIR) | |
test: $(TEST_EXECUTABLE) | |
./$(TEST_EXECUTABLE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment