~nabijaczleweli/febug

febug/Makefile -rw-r--r-- 6.2 KiB
6c7bde18наб Add MacOS PDF manual link. Fix extra space in febug.8 --{help,version} 8 months 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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# SPDX-License-Identifier: MIT


CXX ?= c++
CC ?= cc
CPP ?= cpp
MANDOC ?= mandoc
AWK ?= awk
CARGO ?= cargo
LTO ?= y
FEBUG_VERSION ?= "$(patsubst v%,%,$(shell git describe))"
FEBUG_DATE ?= $(shell date $(shell date --version > /dev/null 2>&1 && echo "--date @" || echo "-r ")$(shell git log -1 --no-show-signature --format=%at) +"%B %e, %Y")
EXTRACCAR ?=
EXTRALDAR ?=

AS_NEEDED := -Wl,--as-needed
SONAME := -soname
SYSTEM := $(shell uname -s)
ifeq "$(SYSTEM)" "NetBSD"
	FUSE_ARGS ?= -lrefuse
else ifeq "$(SYSTEM)" "OpenBSD"
	FUSE_ARGS ?= -lfuse
else ifeq "$(SYSTEM)" "Darwin"
	FUSE_ARGS ?= -lfuse
	AS_NEEDED :=
	SONAME := -install_name
else
	FUSE_ARGS ?= $(shell pkg-config --libs --cflags fuse3)
endif

CXXVER := $(shell $(CXX) --version | head -1)
ifneq "$(findstring clang,$(CXXVER))" ""
	# GCC doesn't have this granularity
	CXXSPECIFICCC := -Wpedantic -Wno-c++20-designator -Wno-c99-extensions -Wno-unknown-warning-option
ifneq "$(findstring Apple,$(CXXVER))" ""
	# CMSG_SPACE() is a macro, and it's decidedly constexpr. i don't care if appleclang can't figure that out
	CXXSPECIFICCC += -Wno-vla-extension
endif
	ifeq "$(LTO)" "y"
		CXXSPECIFICLD := -flto=full  # Clang produces .o files with LLVM bitcode, which cannot be linked to if put in .as
	else
		CXXSPECIFICLD :=
	endif
else
	CXXSPECIFICCC := -Wno-missing-field-initializers -fno-common
	ifeq "$(LTO)" "y"
		CXXSPECIFICCC += -flto
	endif
	CXXSPECIFICLD :=
endif


OUTDIR ?= out/
OBJDIR ?= $(OUTDIR)obj/
CCAR := -g -O3 -pipe -Wall -Wextra -isysteminclude/ $(CXXSPECIFICCC) $(EXTRACCAR)
LDAR := $(AS_NEEDED) -L$(OUTDIR) $(CXXSPECIFICLD) $(EXTRALDAR)
HEADERS := $(wildcard include/*.h include/*.hpp)
EXAMPLES := $(wildcard examples/*.c examples/*.cpp)
EXAMPLES_RS := $(wildcard examples/*.rs)
MANPAGES := $(wildcard man/*.[0123456789])
FEBUG_VERSION := $(FEBUG_VERSION)
FEBUG_DATE := $(FEBUG_DATE)
FUSE_ARGS := $(FUSE_ARGS)


.PHONY : main libfebug++ libfebug examples manpages htmlpages rust-build rust-doc

all : main libfebug++ libfebug examples manpages htmlpages how.png
clean:
	rm -rf $(OUTDIR) $(OBJDIR) how.png

main : $(OUTDIR)febug
libfebug++ : $(OUTDIR)libfebug++.a
libfebug : $(OUTDIR)libfebug.a $(OUTDIR)libfebug.so
examples : $(foreach l,$(patsubst %.c,$(OUTDIR)%,$(patsubst %pp,%,$(EXAMPLES))),$(l) $(l)-dont)
manpages : $(patsubst %,$(OUTDIR)%,$(MANPAGES)) $(OBJDIR)man/aliases
htmlpages : $(patsubst %,$(OUTDIR)%.html,$(MANPAGES)) $(OUTDIR)man/style.css
rust-build : $(OUTDIR)febug.rs/target/libfebug.rlib
rust-doc : $(OUTDIR)febug.rs/doc/febug/index.html


$(OUTDIR)febug : main.cpp $(HEADERS)
	@mkdir -p $(dir $@)
	$(CXX) $< -o$@ -DFEBUG_VERSION='$(FEBUG_VERSION)' -std=c++17 -fno-exceptions -fPIE $(CCAR) $(LDAR) $(FUSE_ARGS)


$(OBJDIR)febug++.o : febug.cpp $(HEADERS)
	@mkdir -p $(dir $@)
	$(CXX) -c $< -o$@ -std=c++17 -fPIC $(CCAR)

$(OUTDIR)libfebug++.a : $(OBJDIR)febug++.o
	@mkdir -p $(dir $@)
	ar crs $@ $^


$(OBJDIR)febug.o : febug.c $(HEADERS)
	@mkdir -p $(dir $@)
	$(CC) -c $< -o$@ -std=c11 -fPIC $(CCAR)

$(OUTDIR)libfebug.a : $(OBJDIR)febug.o
	@mkdir -p $(dir $@)
	ar crs $@ $^

$(OUTDIR)libfebug.so : $(OBJDIR)febug.o
	@mkdir -p $(dir $@)
	$(CC) -shared $< -o$(OUTDIR)libfebug.so.0 -std=c11 -fPIC $(CCAR) $(LDAR) -Wl,$(SONAME),libfebug.so.0
	ln -fs libfebug.so.0 $@


$(OUTDIR)examples/% : examples/%.cpp $(OUTDIR)libfebug++.a $(HEADERS)
	@mkdir -p $(dir $@)
	$(CXX) $< -o$@              -std=c++17 -fPIE $(CCAR) $(LDAR) -lfebug++

$(OUTDIR)examples/%-dont : examples/%.cpp $(OUTDIR)libfebug++.a $(HEADERS)
	@mkdir -p $(dir $@)
	$(CXX) $< -o$@ -DFEBUG_DONT -std=c++17 -fPIE $(CCAR) $(LDAR) -lfebug++

$(OUTDIR)examples/% : examples/%.c $(OUTDIR)libfebug.a $(HEADERS)
	@mkdir -p $(dir $@)
	$(CC) $< -o$@              -std=c11 -fPIE $(CCAR) $(LDAR) -lfebug

$(OUTDIR)examples/%-dont : examples/%.c $(OUTDIR)libfebug.a $(HEADERS)
	@mkdir -p $(dir $@)
	$(CC) $< -o$@ -DFEBUG_DONT -std=c11 -fPIE $(CCAR) $(LDAR) -lfebug


$(OBJDIR)man/aliases : man/aliases
	@mkdir -p $(dir $@)
	@touch $@
	$(AWK) '!/^$$/ {print "ln -fs " $$1 " $(OUTDIR)man/" $$2}' man/aliases | sh -x

$(OUTDIR)man/% : man/% $(wildcard man/*.h)
	@mkdir -p $(dir $@)
	(cd $(dir $<); $(CPP) -nostdinc -Wno-trigraphs -Wno-invalid-pp-token -CC -P -DFEBUG_DATE="$(FEBUG_DATE)" -DFEBUG_VERSION='$(FEBUG_VERSION)' - < $(notdir $<) | \
		$(AWK) '/^$$/ {next}  $$1 == ".Dt" { print ".ds doc-volume-operating-system" }  \
			$$1 == "$$include" {gsub(/"/, "", $$2); while((getline line < $$2) > 0) {gsub(/\\/, "\\e", line); print line}; next}  \
			{print}') > $@
	! $(MANDOC) -Tlint $@ 2>&1 | grep -vE -e 'mandoc: outdated mandoc.db' -e 'STYLE: referenced manual not found' -e 'WARNING: unknown manual section: Dt .* 0$$' -e 'STYLE: operating system explicitly specified: Os febug' -e 'STYLE: input text line longer than 80 bytes' -e 'STYLE: .*OpenBSD' -e 'STYLE: RCS id missing'

$(OUTDIR)man/%.html : $(OUTDIR)man/%
	(cd man/; $(MANDOC) -Thtml -Oincludes="https://git.sr.ht/~nabijaczleweli/febug/tree/trunk/item/include/%I",man="%N.%S.html;https://manpages.debian.org/bullseye/%N.%S",style="style.css" ../$^ | \
		sed -Ee 's/ title=".."//g') > $@

$(OUTDIR)man/style.css : man/style.css
	@mkdir -p $(dir $@)
	ln -f $^ $@ 2>/dev/null || cp $^ $@

$(OUTDIR)febug.rs/README.md : README.md
	@mkdir -p $(dir $@)
	ln -f $^ $@ 2>/dev/null || cp $^ $@

$(OUTDIR)febug.rs/%.rs : febug.rs/%.rs
	@mkdir -p $(dir $@)
	ln -f $^ $@ 2>/dev/null || cp $^ $@

$(OUTDIR)febug.rs/examples/%.rs : examples/%.rs
	@mkdir -p $(dir $@)
	ln -f $^ $@ 2>/dev/null || cp $^ $@

$(OUTDIR)febug.rs/target/libfebug.rlib : $(OUTDIR)febug.rs/Cargo.toml $(OUTDIR)febug.rs/lib.rs $(OUTDIR)febug.rs/build.rs $(OUTDIR)febug.rs/README.md $(patsubst %,$(OUTDIR)febug.rs/%,$(EXAMPLES_RS))
	@mkdir -p $(OUTDIR)examples/
	cd $(dir $<); FEBUG_DONT=1 $(CARGO) build --release --examples
	$(foreach l,$(patsubst %.rs,%,$(EXAMPLES_RS)),mv $(OUTDIR)febug.rs/target/release/$(l) $(OUTDIR)$(l)-dont; )
	cd $(dir $<); $(CARGO) build --release --examples
	$(foreach l,$(patsubst %.rs,%,$(EXAMPLES_RS)),mv $(OUTDIR)febug.rs/target/release/$(l) $(OUTDIR)$(l); )

$(OUTDIR)febug.rs/doc/febug/index.html : $(OUTDIR)febug.rs/target/libfebug.rlib
	cd $(dir $<); $(CARGO) doc --release

$(OUTDIR)febug.rs/Cargo.toml : febug.rs/Cargo.toml
	@mkdir -p $(dir $@)
	sed 's;FEBUG_VERSION;$(FEBUG_VERSION);' $< > $@


how.png : how.dot
	dot -Tpng $^ -o $@