Skip to content

Commit 5c81664

Browse files
committed
kbuild: replace $(if A,A,B) with $(or A,B)
$(or ...) is available since GNU Make 3.81, and useful to shorten the code in some places. Covert as follows: $(if A,A,B) --> $(or A,B) This patch also converts: $(if A, A, B) --> $(or A, B) Strictly speaking, the latter is not an equivalent conversion because GNU Make keeps spaces after commas; if A is not empty, $(if A, A, B) expands to " A", while $(or A, B) expands to "A". Anyway, preceding spaces are not significant in the code hunks I touched. Signed-off-by: Masahiro Yamada <[email protected]> Reviewed-by: Nicolas Schier <[email protected]>
1 parent f67695c commit 5c81664

File tree

22 files changed

+30
-31
lines changed

22 files changed

+30
-31
lines changed

Makefile

+4-4
Original file line numberDiff line numberDiff line change
@@ -1240,8 +1240,8 @@ define filechk_version.h
12401240
echo \#define LINUX_VERSION_SUBLEVEL $(SUBLEVEL)
12411241
endef
12421242

1243-
$(version_h): PATCHLEVEL := $(if $(PATCHLEVEL), $(PATCHLEVEL), 0)
1244-
$(version_h): SUBLEVEL := $(if $(SUBLEVEL), $(SUBLEVEL), 0)
1243+
$(version_h): PATCHLEVEL := $(or $(PATCHLEVEL), 0)
1244+
$(version_h): SUBLEVEL := $(or $(SUBLEVEL), 0)
12451245
$(version_h): FORCE
12461246
$(call filechk,version.h)
12471247

@@ -1624,7 +1624,7 @@ help:
16241624
@$(MAKE) -f $(srctree)/Documentation/Makefile dochelp
16251625
@echo ''
16261626
@echo 'Architecture specific targets ($(SRCARCH)):'
1627-
@$(if $(archhelp),$(archhelp),\
1627+
@$(or $(archhelp),\
16281628
echo ' No architecture specific help defined for $(SRCARCH)')
16291629
@echo ''
16301630
@$(if $(boards), \
@@ -1841,7 +1841,7 @@ $(clean-dirs):
18411841

18421842
clean: $(clean-dirs)
18431843
$(call cmd,rmfiles)
1844-
@find $(if $(KBUILD_EXTMOD), $(KBUILD_EXTMOD), .) $(RCS_FIND_IGNORE) \
1844+
@find $(or $(KBUILD_EXTMOD), .) $(RCS_FIND_IGNORE) \
18451845
\( -name '*.[aios]' -o -name '*.ko' -o -name '.*.cmd' \
18461846
-o -name '*.ko.*' \
18471847
-o -name '*.dtb' -o -name '*.dtbo' -o -name '*.dtb.S' -o -name '*.dt.yaml' \

scripts/Makefile.build

+1-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ include $(srctree)/scripts/Makefile.compiler
4040

4141
# The filename Kbuild has precedence over Makefile
4242
kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
43-
kbuild-file := $(if $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Kbuild,$(kbuild-dir)/Makefile)
44-
include $(kbuild-file)
43+
include $(or $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Makefile)
4544

4645
include $(srctree)/scripts/Makefile.lib
4746

scripts/Makefile.clean

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ include $(srctree)/scripts/Kbuild.include
1212

1313
# The filename Kbuild has precedence over Makefile
1414
kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
15-
include $(if $(wildcard $(kbuild-dir)/Kbuild), $(kbuild-dir)/Kbuild, $(kbuild-dir)/Makefile)
15+
include $(or $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Makefile)
1616

1717
# Figure out what we need to build from the various variables
1818
# ==========================================================================

scripts/Makefile.lib

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ subdir-ym := $(addprefix $(obj)/,$(subdir-ym))
111111
modname-multi = $(sort $(foreach m,$(multi-obj-ym),\
112112
$(if $(filter $*.o, $(call suffix-search, $m, .o, -objs -y -m)),$(m:.o=))))
113113

114-
__modname = $(if $(modname-multi),$(modname-multi),$(basetarget))
114+
__modname = $(or $(modname-multi),$(basetarget))
115115

116116
modname = $(subst $(space),:,$(__modname))
117117
modfile = $(addprefix $(obj)/,$(__modname))
@@ -434,7 +434,7 @@ MKIMAGE := $(srctree)/scripts/mkuboot.sh
434434
# SRCARCH just happens to match slightly more than ARCH (on sparc), so reduces
435435
# the number of overrides in arch makefiles
436436
UIMAGE_ARCH ?= $(SRCARCH)
437-
UIMAGE_COMPRESSION ?= $(if $(2),$(2),none)
437+
UIMAGE_COMPRESSION ?= $(or $(2),none)
438438
UIMAGE_OPTS-y ?=
439439
UIMAGE_TYPE ?= kernel
440440
UIMAGE_LOADADDR ?= arch_must_set_this

tools/bpf/bpftool/Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ CFLAGS += -O2
7878
CFLAGS += -W -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers
7979
CFLAGS += $(filter-out -Wswitch-enum -Wnested-externs,$(EXTRA_WARNINGS))
8080
CFLAGS += -DPACKAGE='"bpftool"' -D__EXPORTED_HEADERS__ \
81-
-I$(if $(OUTPUT),$(OUTPUT),.) \
81+
-I$(or $(OUTPUT),.) \
8282
-I$(LIBBPF_INCLUDE) \
8383
-I$(srctree)/kernel/bpf/ \
8484
-I$(srctree)/tools/include \
@@ -186,7 +186,7 @@ endif
186186

187187
$(OUTPUT)%.bpf.o: skeleton/%.bpf.c $(OUTPUT)vmlinux.h $(LIBBPF_BOOTSTRAP)
188188
$(QUIET_CLANG)$(CLANG) \
189-
-I$(if $(OUTPUT),$(OUTPUT),.) \
189+
-I$(or $(OUTPUT),.) \
190190
-I$(srctree)/tools/include/uapi/ \
191191
-I$(LIBBPF_BOOTSTRAP_INCLUDE) \
192192
-g -O2 -Wall -target bpf -c $< -o $@

tools/build/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ TMP_O := $(if $(OUTPUT),$(OUTPUT)feature/,./)
3636

3737
clean:
3838
$(call QUIET_CLEAN, fixdep)
39-
$(Q)find $(if $(OUTPUT),$(OUTPUT),.) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
39+
$(Q)find $(or $(OUTPUT),.) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
4040
$(Q)rm -f $(OUTPUT)fixdep
4141
$(call QUIET_CLEAN, feature-detect)
4242
ifneq ($(wildcard $(TMP_O)),)

tools/counter/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ $(OUTPUT)counter_example: $(COUNTER_EXAMPLE)
4040
clean:
4141
rm -f $(ALL_PROGRAMS)
4242
rm -rf $(OUTPUT)include/linux/counter.h
43-
find $(if $(OUTPUT),$(OUTPUT),.) -name '*.o' -delete -o -name '\.*.d' -delete
43+
find $(or $(OUTPUT),.) -name '*.o' -delete -o -name '\.*.d' -delete
4444

4545
install: $(ALL_PROGRAMS)
4646
install -d -m 755 $(DESTDIR)$(bindir); \

tools/gpio/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ $(OUTPUT)gpio-watch: $(GPIO_WATCH_IN)
7878
clean:
7979
rm -f $(ALL_PROGRAMS)
8080
rm -f $(OUTPUT)include/linux/gpio.h
81-
find $(if $(OUTPUT),$(OUTPUT),.) -name '*.o' -delete -o -name '\.*.d' -delete
81+
find $(or $(OUTPUT),.) -name '*.o' -delete -o -name '\.*.d' -delete
8282

8383
install: $(ALL_PROGRAMS)
8484
install -d -m 755 $(DESTDIR)$(bindir); \

tools/hv/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ $(OUTPUT)hv_fcopy_daemon: $(HV_FCOPY_DAEMON_IN)
4747

4848
clean:
4949
rm -f $(ALL_PROGRAMS)
50-
find $(if $(OUTPUT),$(OUTPUT),.) -name '*.o' -delete -o -name '\.*.d' -delete
50+
find $(or $(OUTPUT),.) -name '*.o' -delete -o -name '\.*.d' -delete
5151

5252
install: $(ALL_PROGRAMS)
5353
install -d -m 755 $(DESTDIR)$(sbindir); \

tools/iio/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ $(OUTPUT)iio_generic_buffer: $(IIO_GENERIC_BUFFER_IN)
5858
clean:
5959
rm -f $(ALL_PROGRAMS)
6060
rm -rf $(OUTPUT)include/linux/iio
61-
find $(if $(OUTPUT),$(OUTPUT),.) -name '*.o' -delete -o -name '\.*.d' -delete
61+
find $(or $(OUTPUT),.) -name '*.o' -delete -o -name '\.*.d' -delete
6262

6363
install: $(ALL_PROGRAMS)
6464
install -d -m 755 $(DESTDIR)$(bindir); \

tools/lib/api/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ $(LIBFILE): $(API_IN)
6060

6161
clean:
6262
$(call QUIET_CLEAN, libapi) $(RM) $(LIBFILE); \
63-
find $(if $(OUTPUT),$(OUTPUT),.) -name \*.o -or -name \*.o.cmd -or -name \*.o.d | xargs $(RM)
63+
find $(or $(OUTPUT),.) -name \*.o -or -name \*.o.cmd -or -name \*.o.d | xargs $(RM)
6464

6565
FORCE:
6666

tools/lib/bpf/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ ifndef VERBOSE
6060
VERBOSE = 0
6161
endif
6262

63-
INCLUDES = -I$(if $(OUTPUT),$(OUTPUT),.) \
63+
INCLUDES = -I$(or $(OUTPUT),.) \
6464
-I$(srctree)/tools/include -I$(srctree)/tools/include/uapi
6565

6666
export prefix libdir src obj

tools/lib/perf/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ $(TESTS_STATIC): $(TESTS_IN) $(LIBPERF_A) $(LIBAPI)
153153
$(QUIET_LINK)$(CC) -o $@ $^
154154

155155
$(TESTS_SHARED): $(TESTS_IN) $(LIBAPI)
156-
$(QUIET_LINK)$(CC) -o $@ -L$(if $(OUTPUT),$(OUTPUT),.) $^ -lperf
156+
$(QUIET_LINK)$(CC) -o $@ -L$(or $(OUTPUT),.) $^ -lperf
157157

158158
make-tests: libs $(TESTS_SHARED) $(TESTS_STATIC)
159159

tools/lib/subcmd/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ $(LIBFILE): $(SUBCMD_IN)
6363

6464
clean:
6565
$(call QUIET_CLEAN, libsubcmd) $(RM) $(LIBFILE); \
66-
find $(if $(OUTPUT),$(OUTPUT),.) -name \*.o -or -name \*.o.cmd -or -name \*.o.d | xargs $(RM)
66+
find $(or $(OUTPUT),.) -name \*.o -or -name \*.o.cmd -or -name \*.o.d | xargs $(RM)
6767

6868
FORCE:
6969

tools/objtool/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ srctree := $(patsubst %/,%,$(dir $(srctree)))
1313
endif
1414

1515
SUBCMD_SRCDIR = $(srctree)/tools/lib/subcmd/
16-
LIBSUBCMD_OUTPUT = $(if $(OUTPUT),$(OUTPUT),$(CURDIR)/)
16+
LIBSUBCMD_OUTPUT = $(or $(OUTPUT),$(CURDIR)/)
1717
LIBSUBCMD = $(LIBSUBCMD_OUTPUT)libsubcmd.a
1818

1919
OBJTOOL := $(OUTPUT)objtool

tools/pci/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ $(OUTPUT)pcitest: $(PCITEST_IN)
4242
clean:
4343
rm -f $(ALL_PROGRAMS)
4444
rm -rf $(OUTPUT)include/
45-
find $(if $(OUTPUT),$(OUTPUT),.) -name '*.o' -delete -o -name '\.*.d' -delete
45+
find $(or $(OUTPUT),.) -name '*.o' -delete -o -name '\.*.d' -delete
4646

4747
install: $(ALL_PROGRAMS)
4848
install -d -m 755 $(DESTDIR)$(bindir); \

tools/perf/Makefile.perf

+2-2
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ endif
724724
# get relative building directory (to $(OUTPUT))
725725
# and '.' if it's $(OUTPUT) itself
726726
__build-dir = $(subst $(OUTPUT),,$(dir $@))
727-
build-dir = $(if $(__build-dir),$(__build-dir),.)
727+
build-dir = $(or $(__build-dir),.)
728728

729729
prepare: $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)common-cmds.h archheaders $(drm_ioctl_array) \
730730
$(fadvise_advice_array) \
@@ -1090,7 +1090,7 @@ bpf-skel-clean:
10901090

10911091
clean:: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean $(LIBSUBCMD)-clean $(LIBPERF)-clean fixdep-clean python-clean bpf-skel-clean
10921092
$(call QUIET_CLEAN, core-objs) $(RM) $(LIBPERF_A) $(OUTPUT)perf-archive $(OUTPUT)perf-with-kcore $(OUTPUT)perf-iostat $(LANG_BINDINGS)
1093-
$(Q)find $(if $(OUTPUT),$(OUTPUT),.) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
1093+
$(Q)find $(or $(OUTPUT),.) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
10941094
$(Q)$(RM) $(OUTPUT).config-detected
10951095
$(call QUIET_CLEAN, core-progs) $(RM) $(ALL_PROGRAMS) perf perf-read-vdso32 perf-read-vdsox32 $(OUTPUT)pmu-events/jevents $(OUTPUT)$(LIBJVMTI).so
10961096
$(call QUIET_CLEAN, core-gen) $(RM) *.spec *.pyc *.pyo */*.pyc */*.pyo $(OUTPUT)common-cmds.h TAGS tags cscope* $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)FEATURE-DUMP $(OUTPUT)util/*-bison* $(OUTPUT)util/*-flex* \

tools/power/x86/intel-speed-select/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ $(OUTPUT)intel-speed-select: $(ISST_IN)
4343
clean:
4444
rm -f $(ALL_PROGRAMS)
4545
rm -rf $(OUTPUT)include/linux/isst_if.h
46-
find $(if $(OUTPUT),$(OUTPUT),.) -name '*.o' -delete -o -name '\.*.d' -delete
46+
find $(or $(OUTPUT),.) -name '*.o' -delete -o -name '\.*.d' -delete
4747

4848
install: $(ALL_PROGRAMS)
4949
install -d -m 755 $(DESTDIR)$(bindir); \

tools/scripts/utilities.mak

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,5 +175,5 @@ _ge-abspath = $(if $(is-executable),$(1))
175175
define get-executable-or-default
176176
$(if $($(1)),$(call _ge_attempt,$($(1)),$(1)),$(call _ge_attempt,$(2)))
177177
endef
178-
_ge_attempt = $(if $(get-executable),$(get-executable),$(call _gea_err,$(2)))
178+
_ge_attempt = $(or $(get-executable),$(call _gea_err,$(2)))
179179
_gea_err = $(if $(1),$(error Please set '$(1)' appropriately))

tools/spi/Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ $(OUTPUT)spidev_fdx: $(SPIDEV_FDX_IN)
5353
clean:
5454
rm -f $(ALL_PROGRAMS)
5555
rm -rf $(OUTPUT)include/
56-
find $(if $(OUTPUT),$(OUTPUT),.) -name '*.o' -delete
57-
find $(if $(OUTPUT),$(OUTPUT),.) -name '\.*.o.d' -delete
58-
find $(if $(OUTPUT),$(OUTPUT),.) -name '\.*.o.cmd' -delete
56+
find $(or $(OUTPUT),.) -name '*.o' -delete
57+
find $(or $(OUTPUT),.) -name '\.*.o.d' -delete
58+
find $(or $(OUTPUT),.) -name '\.*.o.cmd' -delete
5959

6060
install: $(ALL_PROGRAMS)
6161
install -d -m 755 $(DESTDIR)$(bindir); \

tools/tracing/rtla/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ DATADIR := /usr/share
4646
DOCDIR := $(DATADIR)/doc
4747
MANDIR := $(DATADIR)/man
4848
LICDIR := $(DATADIR)/licenses
49-
SRCTREE := $(if $(BUILD_SRC),$(BUILD_SRC),$(CURDIR))
49+
SRCTREE := $(or $(BUILD_SRC),$(CURDIR))
5050

5151
# If running from the tarball, man pages are stored in the Documentation
5252
# dir. If running from the kernel source, man pages are stored in

tools/usb/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ $(OUTPUT)ffs-test: $(FFS_TEST_IN)
3838

3939
clean:
4040
rm -f $(ALL_PROGRAMS)
41-
find $(if $(OUTPUT),$(OUTPUT),.) -name '*.o' -delete -o -name '\.*.d' -delete -o -name '\.*.o.cmd' -delete
41+
find $(or $(OUTPUT),.) -name '*.o' -delete -o -name '\.*.d' -delete -o -name '\.*.o.cmd' -delete
4242

4343
install: $(ALL_PROGRAMS)
4444
install -d -m 755 $(DESTDIR)$(bindir); \

0 commit comments

Comments
 (0)