xref: /linux-6.15/tools/lib/subcmd/Makefile (revision 630ae80e)
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
12c1d45c3aSJosh PoimboeufCC ?= $(CROSS_COMPILE)gcc
13c1d45c3aSJosh PoimboeufLD ?= $(CROSS_COMPILE)ld
14c1d45c3aSJosh PoimboeufAR ?= $(CROSS_COMPILE)ar
15c1d45c3aSJosh Poimboeuf
164b6ab94eSJosh PoimboeufRM = rm -f
174b6ab94eSJosh Poimboeuf
184b6ab94eSJosh PoimboeufMAKEFLAGS += --no-print-directory
194b6ab94eSJosh Poimboeuf
20*630ae80eSIan RogersINSTALL = install
21*630ae80eSIan Rogers
22*630ae80eSIan Rogers# Use DESTDIR for installing into a different root directory.
23*630ae80eSIan Rogers# This is useful for building a package. The program will be
24*630ae80eSIan Rogers# installed in this directory as if it was the root directory.
25*630ae80eSIan Rogers# Then the build tool can move it later.
26*630ae80eSIan RogersDESTDIR ?=
27*630ae80eSIan RogersDESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
28*630ae80eSIan Rogers
294b6ab94eSJosh PoimboeufLIBFILE = $(OUTPUT)libsubcmd.a
304b6ab94eSJosh Poimboeuf
31d894967fSJames ClarkCFLAGS := -ggdb3 -Wall -Wextra -std=gnu99 -fPIC
324b0b2b09SIan Rogers
334b0b2b09SIan Rogersifeq ($(DEBUG),0)
344b0b2b09SIan Rogers  ifeq ($(feature-fortify-source), 1)
354b0b2b09SIan Rogers    CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2
364b0b2b09SIan Rogers  endif
374b0b2b09SIan Rogersendif
3849b3cd30SArnaldo Carvalho de Melo
3922bd8f1bSJames Clarkifeq ($(DEBUG),1)
4022bd8f1bSJames Clark  CFLAGS += -O0
4122bd8f1bSJames Clarkelse ifeq ($(CC_NO_CLANG), 0)
4249b3cd30SArnaldo Carvalho de Melo  CFLAGS += -O3
4349b3cd30SArnaldo Carvalho de Meloelse
4449b3cd30SArnaldo Carvalho de Melo  CFLAGS += -O6
4549b3cd30SArnaldo Carvalho de Meloendif
46fd01d06aSChris Phlipot
47fd01d06aSChris Phlipot# Treat warnings as errors unless directed not to
48fd01d06aSChris Phlipotifneq ($(WERROR),0)
49fd01d06aSChris Phlipot  CFLAGS += -Werror
50fd01d06aSChris Phlipotendif
51fd01d06aSChris Phlipot
524b6ab94eSJosh PoimboeufCFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
534b6ab94eSJosh Poimboeuf
544b6ab94eSJosh PoimboeufCFLAGS += -I$(srctree)/tools/include/
554b6ab94eSJosh Poimboeuf
56d894967fSJames ClarkCFLAGS += $(EXTRA_WARNINGS) $(EXTRA_CFLAGS)
57d894967fSJames Clark
584b6ab94eSJosh PoimboeufSUBCMD_IN := $(OUTPUT)libsubcmd-in.o
594b6ab94eSJosh Poimboeuf
60*630ae80eSIan Rogersifeq ($(LP64), 1)
61*630ae80eSIan Rogers  libdir_relative = lib64
62*630ae80eSIan Rogerselse
63*630ae80eSIan Rogers  libdir_relative = lib
64*630ae80eSIan Rogersendif
65*630ae80eSIan Rogers
66*630ae80eSIan Rogersprefix ?=
67*630ae80eSIan Rogerslibdir = $(prefix)/$(libdir_relative)
68*630ae80eSIan Rogers
69*630ae80eSIan Rogers# Shell quotes
70*630ae80eSIan Rogerslibdir_SQ = $(subst ','\'',$(libdir))
71*630ae80eSIan Rogers
724b6ab94eSJosh Poimboeufall:
734b6ab94eSJosh Poimboeuf
744b6ab94eSJosh Poimboeufexport srctree OUTPUT CC LD CFLAGS V
754b6ab94eSJosh Poimboeufinclude $(srctree)/tools/build/Makefile.include
764b6ab94eSJosh Poimboeuf
774b6ab94eSJosh Poimboeufall: fixdep $(LIBFILE)
784b6ab94eSJosh Poimboeuf
794b6ab94eSJosh Poimboeuf$(SUBCMD_IN): FORCE
804b6ab94eSJosh Poimboeuf	@$(MAKE) $(build)=libsubcmd
814b6ab94eSJosh Poimboeuf
824b6ab94eSJosh Poimboeuf$(LIBFILE): $(SUBCMD_IN)
834b6ab94eSJosh Poimboeuf	$(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(SUBCMD_IN)
844b6ab94eSJosh Poimboeuf
85*630ae80eSIan Rogersdefine do_install_mkdir
86*630ae80eSIan Rogers	if [ ! -d '$(DESTDIR_SQ)$1' ]; then             \
87*630ae80eSIan Rogers		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \
88*630ae80eSIan Rogers	fi
89*630ae80eSIan Rogersendef
90*630ae80eSIan Rogers
91*630ae80eSIan Rogersdefine do_install
92*630ae80eSIan Rogers	if [ ! -d '$(DESTDIR_SQ)$2' ]; then             \
93*630ae80eSIan Rogers		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
94*630ae80eSIan Rogers	fi;                                             \
95*630ae80eSIan Rogers	$(INSTALL) $1 $(if $3,-m $3,) '$(DESTDIR_SQ)$2'
96*630ae80eSIan Rogersendef
97*630ae80eSIan Rogers
98*630ae80eSIan Rogersinstall_lib: $(LIBFILE)
99*630ae80eSIan Rogers	$(call QUIET_INSTALL, $(LIBFILE)) \
100*630ae80eSIan Rogers		$(call do_install_mkdir,$(libdir_SQ)); \
101*630ae80eSIan Rogers		cp -fpR $(LIBFILE) $(DESTDIR)$(libdir_SQ)
102*630ae80eSIan Rogers
103*630ae80eSIan Rogersinstall_headers:
104*630ae80eSIan Rogers	$(call QUIET_INSTALL, headers) \
105*630ae80eSIan Rogers		$(call do_install,exec-cmd.h,$(prefix)/include/subcmd,644); \
106*630ae80eSIan Rogers		$(call do_install,help.h,$(prefix)/include/subcmd,644); \
107*630ae80eSIan Rogers		$(call do_install,pager.h,$(prefix)/include/subcmd,644); \
108*630ae80eSIan Rogers		$(call do_install,parse-options.h,$(prefix)/include/subcmd,644); \
109*630ae80eSIan Rogers		$(call do_install,run-command.h,$(prefix)/include/subcmd,644);
110*630ae80eSIan Rogers
111*630ae80eSIan Rogersinstall: install_lib install_headers
112*630ae80eSIan Rogers
1134b6ab94eSJosh Poimboeufclean:
1144b6ab94eSJosh Poimboeuf	$(call QUIET_CLEAN, libsubcmd) $(RM) $(LIBFILE); \
1155c816641SMasahiro Yamada	find $(or $(OUTPUT),.) -name \*.o -or -name \*.o.cmd -or -name \*.o.d | xargs $(RM)
1164b6ab94eSJosh Poimboeuf
1174b6ab94eSJosh PoimboeufFORCE:
1184b6ab94eSJosh Poimboeuf
1194b6ab94eSJosh Poimboeuf.PHONY: clean FORCE
120