forked from libhugetlbfs/libhugetlbfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
481 lines (409 loc) · 12 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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
PREFIX ?= /usr/local
EXEDIR ?= /bin
LIBOBJS = hugeutils.o version.o init.o morecore.o debug.o alloc.o shm.o kernel-features.o
LIBPUOBJS = init_privutils.o debug.o hugeutils.o kernel-features.o
INSTALL_OBJ_LIBS = libhugetlbfs.so libhugetlbfs.a libhugetlbfs_privutils.so
BIN_OBJ_DIR=obj
INSTALL_BIN = hugectl hugeedit hugeadm pagesize
INSTALL_HELPER = huge_page_setup_helper.py
INSTALL_PERLMOD = DataCollect.pm OpCollect.pm PerfCollect.pm Report.pm
INSTALL_HEADERS = hugetlbfs.h
INSTALL_MAN1 = ld.hugetlbfs.1 pagesize.1
INSTALL_MAN3 = get_huge_pages.3 get_hugepage_region.3 gethugepagesize.3 \
gethugepagesizes.3 getpagesizes.3 hugetlbfs_find_path.3 \
hugetlbfs_test_path.3 hugetlbfs_unlinked_fd.3
INSTALL_MAN7 = libhugetlbfs.7
INSTALL_MAN8 = hugectl.8 hugeedit.8 hugeadm.8
LDSCRIPT_TYPES = B BDT
LDSCRIPT_DIST_ELF = elf32ppclinux elf64ppc elf_i386 elf_x86_64
INSTALL_OBJSCRIPT = ld.hugetlbfs
VERSION=version.h
SOURCE = $(shell find . -maxdepth 1 ! -name version.h -a -name '*.[h]')
SOURCE += *.c *.lds Makefile
NODEPTARGETS=<version.h> <clean>
INSTALL = install
LDFLAGS += -ldl
CFLAGS ?= -O2 -g
CFLAGS += -Wall -fPIC
CPPFLAGS += -D__LIBHUGETLBFS__
ARCH ?= $(shell uname -m | sed -e s/i.86/i386/)
CC ?= gcc
CUSTOM_LDSCRIPTS = yes
ifeq ($(ARCH),ppc64)
CC64 = $(CC) -m64
ELF64 = elf64ppc
TMPLIB64 = lib64
TMPLIB32 = lib
ifneq ($(BUILDTYPE),NATIVEONLY)
CC32 = $(CC) -m32
ELF32 = elf32ppclinux
endif
else
ifeq ($(ARCH),ppc64le)
CC64 = $(CC) -m64
ELF64 = elf64lppc
TMPLIB64 = lib64
CUSTOM_LDSCRIPTS = no
else
ifeq ($(ARCH),ppc)
CC32 = $(CC) -m32
ELF32 = elf32ppclinux
TMPLIB32 = lib
CPPFLAGS += -DPPC_NO_SEGMENTS
else
ifneq (,$(findstring arm,$(ARCH)))
CC32 = $(CC)
TMPLIB32 = lib
ELF32 += armelf_linux_eabi
CUSTOM_LDSCRIPTS = no
else
ifneq (,$(findstring aarch64,$(ARCH)))
CC64 = $(CC)
ELF64 = aarch64elf
TMPLIB64 = lib64
CUSTOM_LDSCRIPTS = no
else
ifneq (,$(filter i386 i486 i586 i686,$(ARCH)))
CC32 = $(CC)
ELF32 = elf_i386
TMPLIB32 = lib
else
ifeq ($(ARCH),x86_64)
CC64 = $(CC) -m64
ELF64 = elf_x86_64
TMPLIB64 = lib64
TMPLIB32 = lib
ifneq ($(BUILDTYPE),NATIVEONLY)
CC32 = $(CC) -m32
ELF32 = elf_i386
endif
else
ifeq ($(ARCH),ia64)
CC64 = $(CC)
TMPLIB64 = lib64
CFLAGS += -DNO_ELFLINK
else
ifeq ($(ARCH),sparc64)
CC64 = $(CC) -m64
TMPLIB64 = lib64
CFLAGS += -DNO_ELFLINK
else
ifeq ($(ARCH),s390x)
CC64 = $(CC) -m64
ELF64 = elf64_s390
TMPLIB64 = lib64
TMPLIB32 = lib
CUSTOM_LDSCRIPTS = no
ifneq ($(BUILDTYPE),NATIVEONLY)
CC32 = $(CC) -m31
ELF32 = elf_s390
endif
else
ifeq ($(ARCH),s390)
CC32 = $(CC) -m31
ELF32 = elf_s390
TMPLIB32 = lib
CUSTOM_LDSCRIPTS = no
else
ifeq ($(ARCH),riscv64)
CC64 = $(CC)
ELF64 = elf_riscv64
TMPLIB64 = lib64
CUSTOM_LDSCRIPTS = no
else
$(error "Unrecognized architecture ($(ARCH))")
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
ifdef CC32
OBJDIRS += obj32
endif
ifdef CC64
OBJDIRS += obj64
endif
ifdef CC64
CCBIN = $(CC64)
else
CCBIN = $(CC32)
endif
ifdef ELF32
LIBOBJS32 = obj32/elflink.o obj32/sys-$(ELF32).o
endif
ifdef ELF64
LIBOBJS64 = obj64/elflink.o obj64/sys-$(ELF64).o
endif
ifeq ($(ELF32),elf32ppclinux)
LIBOBJS32 += obj32/$(ELF32).o
endif
ifeq ($(ELF64),elf64ppc)
LIBOBJS64 += obj64/$(ELF64).o
endif
ifeq ($(ELF64),elf64lppc)
LIBOBJS64 += obj64/$(ELF64).o
endif
LIBOBJS32 += $(LIBOBJS:%=obj32/%)
LIBOBJS64 += $(LIBOBJS:%=obj64/%)
ifeq ($(LIB32),)
LIB32 = $(TMPLIB32)
endif
ifdef TMPLIB64
ifeq ($(LIB64),)
LIB64 = $(TMPLIB64)
endif
endif
ifeq ($(CUSTOM_LDSCRIPTS),yes)
TEST_LDSCRIPTS = -l
endif
# If building for both 32- and 64-bit, then make sure we are not resolving
# LIB32 and LIB64 to the same place
ifdef TMPLIB64
ifneq ($(BUILDTYPE),NATIVEONLY)
REALLIB32 = $(realpath $(PREFIX)/$(LIB32))
REALLIB64 = $(realpath $(PREFIX)/$(LIB64))
ifneq ($(realpath $(PREFIX)),)
ifeq ($(REALLIB32),$(REALLIB64))
$(error LIB32 ($(PREFIX)/$(LIB32) to $(REALLIB32)) and LIB64 ($(PREFIX)/$(LIB64) to $(REALLIB64)) are resolving to the same place. Manually specify LIB32 and LIB64. e.g. make PREFIX=$(PREFIX) LIB32=lib32 LIB64=lib64)
endif
endif
endif
endif
HEADERDIR = $(PREFIX)/include
LIBDIR32 = $(PREFIX)/$(LIB32)
LIBDIR64 = $(PREFIX)/$(LIB64)
LDSCRIPTDIR = $(PREFIX)/share/libhugetlbfs/ldscripts
BINDIR = $(PREFIX)/share/libhugetlbfs
EXEDIR = $(PREFIX)/bin
DOCDIR = $(PREFIX)/share/doc/libhugetlbfs
MANDIR = $(PREFIX)/share/man
MANDIR1 = $(MANDIR)/man1
MANDIR3 = $(MANDIR)/man3
MANDIR7 = $(MANDIR)/man7
MANDIR8 = $(MANDIR)/man8
ifdef LIB32
LIBPATHS += -DLIB32='"$(LIB32)"' -DLIBDIR32='"$(LIBDIR32)"'
endif
ifdef LIB64
LIBPATHS += -DLIB64='"$(LIB64)"' -DLIBDIR64='"$(LIBDIR64)"'
endif
EXTRA_DIST = \
README \
HOWTO \
LGPL-2.1
INSTALL_LDSCRIPTS = $(foreach type,$(LDSCRIPT_TYPES),$(LDSCRIPT_DIST_ELF:%=%.x$(type)))
ifdef V
VECHO = :
else
VECHO = echo " "
ARFLAGS = rc
.SILENT:
endif
DEPFILES = $(LIBOBJS:%.o=%.d)
export ARCH
export OBJDIRS
export CC32
export CC64
export ELF32
export ELF64
export LIBDIR32
export LIBDIR64
export CUSTOM_LDSCRIPTS
all: libs tests tools
.PHONY: tests libs
libs: $(foreach file,$(INSTALL_OBJ_LIBS),$(OBJDIRS:%=%/$(file))) $(BIN_OBJ_DIR)/libhugetlbfs_privutils.a
tests: libs # Force make to build the library first
tests: tests/all
tests/%: libs
$(MAKE) -C tests $*
tools: $(foreach file,$(INSTALL_BIN),$(BIN_OBJ_DIR)/$(file))
check: all
cd tests; ./run_tests.py $(TEST_LDSCRIPTS)
checkv: all
cd tests; ./run_tests.py -vV $(TEST_LDSCRIPTS)
func: all
cd tests; ./run_tests.py -t func $(TEST_LDSCRIPTS)
funcv: all
cd tests; ./run_tests.py -t func -vV $(TEST_LDSCRIPTS)
stress: all
cd tests; ./run_tests.py -t stress
stressv: all
cd tests; ./run_tests.py -t stress -vV
# Don't want to remake objects just 'cos the directory timestamp changes
$(OBJDIRS): %:
@mkdir -p $@
# <Version handling>
$(VERSION): always
@$(VECHO) VERSION
./localversion version $(SOURCE)
always:
# </Version handling>
snapshot: $(VERSION)
.SECONDARY:
obj32/%.o: %.c
@$(VECHO) CC32 $@
@mkdir -p obj32
$(CC32) $(CPPFLAGS) $(CFLAGS) -o $@ -c $<
obj64/%.o: %.c
@$(VECHO) CC64 $@
@mkdir -p obj64
$(CC64) $(CPPFLAGS) $(CFLAGS) -o $@ -c $<
obj32/%.o: %.S
@$(VECHO) AS32 $@
@mkdir -p obj32
$(CC32) $(CPPFLAGS) -o $@ -c $<
obj64/%.o: %.S
@$(VECHO) AS64 $@
@mkdir -p obj64
$(CC64) $(CPPFLAGS) -o $@ -c $<
obj32/libhugetlbfs.a: $(LIBOBJS32)
@$(VECHO) AR32 $@
$(AR) $(ARFLAGS) $@ $^
obj64/libhugetlbfs.a: $(LIBOBJS64)
@$(VECHO) AR64 $@
$(AR) $(ARFLAGS) $@ $^
obj32/libhugetlbfs.so: $(LIBOBJS32)
@$(VECHO) LD32 "(shared)" $@
$(CC32) $(LDFLAGS) -Wl,--version-script=version.lds -Wl,-soname,$(notdir $@) -shared -o $@ $^ $(LDLIBS)
obj64/libhugetlbfs.so: $(LIBOBJS64)
@$(VECHO) LD64 "(shared)" $@
$(CC64) $(LDFLAGS) -Wl,--version-script=version.lds -Wl,-soname,$(notdir $@) -shared -o $@ $^ $(LDLIBS)
#obj32/libhugetlbfs_privutils.a: $(LIBPUOBJS:%=obj32/%)
# @$(VECHO) AR32 $@
# $(AR) $(ARFLAGS) $@ $^
#
#obj64/libhugetlbfs_privutils.a: $(LIBPUOBJS:%=obj64/%)
# @$(VECHO) AR64 $@
# $(AR) $(ARFLAGS) $@ $^
$(BIN_OBJ_DIR)/libhugetlbfs_privutils.a: $(LIBPUOBJS:%=$(BIN_OBJ_DIR)/%)
@$(VECHO) ARHOST $@
$(AR) $(ARFLAGS) $@ $^
obj32/libhugetlbfs_privutils.so: $(LIBPUOBJS:%=obj32/%)
@$(VECHO) LD32 "(shared)" $@
$(CC32) $(LDFLAGS) -Wl,--version-script=privutils.lds -Wl,-soname,$(notdir $@) -shared -o $@ $^ $(LDLIBS)
obj64/libhugetlbfs_privutils.so: $(LIBPUOBJS:%=obj64/%)
@$(VECHO) LD64 "(shared)" $@
$(CC64) $(LDFLAGS) -Wl,--version-script=privutils.lds -Wl,-soname,$(notdir $@) -shared -o $@ $^ $(LDLIBS)
obj32/%.i: %.c
@$(VECHO) CPP $@
$(CC32) $(CPPFLAGS) -E $< > $@
obj64/%.i: %.c
@$(VECHO) CPP $@
$(CC64) $(CPPFLAGS) -E $< > $@
obj32/%.s: %.c
@$(VECHO) CC32 -S $@
$(CC32) $(CPPFLAGS) $(CFLAGS) -o $@ -S $<
obj64/%.s: %.c
@$(VECHO) CC64 -S $@
$(CC64) $(CPPFLAGS) $(CFLAGS) -o $@ -S $<
$(BIN_OBJ_DIR)/%.o: %.c
@$(VECHO) CCHOST $@
@mkdir -p $(BIN_OBJ_DIR)
$(CCBIN) $(CPPFLAGS) $(CFLAGS) $(LIBPATHS) -o $@ -c $<
$(BIN_OBJ_DIR)/hugectl: $(BIN_OBJ_DIR)/hugectl.o
@$(VECHO) LDHOST $@
mkdir -p $(BIN_OBJ_DIR)
$(CCBIN) $(CPPFLAGS) $(CFLAGS) -o $@ $^ $(LDFLAGS)
$(BIN_OBJ_DIR)/hugeedit: $(BIN_OBJ_DIR)/hugeedit.o
@$(VECHO) LDHOST $@
mkdir -p $(BIN_OBJ_DIR)
$(CCBIN) $(CPPFLAGS) $(CFLAGS) $(LIBPATHS) -o $@ $^ $(LDFLAGS)
HUGEADM_OBJ=hugeadm.o libhugetlbfs_privutils.a
$(BIN_OBJ_DIR)/hugeadm: $(foreach file,$(HUGEADM_OBJ),$(BIN_OBJ_DIR)/$(file))
@$(VECHO) LDHOST $@
mkdir -p $(BIN_OBJ_DIR)
$(CCBIN) $(CPPFLAGS) $(CFLAGS) $(LIBPATHS) -o $@ $^ $(LDFLAGS)
PAGESIZE_OBJ=pagesize.o libhugetlbfs_privutils.a
$(BIN_OBJ_DIR)/pagesize: $(foreach file,$(PAGESIZE_OBJ),$(BIN_OBJ_DIR)/$(file))
@$(VECHO) LDHOST $@
mkdir -p $(BIN_OBJ_DIR)
$(CCBIN) $(CPPFLAGS) $(CFLAGS) $(LIBPATHS) -o $@ $^ $(LDFLAGS)
clean:
@$(VECHO) CLEAN
rm -f *~ *.o *.so *.a *.d *.i core a.out $(VERSION)
rm -rf obj*
rm -f ldscripts/*~
rm -f libhugetlbfs-sock
$(MAKE) -C tests clean
%.d: %.c $(VERSION)
@$(CC) $(CPPFLAGS) -MM -MT "$(foreach DIR,$(OBJDIRS),$(DIR)/$*.o) $@" $< > $@
# Workaround: Don't build dependencies for certain targets
# When the include below is executed, make will use the %.d target above to
# generate missing files. For certain targets (clean, version.h, etc) we don't
# need or want these dependency files, so don't include them in this case.
ifeq (,$(findstring <$(MAKECMDGOALS)>,$(NODEPTARGETS)))
-include $(DEPFILES)
endif
obj32/install:
@$(VECHO) INSTALL-LIB32 $(LIBDIR32)
$(INSTALL) -d $(DESTDIR)$(LIBDIR32)
$(INSTALL) $(INSTALL_OBJ_LIBS:%=obj32/%) $(DESTDIR)$(LIBDIR32)
obj64/install:
@$(VECHO) INSTALL-LIB64 $(LIBDIR64)
$(INSTALL) -d $(DESTDIR)$(LIBDIR64)
$(INSTALL) $(INSTALL_OBJ_LIBS:%=obj64/%) $(DESTDIR)$(LIBDIR64)
objscript.%: %
@$(VECHO) OBJSCRIPT $*
sed "s!### SET DEFAULT LDSCRIPT PATH HERE ###!HUGETLB_LDSCRIPT_PATH=$(LDSCRIPTDIR)!;s!### SET CUSTOM_LDSCRIPTS HERE ###!CUSTOM_LDSCRIPTS=\"$(CUSTOM_LDSCRIPTS)\"!" < $< > $@
install-libs: libs $(OBJDIRS:%=%/install) $(INSTALL_OBJSCRIPT:%=objscript.%)
$(INSTALL) -d $(DESTDIR)$(HEADERDIR)
$(INSTALL) -d $(DESTDIR)$(LDSCRIPTDIR)
$(INSTALL) -d $(DESTDIR)$(BINDIR)
$(INSTALL) -m 644 -t $(DESTDIR)$(HEADERDIR) $(INSTALL_HEADERS)
$(INSTALL) -m 644 $(INSTALL_LDSCRIPTS:%=ldscripts/%) $(DESTDIR)$(LDSCRIPTDIR)
for x in $(INSTALL_OBJSCRIPT); do \
$(INSTALL) -m 755 objscript.$$x $(DESTDIR)$(BINDIR)/$$x; done
cd $(DESTDIR)$(BINDIR) && ln -sf ld.hugetlbfs ld
install-man:
@$(VECHO) INSTALL_MAN $(DESTDIR)manX
$(INSTALL) -d $(DESTDIR)$(MANDIR1)
$(INSTALL) -d $(DESTDIR)$(MANDIR3)
$(INSTALL) -d $(DESTDIR)$(MANDIR7)
$(INSTALL) -d $(DESTDIR)$(MANDIR8)
for x in $(INSTALL_MAN1); do \
$(INSTALL) -m 444 man/$$x $(DESTDIR)$(MANDIR1); \
gzip -f $(DESTDIR)$(MANDIR1)/$$x; \
done
for x in $(INSTALL_MAN3); do \
$(INSTALL) -m 444 man/$$x $(DESTDIR)$(MANDIR3); \
gzip -f $(DESTDIR)$(MANDIR3)/$$x; \
done
rm -f $(DESTDIR)$(MANDIR3)/free_huge_pages.3.gz
rm -f $(DESTDIR)$(MANDIR3)/free_hugepage_region.3.gz
rm -f $(DESTDIR)$(MANDIR3)/hugetlbfs_unlinked_fd_for_size.3.gz
rm -f $(DESTDIR)$(MANDIR3)/hugetlbfs_find_path_for_size.3.gz
ln -s get_huge_pages.3.gz $(DESTDIR)$(MANDIR3)/free_huge_pages.3.gz
ln -s get_hugepage_region.3.gz $(DESTDIR)$(MANDIR3)/free_hugepage_region.3.gz
ln -s hugetlbfs_unlinked_fd.3.gz $(DESTDIR)$(MANDIR3)/hugetlbfs_unlinked_fd_for_size.3.gz
ln -s hugetlbfs_find_path.3.gz $(DESTDIR)$(MANDIR3)/hugetlbfs_find_path_for_size.3.gz
for x in $(INSTALL_MAN7); do \
$(INSTALL) -m 444 man/$$x $(DESTDIR)$(MANDIR7); \
gzip -f $(DESTDIR)$(MANDIR7)/$$x; \
done
for x in $(INSTALL_MAN8); do \
$(INSTALL) -m 444 man/$$x $(DESTDIR)$(MANDIR8); \
gzip -f $(DESTDIR)$(MANDIR8)/$$x; \
done
install-bin:
@$(VECHO) INSTALL_BIN $(DESTDIR)$(EXEDIR)
$(INSTALL) -d $(DESTDIR)$(EXEDIR)
for x in $(INSTALL_BIN); do \
$(INSTALL) -m 755 $(BIN_OBJ_DIR)/$$x $(DESTDIR)$(EXEDIR); done
install: install-libs install-bin install-man
install-helper:
@$(VECHO) INSTALL_HELPER $(DESTDIR)$(EXEDIR)
$(INSTALL) -d $(DESTDIR)$(EXEDIR)
for x in $(INSTALL_HELPER); do \
$(INSTALL) -m 755 $$x $(DESTDIR)$(EXEDIR); done
install-docs:
$(INSTALL) -d $(DESTDIR)$(DOCDIR)
for x in $(EXTRA_DIST); do $(INSTALL) -m 755 $$x $(DESTDIR)$(DOCDIR)/$$x; done
install-tests: tests install # Force make to build tests and install the library first
${MAKE} -C tests install DESTDIR=$(DESTDIR) OBJDIRS="$(OBJDIRS)" LIB32=$(LIB32) LIB64=$(LIB64)