-
Notifications
You must be signed in to change notification settings - Fork 44
/
Makefile
173 lines (140 loc) · 6.19 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# USER-SETTABLE VARIABLES
#
# The following variables can be overridden by user (i.e.,
# make install DESTDIR=/tmp/xxx):
#
# Name Default Description
# ---- ------- -----------
# DESTDIR Destination directory for make install
# CC gcc C compiler
# CPPFLAGS C preprocessor flags
# CFLAGS -O2 -g -W -Wall -Werror C compiler flags
# LDFLAGS Linker flags
# COMPRESS gzip -n Program to compress man page, or ""
# STRIP -s Stripping of debug symbols
# PKG_CONFIG pkg-config Program to query dependencies info
# INSTALL install Installation program
#
# Variables for Installation Directories
# Name Linux BSD
# ---- ----- ---
# prefix /usr /usr/local
# exec_prefix $(prefix) $(prefix)
# sysconfdir /etc $(prefix)/etc
# bindir $(exec_prefix)/bin $(exec_prefix)/bin
# libdir $(shell $(PKG_CONFIG) --variable=libdir sane-backends)
# datarootdir $(prefix)/share $(prefix)/share
# mandir $(datarootdir)/man $(datarootdir)/man
#
CC = gcc
COMPRESS = gzip -n
CFLAGS += -O2 -g -W -Wall -Werror -pthread $(CPPFLAGS)
PKG_CONFIG = pkg-config
STRIP = -s
INSTALL = install
ifeq "$(shell uname -s)" "Linux"
prefix ?= /usr
else
prefix ?= /usr/local
endif
ifeq "$(prefix)" "/usr"
sysconfdir = /etc
else
sysconfdir = $(prefix)/etc
endif
exec_prefix = $(prefix)
bindir = $(exec_prefix)/bin
libdir = $(shell $(PKG_CONFIG) --variable=libdir sane-backends)
datarootdir = $(prefix)/share
mandir = $(datarootdir)/man
# These variables are not intended to be user-settable
OBJDIR = objs/
CONFDIR = $(sysconfdir)/sane.d
BACKEND = libsane-airscan.so.1
DISCOVER = airscan-discover
LIBAIRSCAN = $(OBJDIR)/libairscan.a
MAN_DISCOVER = $(DISCOVER).1
MAN_DISCOVER_TITLE = "SANE Scanner Access Now Easy"
MAN_BACKEND = sane-airscan.5
MAN_BACKEND_TITLE = "AirScan (eSCL) and WSD SANE backend"
DEPS_COMMON := avahi-client libxml-2.0 gnutls
DEPS_CODECS := libjpeg libpng libtiff-4
CFLAGS += -D CONFIG_SANE_CONFIG_DIR=\"$(CONFDIR)\"
# Sources and object files
SRC = $(wildcard airscan-*.c) sane_strstatus.c http_parser.c
OBJ = $(addprefix $(OBJDIR), $(SRC:.c=.o))
# Obtain CFLAGS and LDFLAGS for dependencies
deps_CFLAGS := $(foreach lib, $(DEPS_COMMON), $(shell $(PKG_CONFIG) --cflags $(lib)))
deps_CFLAGS += $(foreach lib, $(DEPS_CODECS), $(shell $(PKG_CONFIG) --cflags $(lib)))
deps_LIBS := $(foreach lib, $(DEPS_COMMON), $(shell $(PKG_CONFIG) --libs $(lib))) -lm -lpthread
deps_LIBS_CODECS := $(foreach lib, $(DEPS_CODECS), $(shell $(PKG_CONFIG) --libs $(lib)))
# Compute CFLAGS and LDFLAGS for backend and tools
#
# Note, CFLAGS are common, for simplicity, while LDFLAGS are not, to
# avoid linking unneeded libraries
common_CFLAGS := $(CFLAGS) $(deps_CFLAGS)
common_CFLAGS += -fPIC
backend_LDFLAGS := $(LDFLAGS)
backend_LDFLAGS += $(deps_LIBS) $(deps_LIBS_CODECS)
backend_LDFLAGS += -Wl,--version-script=airscan.sym -Wl,--no-undefined -lc
tools_LDFLAGS := $(LDFLAGS)
tools_LDFLAGS += $(deps_LIBS)
tools_LDFLAGS += -fPIE
tests_LDFLAGS := $(tools_LDFLAGS) $(deps_LIBS_CODECS)
$(OBJDIR)%.o: %.c Makefile airscan.h
mkdir -p $(OBJDIR)
$(CC) -c -o $@ $< $(CPPFLAGS) $(common_CFLAGS)
.PHONY: all clean install man
all: tags $(BACKEND) $(DISCOVER) test test-decode test-devcaps test-multipart test-zeroconf test-uri
tags: $(SRC) airscan.h test.c test-decode.c test-devcaps.c test-multipart.c test-zeroconf.c test-uri.c
-ctags -R .
$(BACKEND): $(OBJDIR)airscan.o $(LIBAIRSCAN) airscan.sym
$(CC) -o $(BACKEND) -shared $(OBJDIR)/airscan.o $(LIBAIRSCAN) $(backend_LDFLAGS)
$(DISCOVER): $(OBJDIR)discover.o $(LIBAIRSCAN)
$(CC) -o $(DISCOVER) discover.c $(CPPFLAGS) $(common_CFLAGS) $(LIBAIRSCAN) $(tools_LDFLAGS)
$(LIBAIRSCAN): $(OBJ) Makefile
ar cru $(LIBAIRSCAN) $(OBJ)
install: all
mkdir -p $(DESTDIR)/$(bindir)
mkdir -p $(DESTDIR)/$(CONFDIR)
mkdir -p $(DESTDIR)/$(CONFDIR)/dll.d
$(INSTALL) $(STRIP) $(DISCOVER) $(DESTDIR)/$(bindir)
[ -e $(DESTDIR)/$(CONFDIR)/airscan.conf ] || cp airscan.conf $(DESTDIR)/$(CONFDIR)
[ -e $(DESTDIR)/$(CONFDIR)/dll.d/airscan ] || cp dll.conf $(DESTDIR)/$(CONFDIR)/dll.d/airscan
mkdir -p $(DESTDIR)/$(libdir)/sane
$(INSTALL) $(STRIP) $(BACKEND) $(DESTDIR)/$(libdir)/sane
mkdir -p $(DESTDIR)/$(mandir)/man1
mkdir -p $(DESTDIR)/$(mandir)/man5
$(INSTALL) -m 644 $(MAN_DISCOVER) $(DESTDIR)/$(mandir)/man1
$(INSTALL) -m 644 $(MAN_BACKEND) $(DESTDIR)/$(mandir)/man5
[ "$(COMPRESS)" = "" ] || $(COMPRESS) -f $(DESTDIR)/$(mandir)/man1/$(MAN_DISCOVER)
[ "$(COMPRESS)" = "" ] || $(COMPRESS) -f $(DESTDIR)/$(mandir)/man5/$(MAN_BACKEND)
clean:
rm -f test test-decode test-devcaps test-multipart test-zeroconf test-uri $(BACKEND) tags
rm -rf $(OBJDIR)
uninstall:
rm -f $(DESTDIR)/$(bindir)/$(DISCOVER)
rm -f $(DESTDIR)/$(CONFDIR)/dll.d/airscan
rm -f $(DESTDIR)/$(libdir)/sane/$(BACKEND)
rm -f $(DESTDIR)/$(mandir)/man1/$(MAN_DISCOVER)*
rm -f $(DESTDIR)/$(mandir)/man5/$(MAN_BACKEND)*
check: all
./test-uri
./test-zeroconf
man: $(MAN_DISCOVER) $(MAN_BACKEND)
$(MAN_DISCOVER): $(MAN_DISCOVER).md
ronn --roff --manual=$(MAN_DISCOVER_TITLE) $(MAN_DISCOVER).md
$(MAN_BACKEND): $(MAN_BACKEND).md
ronn --roff --manual=$(MAN_BACKEND_TITLE) $(MAN_BACKEND).md
test: $(BACKEND) test.c
$(CC) -o test test.c $(BACKEND) -Wl,-rpath . $(LDFLAGS) ${common_CFLAGS}
test-decode: test-decode.c $(LIBAIRSCAN)
$(CC) -o test-decode test-decode.c $(CPPFLAGS) $(common_CFLAGS) $(LIBAIRSCAN) $(tests_LDFLAGS)
test-devcaps: test-devcaps.c $(LIBAIRSCAN)
$(CC) -o test-devcaps test-devcaps.c $(CPPFLAGS) $(common_CFLAGS) $(LIBAIRSCAN) $(tests_LDFLAGS)
test-multipart: test-multipart.c $(LIBAIRSCAN)
$(CC) -o test-multipart test-multipart.c $(CPPFLAGS) $(common_CFLAGS) $(LIBAIRSCAN) $(tests_LDFLAGS)
test-zeroconf: test-zeroconf.c $(LIBAIRSCAN)
$(CC) -o test-zeroconf test-zeroconf.c $(CPPFLAGS) $(common_CFLAGS) $(LIBAIRSCAN) $(tests_LDFLAGS)
test-uri: test-uri.c $(LIBAIRSCAN)
$(CC) -o test-uri test-uri.c $(CPPFLAGS) $(common_CFLAGS) $(LIBAIRSCAN) $(tests_LDFLAGS)