Index

ncurses-minesweeper / 69783cd

Terminal game of Minesweeper, implemented in C with ncurses.

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
610 Sep 2020 18:1369783cdRewrite lint make targets; create clang-format configJosh Stockin1349G

Blob @ ncurses-minesweeper / Makefile

text/plain3002 bytesdownload raw
1# Preamble >> Make config
2SHELL := bash
3.ONESHELL:
4.SHELLFLAGS := -eu -o pipefail -c
5.DELETE_ON_ERROR:
6MAKEFLAGS += --warn-undefined-variables
7MAKEFLAGS += --no-builtin-rules
8
9ifeq ($(origin .RECIPEPREFIX), undefined)
10 $(error This Make does not support .RECIPEPREFIX. Please use GNU Make 4.0 or later)
11endif
12.RECIPEPREFIX = >
13
14
15# Compiler settings
16CC := gcc -std=c11
17CFLAGS := -O3
18CWARNINGS := -Werror -Wall -Wextra -pedantic
19CINCLUDES := -Isrc
20CLIBS := -lncurses
21
22CFORMAT := clang-format -i
23CTIDY := clang-tidy --checks=-*,clang-analyzer-*,-clang-analyzer-cplusplus-*
24
25SOURCE_DIR := src
26BIN_DIR := bin
27SOURCES := $(wildcard $(SOURCE_DIR)/*.c)
28HEADERS := $(wildcard $(SOURCE_DIR)/*.h)
29OBJECTS := $(patsubst %.c, $(BIN_DIR)/%.o, $(SOURCES))
30OUTFILE := $(BIN_DIR)/minesweeper
31
32.PHONY: all lint precompile postcompile compile build clean run done
33all: lint compile build run done
34
35
36# Automatically create targets and gather their prerequisites
37define create-ctarget
38$1
39> @echo -en "\e[37m[\e[34m?\e[37m]\e[0m $$< \e[36m⇒\e[0m $$@"
40> @mkdir -p $$(dir $$@)
41> @if $(CC) -o $$@ -c $(CFLAGS) $(CWARNINGS) $(CINCLUDES) $$<>/dev/null 2>&1;
42> @then echo -e "\r\e[37m[\e[32m✓\e[37m]\e[0m";
43> @else echo -e "\r\e[37m[\e[31m✗\e[37m]\e[0m";
44> @$(CC) -o $$@ -c $(CFLAGS) $(CWARNINGS) $(CINCLUDES) $$<;
45> @fi
46endef
47
48compile: precompile $(OBJECTS) postcompile
49precompile:
50> @echo -e "\e[1m\e[35mCOMPILING\e[0m"
51postcompile:
52> @echo -e "\e[94mDone compiling\e[0m\n"
53$(foreach src,$(SOURCES),$(eval $(call create-ctarget,$(shell $(CC) -MM -MT $(patsubst %.c, $(BIN_DIR)/%.o, $(src)) $(src)))))
54
55
56# Link and build outfile
57build: $(OUTFILE)
58$(OUTFILE): $(OBJECTS)
59> @echo -e "\e[1m\e[35mLINKING\e[0m"
60> @echo -en "\e[37m[\e[34m?\e[37m]\e[0m $^ \e[36m⇒\e[0m $@"
61> @mkdir -p $(dir $@)
62> @if $(CC) -o $@ $^ $(CLIBS)>/dev/null 2>&1;
63> @then echo -e "\r\e[37m[\e[32m✓\e[37m]\e[0m";
64> @else echo -e "\r\e[37m[\e[31m✗\e[37m]\e[0m";
65> @$(CC) -o $@ $^ $(CLIBS);
66> @fi
67> @echo -e "\e[94mDone linking\e[0m\n"
68done:
69> @echo -e "\e[1m\e[48;5;28m\e[37mDone!\e[0m"
70
71
72# Run out
73run: $(OUTFILE)
74> @$(OUTFILE)
75
76
77# Create linter targets for source and header files
78define create-linttarget
79$1
80> @echo -en "\e[37m[\e[34m?\e[37m]\e[0m $$<"
81> @if ! $(CFORMAT) $$<>/dev/null 2>&1;
82> @then echo -e "\r\e[37m[\e[31m✗\e[37m]\e[0m";
83> @$(CFORMAT) $$<;
84> @fi;
85> @if $(CTIDY) $$<>/dev/null 2>&1;
86> @then echo -e "\r\e[37m[\e[32m✓\e[37m]\e[0m";
87> @else echo -e "\r\e[37m[\e[31m✗\e[37m]\e[0m";
88> @$(CTIDY) $$<;
89> @fi;
90> @mkdir -p $$(dir $$@)
91> @touch $$@
92endef
93
94$(foreach src,$(SOURCES),$(eval $(call create-linttarget,$(patsubst %.c, $(BIN_DIR)/%.cl, $(src)): $(src))))
95$(foreach header,$(HEADERS),$(eval $(call create-linttarget,$(patsubst %.h, $(BIN_DIR)/%.hl, $(header)): $(header))))
96
97prelint:
98> @echo -e "\e[1m\e[35mLINTING\e[0m"
99postlint:
100> @echo -e "\e[94mDone linting\e[0m\n"
101lint: prelint $(patsubst %.h, $(BIN_DIR)/%.hl, $(HEADERS)) $(patsubst %.c, $(BIN_DIR)/%.cl, $(SOURCES)) postlint
102
103
104# Clean
105clean:
106> @rm -r $(BIN_DIR)
107