blob: dea14dfc17fec96be19e02974e226f4e72560437 (
plain) (
blame)
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
|
# Pure POSIX makefile for nytpu's implementation of ed(1)
# It should be completely generic though, just change PROGNAME, VERSION, & OBJS
#
# Copyright (c) 2021 nytpu <alex@nytpu.com>
# SPDX-License-Identifier: MIT
# For more license details, see LICENSE_MIT or <https://spdx.org/licenses/MIT.html>.
.POSIX:
.SILENT:
.SUFFIXES:
# program info
PROGNAME = ed
VERSION = 0.1.0
# default install directories
PREFIX = /usr/local
BINDIR = $(PREFIX)/bin
MANDIR = $(PREFIX)/share/man
# default programs
CC = cc
# compilation flags
CFLAGS = -Wall -Wextra -pedantic -Wfatal-errors -std=c11 -O3 \
-Wno-missing-field-initializers -Wno-unused-parameter -Werror=return-type
LDFLAGS =
LDLIBS =
include config.mk
CFLAGS += -DVERSION=\"\$(VERSION)\"
# files & dependencies
BINS = $(PROGNAME)
MANS = ed.1 ed.1p
OBJS = main.o buffer.o command.o io.o linenoise.o
TESTS =
all: $(BINS)
main.o: buffer.h command.h common.h io.h linenoise.h
buffer.o: buffer.h common.h
command.o: command.h common.h
io.o: buffer.h common.h io.h
linenoise.o: linenoise.h
# rules
.SUFFIXES: .o .c
.c.o:
printf 'Compiling\t$<\n'
$(CC) $(CFLAGS) -c -o $@ $<
$(PROGNAME): $(OBJS)
printf 'Linking\t\t$@\n'
$(CC) $(LDFLAGS) $(OBJS) $(LDLIBS) -o $@
# phonies
# technically .PHONY isn't POSIX, but targets with a leading period aren't
# reserved so it's still valid, it'd just be useless to actually execute
.PHONY: all format clean install uninstall
clean:
rm -rf $(OBJS) $(PROGNAME) $(TESTS)
format:
find . (-name '*.[ch]' -a (! -name 'linenoise.*')) -exec clang-format -style=file -i {} \;
install: $(BINS) $(MANS)
mkdir -p $(BINDIR) $(MANDIR)/man1
cp $(BINS) $(BINDIR)
cp $(MANS) $(MANDIR)/man1
uninstall:
rm -f $(BINS:%=$(BINDIR)/%)
rm -f $(MANS:%=$(MANDIR)/man1/%)
-rmdir -p $(BINDIR) $(MANDIR)/man1
# testing
.PHONY: test-includes test
.SUFFIXES: .t .c
.c.t:
printf 'Testing\t$<\n'
$(CC) $(CFLAGS) -DTEST $(LDFLAGS) -o $@ $<
test: $(TESTS)
set -e; $(TESTS:%=./%;)
test-includes:
find . -type f \( -name "*.c" -or -name "*.h" \) -exec \
include-what-you-use -Xiwyu --quoted_includes_first -Xiwyu --keep=common.h {} \;
|