Index

ncurses-minesweeper / bfddcc3

Terminal game of Minesweeper, implemented in C with ncurses.

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
409 Sep 2020 17:16bfddcc3Automatically create Make targetsJosh Stockin13410G

Blob @ ncurses-minesweeper / Makefile

text/plain1313 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
21CLINT := --syntax-only
22
23SOURCE_DIR := src
24BIN_DIR := bin
25SOURCES := $(wildcard $(SOURCE_DIR)/*.c)
26OBJECTS := $(patsubst %.c, $(BIN_DIR)/%.o, $(SOURCES))
27OUTFILE := $(BIN_DIR)/minesweeper
28
29.PHONY: all lint clean
30all: $(OUTFILE)
31
32
33# Automatically create targets and gather their prerequisites
34define create-ctarget
35$1
36> @echo Compiling $$@ from $$^
37> @mkdir -p $$(dir $$@)
38> @$(CC) -o $$@ -c $(CFLAGS) $(CWARNINGS) $(CINCLUDES) $$<
39endef
40
41$(foreach src,$(SOURCES),$(eval $(call create-ctarget,$(shell $(CC) -MM -MT $(patsubst %.c, $(BIN_DIR)/%.o, $(src)) $(src)))))
42
43
44# Build outfile
45$(OUTFILE): $(OBJECTS)
46> @echo Building $@ from $^
47> @mkdir -p $(dir $@)
48> $(CC) -o $@ $^ $(CLIBS)
49> @echo Done!
50
51
52# Lint
53lint: $(SOURCES)
54> @echo Linting...
55> @$(foreach src,$^,$(CC) $(CLINT) $(CWARNINGS) $(CINCLUDES) $(src);)
56
57
58# Clean
59clean:
60> @rm -r $(BIN_DIR)
61