Skip to content

Commit

Permalink
kbuild: replace $(if A,A,B) with $(or A,B)
Browse files Browse the repository at this point in the history
$(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]>
  • Loading branch information
masahir0y committed Feb 15, 2022
1 parent f67695c commit 5c81664
Show file tree
Hide file tree
Showing 22 changed files with 30 additions and 31 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1240,8 +1240,8 @@ define filechk_version.h
echo \#define LINUX_VERSION_SUBLEVEL $(SUBLEVEL)
endef

$(version_h): PATCHLEVEL := $(if $(PATCHLEVEL), $(PATCHLEVEL), 0)
$(version_h): SUBLEVEL := $(if $(SUBLEVEL), $(SUBLEVEL), 0)
$(version_h): PATCHLEVEL := $(or $(PATCHLEVEL), 0)
$(version_h): SUBLEVEL := $(or $(SUBLEVEL), 0)
$(version_h): FORCE
$(call filechk,version.h)

Expand Down Expand Up @@ -1624,7 +1624,7 @@ help:
@$(MAKE) -f $(srctree)/Documentation/Makefile dochelp
@echo ''
@echo 'Architecture specific targets ($(SRCARCH)):'
@$(if $(archhelp),$(archhelp),\
@$(or $(archhelp),\
echo ' No architecture specific help defined for $(SRCARCH)')
@echo ''
@$(if $(boards), \
Expand Down Expand Up @@ -1841,7 +1841,7 @@ $(clean-dirs):

clean: $(clean-dirs)
$(call cmd,rmfiles)
@find $(if $(KBUILD_EXTMOD), $(KBUILD_EXTMOD), .) $(RCS_FIND_IGNORE) \
@find $(or $(KBUILD_EXTMOD), .) $(RCS_FIND_IGNORE) \
\( -name '*.[aios]' -o -name '*.ko' -o -name '.*.cmd' \
-o -name '*.ko.*' \
-o -name '*.dtb' -o -name '*.dtbo' -o -name '*.dtb.S' -o -name '*.dt.yaml' \
Expand Down
3 changes: 1 addition & 2 deletions scripts/Makefile.build
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ include $(srctree)/scripts/Makefile.compiler

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

include $(srctree)/scripts/Makefile.lib

Expand Down
2 changes: 1 addition & 1 deletion scripts/Makefile.clean
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ include $(srctree)/scripts/Kbuild.include

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

# Figure out what we need to build from the various variables
# ==========================================================================
Expand Down
4 changes: 2 additions & 2 deletions scripts/Makefile.lib
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ subdir-ym := $(addprefix $(obj)/,$(subdir-ym))
modname-multi = $(sort $(foreach m,$(multi-obj-ym),\
$(if $(filter $*.o, $(call suffix-search, $m, .o, -objs -y -m)),$(m:.o=))))

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

modname = $(subst $(space),:,$(__modname))
modfile = $(addprefix $(obj)/,$(__modname))
Expand Down Expand Up @@ -434,7 +434,7 @@ MKIMAGE := $(srctree)/scripts/mkuboot.sh
# SRCARCH just happens to match slightly more than ARCH (on sparc), so reduces
# the number of overrides in arch makefiles
UIMAGE_ARCH ?= $(SRCARCH)
UIMAGE_COMPRESSION ?= $(if $(2),$(2),none)
UIMAGE_COMPRESSION ?= $(or $(2),none)
UIMAGE_OPTS-y ?=
UIMAGE_TYPE ?= kernel
UIMAGE_LOADADDR ?= arch_must_set_this
Expand Down
4 changes: 2 additions & 2 deletions tools/bpf/bpftool/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ CFLAGS += -O2
CFLAGS += -W -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers
CFLAGS += $(filter-out -Wswitch-enum -Wnested-externs,$(EXTRA_WARNINGS))
CFLAGS += -DPACKAGE='"bpftool"' -D__EXPORTED_HEADERS__ \
-I$(if $(OUTPUT),$(OUTPUT),.) \
-I$(or $(OUTPUT),.) \
-I$(LIBBPF_INCLUDE) \
-I$(srctree)/kernel/bpf/ \
-I$(srctree)/tools/include \
Expand Down Expand Up @@ -186,7 +186,7 @@ endif

$(OUTPUT)%.bpf.o: skeleton/%.bpf.c $(OUTPUT)vmlinux.h $(LIBBPF_BOOTSTRAP)
$(QUIET_CLANG)$(CLANG) \
-I$(if $(OUTPUT),$(OUTPUT),.) \
-I$(or $(OUTPUT),.) \
-I$(srctree)/tools/include/uapi/ \
-I$(LIBBPF_BOOTSTRAP_INCLUDE) \
-g -O2 -Wall -target bpf -c $< -o $@
Expand Down
2 changes: 1 addition & 1 deletion tools/build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ TMP_O := $(if $(OUTPUT),$(OUTPUT)feature/,./)

clean:
$(call QUIET_CLEAN, fixdep)
$(Q)find $(if $(OUTPUT),$(OUTPUT),.) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
$(Q)find $(or $(OUTPUT),.) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
$(Q)rm -f $(OUTPUT)fixdep
$(call QUIET_CLEAN, feature-detect)
ifneq ($(wildcard $(TMP_O)),)
Expand Down
2 changes: 1 addition & 1 deletion tools/counter/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ $(OUTPUT)counter_example: $(COUNTER_EXAMPLE)
clean:
rm -f $(ALL_PROGRAMS)
rm -rf $(OUTPUT)include/linux/counter.h
find $(if $(OUTPUT),$(OUTPUT),.) -name '*.o' -delete -o -name '\.*.d' -delete
find $(or $(OUTPUT),.) -name '*.o' -delete -o -name '\.*.d' -delete

install: $(ALL_PROGRAMS)
install -d -m 755 $(DESTDIR)$(bindir); \
Expand Down
2 changes: 1 addition & 1 deletion tools/gpio/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ $(OUTPUT)gpio-watch: $(GPIO_WATCH_IN)
clean:
rm -f $(ALL_PROGRAMS)
rm -f $(OUTPUT)include/linux/gpio.h
find $(if $(OUTPUT),$(OUTPUT),.) -name '*.o' -delete -o -name '\.*.d' -delete
find $(or $(OUTPUT),.) -name '*.o' -delete -o -name '\.*.d' -delete

install: $(ALL_PROGRAMS)
install -d -m 755 $(DESTDIR)$(bindir); \
Expand Down
2 changes: 1 addition & 1 deletion tools/hv/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ $(OUTPUT)hv_fcopy_daemon: $(HV_FCOPY_DAEMON_IN)

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

install: $(ALL_PROGRAMS)
install -d -m 755 $(DESTDIR)$(sbindir); \
Expand Down
2 changes: 1 addition & 1 deletion tools/iio/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ $(OUTPUT)iio_generic_buffer: $(IIO_GENERIC_BUFFER_IN)
clean:
rm -f $(ALL_PROGRAMS)
rm -rf $(OUTPUT)include/linux/iio
find $(if $(OUTPUT),$(OUTPUT),.) -name '*.o' -delete -o -name '\.*.d' -delete
find $(or $(OUTPUT),.) -name '*.o' -delete -o -name '\.*.d' -delete

install: $(ALL_PROGRAMS)
install -d -m 755 $(DESTDIR)$(bindir); \
Expand Down
2 changes: 1 addition & 1 deletion tools/lib/api/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ $(LIBFILE): $(API_IN)

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

FORCE:

Expand Down
2 changes: 1 addition & 1 deletion tools/lib/bpf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ ifndef VERBOSE
VERBOSE = 0
endif

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

export prefix libdir src obj
Expand Down
2 changes: 1 addition & 1 deletion tools/lib/perf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ $(TESTS_STATIC): $(TESTS_IN) $(LIBPERF_A) $(LIBAPI)
$(QUIET_LINK)$(CC) -o $@ $^

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

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

Expand Down
2 changes: 1 addition & 1 deletion tools/lib/subcmd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ $(LIBFILE): $(SUBCMD_IN)

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

FORCE:

Expand Down
2 changes: 1 addition & 1 deletion tools/objtool/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ srctree := $(patsubst %/,%,$(dir $(srctree)))
endif

SUBCMD_SRCDIR = $(srctree)/tools/lib/subcmd/
LIBSUBCMD_OUTPUT = $(if $(OUTPUT),$(OUTPUT),$(CURDIR)/)
LIBSUBCMD_OUTPUT = $(or $(OUTPUT),$(CURDIR)/)
LIBSUBCMD = $(LIBSUBCMD_OUTPUT)libsubcmd.a

OBJTOOL := $(OUTPUT)objtool
Expand Down
2 changes: 1 addition & 1 deletion tools/pci/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ $(OUTPUT)pcitest: $(PCITEST_IN)
clean:
rm -f $(ALL_PROGRAMS)
rm -rf $(OUTPUT)include/
find $(if $(OUTPUT),$(OUTPUT),.) -name '*.o' -delete -o -name '\.*.d' -delete
find $(or $(OUTPUT),.) -name '*.o' -delete -o -name '\.*.d' -delete

install: $(ALL_PROGRAMS)
install -d -m 755 $(DESTDIR)$(bindir); \
Expand Down
4 changes: 2 additions & 2 deletions tools/perf/Makefile.perf
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ endif
# get relative building directory (to $(OUTPUT))
# and '.' if it's $(OUTPUT) itself
__build-dir = $(subst $(OUTPUT),,$(dir $@))
build-dir = $(if $(__build-dir),$(__build-dir),.)
build-dir = $(or $(__build-dir),.)

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

clean:: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean $(LIBSUBCMD)-clean $(LIBPERF)-clean fixdep-clean python-clean bpf-skel-clean
$(call QUIET_CLEAN, core-objs) $(RM) $(LIBPERF_A) $(OUTPUT)perf-archive $(OUTPUT)perf-with-kcore $(OUTPUT)perf-iostat $(LANG_BINDINGS)
$(Q)find $(if $(OUTPUT),$(OUTPUT),.) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
$(Q)find $(or $(OUTPUT),.) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
$(Q)$(RM) $(OUTPUT).config-detected
$(call QUIET_CLEAN, core-progs) $(RM) $(ALL_PROGRAMS) perf perf-read-vdso32 perf-read-vdsox32 $(OUTPUT)pmu-events/jevents $(OUTPUT)$(LIBJVMTI).so
$(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* \
Expand Down
2 changes: 1 addition & 1 deletion tools/power/x86/intel-speed-select/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ $(OUTPUT)intel-speed-select: $(ISST_IN)
clean:
rm -f $(ALL_PROGRAMS)
rm -rf $(OUTPUT)include/linux/isst_if.h
find $(if $(OUTPUT),$(OUTPUT),.) -name '*.o' -delete -o -name '\.*.d' -delete
find $(or $(OUTPUT),.) -name '*.o' -delete -o -name '\.*.d' -delete

install: $(ALL_PROGRAMS)
install -d -m 755 $(DESTDIR)$(bindir); \
Expand Down
2 changes: 1 addition & 1 deletion tools/scripts/utilities.mak
Original file line number Diff line number Diff line change
Expand Up @@ -175,5 +175,5 @@ _ge-abspath = $(if $(is-executable),$(1))
define get-executable-or-default
$(if $($(1)),$(call _ge_attempt,$($(1)),$(1)),$(call _ge_attempt,$(2)))
endef
_ge_attempt = $(if $(get-executable),$(get-executable),$(call _gea_err,$(2)))
_ge_attempt = $(or $(get-executable),$(call _gea_err,$(2)))
_gea_err = $(if $(1),$(error Please set '$(1)' appropriately))
6 changes: 3 additions & 3 deletions tools/spi/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ $(OUTPUT)spidev_fdx: $(SPIDEV_FDX_IN)
clean:
rm -f $(ALL_PROGRAMS)
rm -rf $(OUTPUT)include/
find $(if $(OUTPUT),$(OUTPUT),.) -name '*.o' -delete
find $(if $(OUTPUT),$(OUTPUT),.) -name '\.*.o.d' -delete
find $(if $(OUTPUT),$(OUTPUT),.) -name '\.*.o.cmd' -delete
find $(or $(OUTPUT),.) -name '*.o' -delete
find $(or $(OUTPUT),.) -name '\.*.o.d' -delete
find $(or $(OUTPUT),.) -name '\.*.o.cmd' -delete

install: $(ALL_PROGRAMS)
install -d -m 755 $(DESTDIR)$(bindir); \
Expand Down
2 changes: 1 addition & 1 deletion tools/tracing/rtla/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ DATADIR := /usr/share
DOCDIR := $(DATADIR)/doc
MANDIR := $(DATADIR)/man
LICDIR := $(DATADIR)/licenses
SRCTREE := $(if $(BUILD_SRC),$(BUILD_SRC),$(CURDIR))
SRCTREE := $(or $(BUILD_SRC),$(CURDIR))

# If running from the tarball, man pages are stored in the Documentation
# dir. If running from the kernel source, man pages are stored in
Expand Down
2 changes: 1 addition & 1 deletion tools/usb/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ $(OUTPUT)ffs-test: $(FFS_TEST_IN)

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

install: $(ALL_PROGRAMS)
install -d -m 755 $(DESTDIR)$(bindir); \
Expand Down

0 comments on commit 5c81664

Please sign in to comment.