Commit | Line | Data |
---|---|---|
b2441318 | 1 | # SPDX-License-Identifier: GPL-2.0 |
85c66be1 | 2 | include ../../scripts/Makefile.include |
ca70c24f | 3 | include ../../scripts/utilities.mak # QUIET_CLEAN |
85c66be1 | 4 | |
b4f91668 | 5 | ifeq ($(srctree),) |
e19b7cee | 6 | srctree := $(patsubst %/,%,$(dir $(CURDIR))) |
b4f91668 JO |
7 | srctree := $(patsubst %/,%,$(dir $(srctree))) |
8 | srctree := $(patsubst %/,%,$(dir $(srctree))) | |
9 | #$(info Determined 'srctree' to be $(srctree)) | |
10 | endif | |
11 | ||
12024aac DCC |
12 | CC ?= $(CROSS_COMPILE)gcc |
13 | AR ?= $(CROSS_COMPILE)ar | |
14 | LD ?= $(CROSS_COMPILE)ld | |
3c4797d4 | 15 | |
b4f91668 | 16 | MAKEFLAGS += --no-print-directory |
85c66be1 | 17 | |
a6efaa2c IR |
18 | INSTALL = install |
19 | ||
20 | ||
21 | # Use DESTDIR for installing into a different root directory. | |
22 | # This is useful for building a package. The program will be | |
23 | # installed in this directory as if it was the root directory. | |
24 | # Then the build tool can move it later. | |
25 | DESTDIR ?= | |
26 | DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))' | |
27 | ||
285a8f24 | 28 | LIBFILE = $(OUTPUT)libapi.a |
85c66be1 | 29 | |
b4f91668 | 30 | CFLAGS := $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) |
58b79186 | 31 | CFLAGS += -ggdb3 -Wall -Wextra -std=gnu99 -U_FORTIFY_SOURCE -fPIC |
49b3cd30 | 32 | |
58b79186 | 33 | ifeq ($(DEBUG),0) |
49b3cd30 | 34 | CFLAGS += -O3 |
58b79186 JO |
35 | endif |
36 | ||
37 | ifeq ($(DEBUG),0) | |
38 | CFLAGS += -D_FORTIFY_SOURCE | |
39 | endif | |
b983d544 CP |
40 | |
41 | # Treat warnings as errors unless directed not to | |
42 | ifneq ($(WERROR),0) | |
43 | CFLAGS += -Werror | |
44 | endif | |
45 | ||
b4f91668 | 46 | CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 |
975f14fa | 47 | CFLAGS += -I$(srctree)/tools/lib/api |
b31e3e33 | 48 | CFLAGS += -I$(srctree)/tools/include |
85c66be1 BP |
49 | |
50 | RM = rm -f | |
51 | ||
285a8f24 | 52 | API_IN := $(OUTPUT)libapi-in.o |
85c66be1 | 53 | |
a6efaa2c IR |
54 | ifeq ($(LP64), 1) |
55 | libdir_relative = lib64 | |
56 | else | |
57 | libdir_relative = lib | |
58 | endif | |
59 | ||
60 | prefix ?= | |
61 | libdir = $(prefix)/$(libdir_relative) | |
62 | ||
63 | # Shell quotes | |
64 | libdir_SQ = $(subst ','\'',$(libdir)) | |
65 | ||
7c422f55 JO |
66 | all: |
67 | ||
b4f91668 | 68 | export srctree OUTPUT CC LD CFLAGS V |
ab6201d0 | 69 | include $(srctree)/tools/build/Makefile.include |
a6efaa2c | 70 | include $(srctree)/tools/scripts/Makefile.include |
85c66be1 | 71 | |
7c422f55 | 72 | all: fixdep $(LIBFILE) |
553873e1 | 73 | |
b4f91668 | 74 | $(API_IN): FORCE |
285a8f24 | 75 | @$(MAKE) $(build)=libapi |
b4f91668 JO |
76 | |
77 | $(LIBFILE): $(API_IN) | |
78 | $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(API_IN) | |
85c66be1 | 79 | |
a6efaa2c IR |
80 | define do_install_mkdir |
81 | if [ ! -d '$(DESTDIR_SQ)$1' ]; then \ | |
82 | $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \ | |
83 | fi | |
84 | endef | |
85 | ||
86 | define do_install | |
1849f9f0 IR |
87 | if [ ! -d '$2' ]; then \ |
88 | $(INSTALL) -d -m 755 '$2'; \ | |
89 | fi; \ | |
90 | $(INSTALL) $1 $(if $3,-m $3,) '$2' | |
a6efaa2c IR |
91 | endef |
92 | ||
93 | install_lib: $(LIBFILE) | |
94 | $(call QUIET_INSTALL, $(LIBFILE)) \ | |
95 | $(call do_install_mkdir,$(libdir_SQ)); \ | |
96 | cp -fpR $(LIBFILE) $(DESTDIR)$(libdir_SQ) | |
97 | ||
d118b08f | 98 | HDRS := cpu.h debug.h io.h io_dir.h |
1849f9f0 IR |
99 | FD_HDRS := fd/array.h |
100 | FS_HDRS := fs/fs.h fs/tracing_path.h | |
101 | INSTALL_HDRS_PFX := $(DESTDIR)$(prefix)/include/api | |
102 | INSTALL_HDRS := $(addprefix $(INSTALL_HDRS_PFX)/, $(HDRS)) | |
103 | INSTALL_FD_HDRS := $(addprefix $(INSTALL_HDRS_PFX)/, $(FD_HDRS)) | |
104 | INSTALL_FS_HDRS := $(addprefix $(INSTALL_HDRS_PFX)/, $(FS_HDRS)) | |
105 | ||
106 | $(INSTALL_HDRS): $(INSTALL_HDRS_PFX)/%.h: %.h | |
107 | $(call QUIET_INSTALL, $@) \ | |
108 | $(call do_install,$<,$(INSTALL_HDRS_PFX)/,644) | |
109 | ||
110 | $(INSTALL_FD_HDRS): $(INSTALL_HDRS_PFX)/fd/%.h: fd/%.h | |
111 | $(call QUIET_INSTALL, $@) \ | |
112 | $(call do_install,$<,$(INSTALL_HDRS_PFX)/fd/,644) | |
113 | ||
114 | $(INSTALL_FS_HDRS): $(INSTALL_HDRS_PFX)/fs/%.h: fs/%.h | |
115 | $(call QUIET_INSTALL, $@) \ | |
116 | $(call do_install,$<,$(INSTALL_HDRS_PFX)/fs/,644) | |
117 | ||
118 | install_headers: $(INSTALL_HDRS) $(INSTALL_FD_HDRS) $(INSTALL_FS_HDRS) | |
119 | $(call QUIET_INSTALL, libapi_headers) | |
a6efaa2c IR |
120 | |
121 | install: install_lib install_headers | |
122 | ||
85c66be1 | 123 | clean: |
285a8f24 | 124 | $(call QUIET_CLEAN, libapi) $(RM) $(LIBFILE); \ |
5c816641 | 125 | find $(or $(OUTPUT),.) -name \*.o -or -name \*.o.cmd -or -name \*.o.d | xargs $(RM) |
b4f91668 JO |
126 | |
127 | FORCE: | |
85c66be1 | 128 | |
b4f91668 | 129 | .PHONY: clean FORCE |