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