blob: 6b4ee3c5cb9cdfddd8b0207ec894d70fcaf71eee (
plain)
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
# SPDX-License-Identifier: MIT
# Copyright (c) 2022,2026 Leah Rowe <leah@libreboot.org>
# Copyright (c) 2023 Riku Viitanen <riku.viitanen@protonmail.com>
CC?=cc
HELLCC?=clang
CFLAGS?=
LDFLAGS?=
DESTDIR?=
PREFIX?=/usr/local
INSTALL?=install
.SUFFIXES: .c .o
LDIR?=
PORTABLE?=$(LDIR) $(CFLAGS)
WARN?=$(PORTABLE) -Wall -Wextra
STRICT?=$(WARN) -std=c90 -pedantic -Werror
HELLFLAGS?=$(STRICT) -Weverything
PROG=nvmutil
# source files
SRCS = nvmutil.c state.c file.c string.c usage.c command.c num.c io.c \
checksum.c word.c
# object files
OBJS = $(SRCS:.c=.o)
# default mode
MODE?=portable
# default mode, options
CFLAGS_MODE=$(PORTABLE)
CC_MODE=$(CC)
# override modes (options)
ifeq ($(MODE),warn)
CFLAGS_MODE=$(WARN)
endif
ifeq ($(MODE),strict)
CFLAGS_MODE=$(STRICT)
endif
ifeq ($(MODE),hell)
CFLAGS_MODE=$(HELLFLAGS)
CC_MODE=$(HELLCC)
endif
# (rebuild on .h changes)
# (commented for portability)
#
# CFLAGS_MODE += -MMD -MP
# -include $(OBJS:.o=.d)
#
# likely more compatible,
# on its own:
# -include $(OBJS:.o=.d)
#
# i want this to build on
# old make, so i'll leave
# this blanked by default
all: $(PROG)
$(PROG): $(OBJS)
$(CC_MODE) $(OBJS) -o $(PROG) $(LDFLAGS)
# generic rules
# .c.o: is the old style (portable)
# modern equivalent:
# %.o: %.c
#
.c.o:
$(CC_MODE) $(CFLAGS_MODE) -c $< -o $@
# -m in install is not portable
# to old/other/weird versions.
# use chmod directly.
#
install: $(PROG)
$(INSTALL) -d $(DESTDIR)$(PREFIX)/bin
$(INSTALL) $(PROG) $(DESTDIR)$(PREFIX)/bin/$(PROG)
chmod 755 $(DESTDIR)$(PREFIX)/bin/$(PROG)
uninstall:
rm -f $(DESTDIR)$(PREFIX)/bin/$(PROG)
clean:
rm -f $(PROG) $(OBJS) *.d
distclean: clean
# easy commands
warn:
$(MAKE) MODE=warn
strict:
$(MAKE) MODE=strict
hell:
$(MAKE) MODE=hell
.PHONY: all warn strict hell install uninstall clean distclean
|