~q3cpma/csv-view

ref: 4112c64f963368ed130a69980ee71e21ba28009a csv-view/GNUmakefile -rw-r--r-- 1.9 KiB
4112c64fq3cpma Minor changes 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
BIN := csv_view
PREFIX := /usr/local
CONFIG := Release

MAKEFLAGS := $(MAKEFLAGS) -r

ifeq ($(CONFIG), Asan)
	CFLAGS += -Og -g3 -fsanitize=address
	LDFLAGS += -fsanitize=address
else ifeq ($(CONFIG), Ubsan)
	CFLAGS += -Og -g3 -fsanitize=undefined
	LDFLAGS += -fsanitize=undefined
else ifeq ($(CONFIG), Lsan)
	CFLAGS += -Og -g3 -fsanitize=leak
	LDFLAGS += -fsanitize=leak
else ifeq ($(CONFIG), Profile)
	CFLAGS += -Og -g3
	CPPFLAGS += -DNDEBUG
else ifeq ($(CONFIG), Release)
	LTO ?= yes
	STRIP ?= yes
	CFLAGS += -O3
	CPPFLAGS += -DNDEBUG
	LDFLAGS += -Wl,-O1,--as-needed,-z,now,-z,defs
else
	$(error CONFIG: invalid value; must be "Asan", "Ubsan", "Lsan", "Profile" or "Release")
endif

ifeq ($(LTO), yes)
	CFLAGS += -flto
	LDFLAGS += -fuse-linker-plugin $(CFLAGS)
endif

ifeq ($(STATIC), yes)
    LDFLAGS += -static
endif

ifeq ($(STRIP), yes)
	LDFLAGS += -s
endif

override CFLAGS += -std=c11 -pedantic -Wall -Wextra -Wno-char-subscripts \
	-funsigned-char
override CPPFLAGS += -Iinclude -D_DEFAULT_SOURCE \
	-DPROG_NAME="\"$(BIN)\"" \
	-DPROG_VERSION="\"$(shell git rev-parse --short HEAD)\""
override LDFLAGS +=
override LDLIBS += -lncurses -ltinfo

SRC := $(wildcard src/*.c)
OBJ := $(SRC:src/%.c=obj/%.o)


.PHONY: all clean install uninstall lint test pgo-gcc

all: $(BIN)

clean:
	rm -rf -- $(BIN) obj/

install: $(BIN)
	mkdir -p -- $(DESTDIR)$(PREFIX)/bin
	cp -f -- $(BIN) $(DESTDIR)$(PREFIX)/bin
	chmod 755 -- $(addprefix $(DESTDIR)$(PREFIX)/bin/, $(BIN))

uninstall: | $(SUBMAKE)
	rm -- $(addprefix $(DESTDIR)$(PREFIX)/bin/, $(BIN))

lint: clean
	@command -v scan-build >/dev/null && scan-build -analyze-headers \
		-no-failure-reports $(MAKE) CFLAGS="-O0";

test: $(BIN)
	test/test.sh all

pgo-gcc: clean
	@ CFLAGS="-fprofile-generate" LDFLAGS="-fprofile-generate" $(MAKE) test
	rm -f -- $(BIN) obj/*.o
	@ CFLAGS="-fprofile-use" $(MAKE)

$(BIN): $(OBJ)
	$(CC) $(LDFLAGS) $^ -o $@ $(LDLIBS)

obj/%.o: src/%.c | obj/
	$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@

obj/:
	@mkdir obj/