forked from xemul/libct
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
235 lines (188 loc) · 4.93 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
VERSION_MAJOR := 0
VERSION_MINOR := 1
VERSION_SUBLEVEL :=
VERSION_EXTRA :=
VERSION_NAME :=
VERSION_SO_MAJOR := 0
VERSION_SO_MINOR := 1
MAKEFLAGS := -r -R --no-print-directory
ifeq ($(strip $(V)),)
E = @echo
Q = @
else
E = @\#
Q =
endif
FIND := find
CSCOPE := cscope
TAGS := ctags
RM := rm -f
CP := cp
LD := ld
CC := gcc
CD := cd
ECHO := echo
NM := nm
AWK := awk
SH := bash
MAKE := make
OBJCOPY := objcopy
MKDIR := mkdir
LN := ln
ESED := esed
SED := sed
CAT := cat
#
# Fetch ARCH from the uname if not yet set
#
ARCH ?= $(shell uname -m | sed \
-e s/i.86/i386/ \
-e s/sun4u/sparc64/ \
-e s/arm.*/arm/ \
-e s/sa110/arm/ \
-e s/s390x/s390/ \
-e s/parisc64/parisc/ \
-e s/ppc.*/powerpc/ \
-e s/mips.*/mips/ \
-e s/sh[234].*/sh/)
ifeq ($(ARCH),x86_64)
ARCH := x86
DEFINES := -DCONFIG_X86_64 -DARCH="\"$(ARCH)\""
LDARCH := i386:x86-64
endif
# Installation paths
PREFIX ?= /usr/local
MANDIR := $(PREFIX)/share/man
LIBDIR := $(PREFIX)/lib
# For recent Debian/Ubuntu with multiarch support
DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture \
-qDEB_HOST_MULTIARCH 2>/dev/null)
ifneq "$(DEB_HOST_MULTIARCH)" ""
LIBDIR := $(PREFIX)/lib/$(DEB_HOST_MULTIARCH)
# For most other systems
else ifeq "$(shell uname -m)" "x86_64"
LIBDIR := $(PREFIX)/lib64
endif
INCLUDEDIR := $(PREFIX)/include/libct
ifneq ($(ARCH),x86)
$(error "The architecture $(ARCH) isn't supported"))
endif
ifneq ("$(wildcard /proc/vz)","")
VZ := 1
endif
cflags-y += -iquote src/include
cflags-y += -iquote src/include/vz
cflags-y += -iquote src/lsm
cflags-y += -iquote src
cflags-y += -fno-strict-aliasing
cflags-y += -I/usr/include
cflags-y += -I/usr/include/libnl3
cflags-y += -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include
cflags-y += -I/usr/lib64/dbus-1.0/include/
cflags-y += -I/usr/include/dbus-1.0
export cflags-y
VERSION_MAJOR := 0
VERSION_MINOR := 1
VERSION_SUBLEVEL := 0
VERSION_EXTRA :=
VERSION_NAME :=
CONFIG_SELINUX :=
CONFIG_APPARMOR :=
# FAKE_LIBS is required for go bindings,
# because LDFLAGS can not be customized there
FAKE_LIBS :=
export VERSION_MAJOR VERSION_MINOR VERSION_SUBLEVEL VERSION_EXTRA VERSION_NAME
include scripts/Makefile.version
include scripts/Makefile.config
LIBS := -lrt
DEFINES += -D_FILE_OFFSET_BITS=64
DEFINES += -D_GNU_SOURCE
WARNINGS := -Wall -Wno-unused-result
ifneq ($(WERROR),0)
WARNINGS += -Werror
endif
ifeq ($(DEBUG),1)
DEFINES += -DCR_DEBUG
CFLAGS += -O0 -ggdb3
else
CFLAGS += -O2
endif
ifeq ($(CONFIG_APPARMOR),y)
DEFINES += -DHAVE_APPARMOR
else
FAKE_LIBS += libapparmor.a
endif
ifeq ($(CONFIG_SELINUX),y)
DEFINES += -DHAVE_SELINUX
else
FAKE_LIBS += libselinux.a
endif
CFLAGS += $(WARNINGS) $(DEFINES)
export E Q CC ECHO MAKE CFLAGS LIBS ARCH DEFINES MAKEFLAGS
export CONFIG_SELINUX CONFIG_APPARMOR
export SH RM OBJCOPY LDARCH LD CP MKDIR CD LN
export ESED SED CAT
include scripts/Makefile.rules
build := -r -R --no-print-directory -f scripts/Makefile.build makefile=Makefile obj
run := -r -R --no-print-directory
LIBCT := libct
LIBCT-INC := src/include/uapi/libct.h src/include/uapi/libct-log-levels.h src/include/uapi/libct-errors.h
.PHONY: all clean tags docs
cflags-y += -I.shipped/libnl/include/
cflags-y += -iquote src/include
cflags-y += -iquote src/arch/$(ARCH)/include
export cflags-y
#
# First order targets, usually pregenerated
EARLY-GEN := $(VERSION_HEADER) config
#
# Library itself
src/%: $(EARLY-GEN)
$(Q) $(MAKE) $(build)=src $@
src: $(EARLY-GEN)
$(Q) $(MAKE) $(build)=src all
.PHONY: src
$(LIBCT).a: src/$(LIBCT).a
$(E) " LN " $@
$(Q) $(LN) -sf $^ $@
$(LIBCT).so: src/$(LIBCT).so
$(E) " LN " $@
$(Q) $(LN) -sf $^ $@
libselinux.a: src/$(LIBCT).a
$(Q) $(LN) -sf $^ $@
libapparmor.a: src/$(LIBCT).a
$(Q) $(LN) -sf $^ $@
src/$(LIBCT).so: src/$(LIBCT).a
all: $(LIBCT).so $(LIBCT).a $(FAKE_LIBS)
@true
test-build:
$(Q) $(MAKE) -C test all
test: test-build
$(Q) $(MAKE) -C test run-local
docs:
$(Q) $(MAKE) -s -C Documentation all
docs-pdf:
$(Q) $(MAKE) -s -C Documentation all-pdfs
tags:
$(E) " GEN " $@
$(Q) $(RM) tags
$(Q) $(FIND) -L . \( -name '*.[hcS]' -o -name '*.go' \) ! -path './.*' -print | xargs ctags -a
clean:
$(Q) $(MAKE) $(build)=src clean
$(Q) $(MAKE) -C test clean
$(Q) $(MAKE) -s -C Documentation clean
$(Q) $(RM) $(LIBCT).so $(LIBCT).a
$(Q) $(RM) $(CONFIG)
$(Q) $(RM) $(VERSION_HEADER)
$(Q) $(RM) libapparmor.a libselinux.a
install:
$(E) " INSTALL "
$(Q) install -D -m 755 $(LIBCT).so \
$(DESTDIR)$(LIBDIR)/$(LIBCT).so.$(VERSION_SO_MAJOR).$(VERSION_SO_MINOR)
$(Q) ln -fns $(LIBCT).so.$(VERSION_SO_MAJOR).$(VERSION_SO_MINOR) \
$(DESTDIR)$(LIBDIR)/$(LIBCT).so.$(VERSION_SO_MAJOR)
$(Q) ln -fns $(LIBCT).so.$(VERSION_SO_MAJOR).$(VERSION_SO_MINOR) \
$(DESTDIR)$(LIBDIR)/$(LIBCT).so
$(Q) mkdir -p $(DESTDIR)$(INCLUDEDIR)
$(Q) install -m 644 $(LIBCT-INC) $(DESTDIR)$(INCLUDEDIR)
.DEFAULT_GOAL := all