xref: /linux/tools/lib/subcmd/Makefile (revision 473f6c8f437b049f8ec015d57cd59bb983b1d85c)
1b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0
24b6ab94eSJosh Poimboeufinclude ../../scripts/Makefile.include
3ca70c24fSArnaldo Carvalho de Meloinclude ../../scripts/utilities.mak		# QUIET_CLEAN
44b6ab94eSJosh Poimboeuf
54b6ab94eSJosh Poimboeufifeq ($(srctree),)
6e19b7ceeSUwe Kleine-Königsrctree := $(patsubst %/,%,$(dir $(CURDIR)))
74b6ab94eSJosh Poimboeufsrctree := $(patsubst %/,%,$(dir $(srctree)))
84b6ab94eSJosh Poimboeufsrctree := $(patsubst %/,%,$(dir $(srctree)))
94b6ab94eSJosh Poimboeuf#$(info Determined 'srctree' to be $(srctree))
104b6ab94eSJosh Poimboeufendif
114b6ab94eSJosh Poimboeuf
124b6ab94eSJosh PoimboeufRM = rm -f
134b6ab94eSJosh Poimboeuf
144b6ab94eSJosh PoimboeufMAKEFLAGS += --no-print-directory
154b6ab94eSJosh Poimboeuf
16630ae80eSIan RogersINSTALL = install
17630ae80eSIan Rogers
18630ae80eSIan Rogers# Use DESTDIR for installing into a different root directory.
19630ae80eSIan Rogers# This is useful for building a package. The program will be
20630ae80eSIan Rogers# installed in this directory as if it was the root directory.
21630ae80eSIan Rogers# Then the build tool can move it later.
22630ae80eSIan RogersDESTDIR ?=
23630ae80eSIan RogersDESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
24630ae80eSIan Rogers
254b6ab94eSJosh PoimboeufLIBFILE = $(OUTPUT)libsubcmd.a
264b6ab94eSJosh Poimboeuf
27d894967fSJames ClarkCFLAGS := -ggdb3 -Wall -Wextra -std=gnu99 -fPIC
284b0b2b09SIan Rogers
294b0b2b09SIan Rogersifeq ($(DEBUG),0)
304b0b2b09SIan Rogers  ifeq ($(feature-fortify-source), 1)
314b0b2b09SIan Rogers    CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2
324b0b2b09SIan Rogers  endif
334b0b2b09SIan Rogersendif
3449b3cd30SArnaldo Carvalho de Melo
3522bd8f1bSJames Clarkifeq ($(DEBUG),1)
3622bd8f1bSJames Clark  CFLAGS += -O0
3749b3cd30SArnaldo Carvalho de Meloelse
38*eb9b9a6fSSam James  CFLAGS += -O3
3949b3cd30SArnaldo Carvalho de Meloendif
40fd01d06aSChris Phlipot
41fd01d06aSChris Phlipot# Treat warnings as errors unless directed not to
42fd01d06aSChris Phlipotifneq ($(WERROR),0)
43fd01d06aSChris Phlipot  CFLAGS += -Werror
44fd01d06aSChris Phlipotendif
45fd01d06aSChris Phlipot
464b6ab94eSJosh PoimboeufCFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
474b6ab94eSJosh Poimboeuf
484b6ab94eSJosh PoimboeufCFLAGS += -I$(srctree)/tools/include/
494b6ab94eSJosh Poimboeuf
50d894967fSJames ClarkCFLAGS += $(EXTRA_WARNINGS) $(EXTRA_CFLAGS)
51d894967fSJames Clark
524b6ab94eSJosh PoimboeufSUBCMD_IN := $(OUTPUT)libsubcmd-in.o
534b6ab94eSJosh Poimboeuf
54630ae80eSIan Rogersifeq ($(LP64), 1)
55630ae80eSIan Rogers  libdir_relative = lib64
56630ae80eSIan Rogerselse
57630ae80eSIan Rogers  libdir_relative = lib
58630ae80eSIan Rogersendif
59630ae80eSIan Rogers
60630ae80eSIan Rogersprefix ?=
61630ae80eSIan Rogerslibdir = $(prefix)/$(libdir_relative)
62630ae80eSIan Rogers
63630ae80eSIan Rogers# Shell quotes
64630ae80eSIan Rogerslibdir_SQ = $(subst ','\'',$(libdir))
65630ae80eSIan Rogers
664b6ab94eSJosh Poimboeufall:
674b6ab94eSJosh Poimboeuf
684b6ab94eSJosh Poimboeufexport srctree OUTPUT CC LD CFLAGS V
694b6ab94eSJosh Poimboeufinclude $(srctree)/tools/build/Makefile.include
704b6ab94eSJosh Poimboeuf
714b6ab94eSJosh Poimboeufall: fixdep $(LIBFILE)
724b6ab94eSJosh Poimboeuf
7396f30c8fSBrian Norris$(SUBCMD_IN): fixdep FORCE
744b6ab94eSJosh Poimboeuf	@$(MAKE) $(build)=libsubcmd
754b6ab94eSJosh Poimboeuf
764b6ab94eSJosh Poimboeuf$(LIBFILE): $(SUBCMD_IN)
774b6ab94eSJosh Poimboeuf	$(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(SUBCMD_IN)
784b6ab94eSJosh Poimboeuf
79630ae80eSIan Rogersdefine do_install_mkdir
80630ae80eSIan Rogers	if [ ! -d '$(DESTDIR_SQ)$1' ]; then             \
81630ae80eSIan Rogers		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \
82630ae80eSIan Rogers	fi
83630ae80eSIan Rogersendef
84630ae80eSIan Rogers
85630ae80eSIan Rogersdefine do_install
865d890591SIan Rogers	if [ ! -d '$2' ]; then             \
875d890591SIan Rogers		$(INSTALL) -d -m 755 '$2'; \
88630ae80eSIan Rogers	fi;                                             \
895d890591SIan Rogers	$(INSTALL) $1 $(if $3,-m $3,) '$2'
90630ae80eSIan Rogersendef
91630ae80eSIan Rogers
92630ae80eSIan Rogersinstall_lib: $(LIBFILE)
93630ae80eSIan Rogers	$(call QUIET_INSTALL, $(LIBFILE)) \
94630ae80eSIan Rogers		$(call do_install_mkdir,$(libdir_SQ)); \
95630ae80eSIan Rogers		cp -fpR $(LIBFILE) $(DESTDIR)$(libdir_SQ)
96630ae80eSIan Rogers
975d890591SIan RogersHDRS := exec-cmd.h help.h pager.h parse-options.h run-command.h
985d890591SIan RogersINSTALL_HDRS_PFX := $(DESTDIR)$(prefix)/include/subcmd
995d890591SIan RogersINSTALL_HDRS := $(addprefix $(INSTALL_HDRS_PFX)/, $(HDRS))
1005d890591SIan Rogers
1015d890591SIan Rogers$(INSTALL_HDRS): $(INSTALL_HDRS_PFX)/%.h: %.h
1025d890591SIan Rogers	$(call QUIET_INSTALL, $@) \
1035d890591SIan Rogers		$(call do_install,$<,$(INSTALL_HDRS_PFX)/,644)
1045d890591SIan Rogers
1055d890591SIan Rogersinstall_headers: $(INSTALL_HDRS)
1065d890591SIan Rogers	$(call QUIET_INSTALL, libsubcmd_headers)
107630ae80eSIan Rogers
108630ae80eSIan Rogersinstall: install_lib install_headers
109630ae80eSIan Rogers
1104b6ab94eSJosh Poimboeufclean:
1114b6ab94eSJosh Poimboeuf	$(call QUIET_CLEAN, libsubcmd) $(RM) $(LIBFILE); \
1125c816641SMasahiro Yamada	find $(or $(OUTPUT),.) -name \*.o -or -name \*.o.cmd -or -name \*.o.d | xargs $(RM)
1134b6ab94eSJosh Poimboeuf
1144b6ab94eSJosh PoimboeufFORCE:
1154b6ab94eSJosh Poimboeuf
1164b6ab94eSJosh Poimboeuf.PHONY: clean FORCE
117