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