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