-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile
150 lines (115 loc) · 3.82 KB
/
Makefile
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
PROG_SERVICE := $(shell sed -n 's|.*define.*PROG_SERVICE.*"\(.*\)".*|\1|p' src/config.h)
PROG_VERSION := $(shell ./version.sh)
CPPFLAGS := -DPROG_VERSION=\"$(PROG_VERSION)\"
LDFLAGS := -Wl,-O1,--sort-common,--as-needed
ALL_CFLAGS := -std=c99 -ffreestanding -Wall -Wextra $(CFLAGS)
ALL_LDFLAGS := $(LDFLAGS)
QUIET = @echo '$@';
CC ?= gcc
STRIP ?= strip
INSTALL ?= install
prefix := /usr
ifeq ($(temps),yes)
ALL_CFLAGS += -save-temps=obj
endif
mode := release
arch := $(shell $(CC) -dumpmachine | cut -f1 -d-)
ifeq ($(arch),x86_64)
ALL_CFLAGS += -mtune=generic -m64 -march=x86-64
else
override arch := i686
ALL_CFLAGS += -mtune=generic -m32 -march=i686
endif
mark := $(mode)-$(arch)-
ifeq ($(mode),release)
ALL_CFLAGS += -O3 -fomit-frame-pointer
endif
ifeq ($(mode),debug)
ALL_CFLAGS += -O0 -g -fno-omit-frame-pointer -fsanitize=address
else
ALL_CFLAGS += -DNDEBUG
endif
ifeq ($(mode),coverage)
ALL_CFLAGS += -O0 -g -fno-omit-frame-pointer -fprofile-arcs -ftest-coverage
LDLIBS += -lgcov
endif
ifeq ($(mode),profile)
ALL_CFLAGS += -O0 -g -pg -fno-omit-frame-pointer
endif
ifeq ($(mode),pgo)
ifneq ($(pgo),use)
ALL_CFLAGS += -O0
endif
ALL_CFLAGS += -fprofile-$(pgo)
endif
SERVER := $(PROG_SERVICE)d
CLIENT := $(PROG_SERVICE)
SOURCES := $(wildcard src/*.c)
HEADERS := $(wildcard src/*.h)
DISTNAME := $(PROG_SERVICE)-$(PROG_VERSION)-$(mode)-$(arch)
ifeq ($(findstring mingw,$(CC)),mingw)
MN_$(CLIENT).exe := client-win
LD_client-win.o := -lws2_32 -lgdi32
PROGRAMS := $(CLIENT).exe
DIST := zip
else
MN_$(SERVER) := server
MN_$(CLIENT) := client
LD_screen.o := -lxcb -lxcb-xfixes -lxcb-shm -lxcb-randr -lxcb-damage
LD_common.o := -lrt
LD_user.o := -lcap
LD_display.o := -lX11 -lXfixes
LD_image.o := -lXext
LD_input.o := -lXi -lXtst
LD_xrandr.o := -lXrandr
LD_xdamage.o := -lXdamage
LD_auth-pam.o := -lpam
LD_auth-gss.o := -lgssapi_krb5 -lkrb5
LD_client.o := -lXrender
PROGRAMS := $(SERVER) $(CLIENT)
DIST := tar.gz
endif
LD_openssl.o := -lssl -lcrypto
.SUFFIXES:
.PHONY: default all clean install dist test
default: $(PROGRAMS)
all: defaults test
clean:
git clean -Xfd
install: $(CLIENT) $(SERVER)
$(INSTALL) -m 755 -d $(DESTDIR)$(prefix)/bin
$(INSTALL) -m 755 -s $(SERVER) $(DESTDIR)$(prefix)/bin
$(INSTALL) -m 755 -s $(CLIENT) $(DESTDIR)$(prefix)/bin
dist: $(DISTNAME).$(DIST)
test: $(patsubst src/test-%.c, src/$(mark)test-%.bin, $(SOURCES))
-include src/$(mark)h.mk
-include src/$(mark)o.mk
$(foreach k,$(PROGRAMS),$(eval $(k): src/$(mark)$(MN_$(k)).bin))
$(PROGRAMS):
$(QUIET)cp $< $@
$(DISTNAME): $(PROGRAMS)
@$(STRIP) -s -R .comment -R .note -R .eh_frame_hdr -R .eh_frame $^ && mkdir -p $@; cp -rf $^ -t $@
src/ucs_to_keysym-static.h: src/ucs_to_keysym.awk src/keysymdef.h
$(QUIET)awk -f $^ > $@
src/$(mark)h.mk: $(SOURCES) $(HEADERS)
@$(CC) $(ALL_CFLAGS) $(CPPFLAGS) -MM $(SOURCES) | sed 's|^\(.*:.*\)$$|src/$(mark)\1|g' > $@
src/$(mark)o.mk: $(patsubst src/%.c, src/$(mark)%.o, $(SOURCES))
@for f in $^; do grep -sq '^main$$' "$$f.def" || continue ;\
U="/tmp/$$(basename "$$f").$$$$.und" ;\
cp "$$f.und" "$$U" ;\
while true; do \
(cat "$$U"; fgrep -w -l -f "$$U" src/*.o.def | sed 's/.def/.und/' | xargs cat) 2>/dev/null | sort -u > "$$U".2 ;\
cmp -s "$$U" "$$U".2 && break ;\
mv "$$U".2 "$$U" ;\
done ;\
echo $${f%%.o}.bin: $$f $$(fgrep -w -l -f "$$U" src/*.o.def | sed 's/.def//') ;\
rm -f "$$U"* ;\
done > $@
src/$(mark)%.bin:
$(QUIET)$(CC) $(ALL_CFLAGS) $(ALL_LDFLAGS) $^ -o $@ $(LDLIBS) $(foreach k,$^,$(LD_$(k:src/$(mark)%=%)))
src/$(mark)%.o: src/%.c
$(QUIET)$(CC) $(ALL_CFLAGS) $(CPPFLAGS) -c $< -o $@ && objdump -t $@ | awk '/\*UND\*/{print $$NF >> "[email protected]"} /g.*F.*\.text/{print $$NF >> "[email protected]"}'
%.tar.gz: %
$(QUIET)tar -czf $@ $< --remove-files
%.zip: %
$(QUIET)zip -qrm $@ $<