Skip to content

Commit

Permalink
Makefile: Build man-page only when sphinx is available
Browse files Browse the repository at this point in the history
Currently, it's not possible to compile the upstream branch using the
`make' command without sphinx beeing installed.

Check if sphinx-build is installed and only then build or install the
man-page.

The problem was noticed from commit
f4f2f3d move manpage to sphinx.

Change-Id: If1b81d9bc25ecac19d493b44b00a7c42d0643fe6
Signed-off-by: Thomas Heijligen <[email protected]>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/74519
Reviewed-by: Anastasia Klimchuk <[email protected]>
Tested-by: build bot (Jenkins) <[email protected]>
  • Loading branch information
heijligen authored and Anastasia Klimchuk committed May 10, 2023
1 parent 5ebdfb8 commit fc7810e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
23 changes: 16 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ EXPORTDIR ?= .
RANLIB ?= ranlib
PKG_CONFIG ?= pkg-config
BUILD_DETAILS_FILE ?= build_details.txt
SPHINXBUILD ?= sphinx-build

# The following parameter changes the default programmer that will be used if there is no -p/--programmer
# argument given when running flashrom. The predefined setting does not enable any default so that every
Expand Down Expand Up @@ -259,6 +260,7 @@ HAS_LINUX_MTD := $(call c_compile_test, Makefile.d/linux_mtd_test.c)
HAS_LINUX_SPI := $(call c_compile_test, Makefile.d/linux_spi_test.c)
HAS_LINUX_I2C := $(call c_compile_test, Makefile.d/linux_i2c_test.c)
HAS_SERIAL := $(strip $(if $(filter $(TARGET_OS), DOS libpayload), no, yes))
HAS_SPHINXBUILD := $(shell command -v $(SPHINXBUILD) &>/dev/null && echo yes || echo no)
EXEC_SUFFIX := $(strip $(if $(filter $(TARGET_OS), DOS MinGW), .exe))

override CFLAGS += -Iinclude
Expand Down Expand Up @@ -956,7 +958,7 @@ endif
OBJS = $(CHIP_OBJS) $(PROGRAMMER_OBJS) $(LIB_OBJS)


all: $(PROGRAM)$(EXEC_SUFFIX) man8/$(PROGRAM).8
all: $(PROGRAM)$(EXEC_SUFFIX) $(call has_dependency, $(HAS_SPHINXBUILD), man8/$(PROGRAM).8)
ifeq ($(ARCH), x86)
@+$(MAKE) -C util/ich_descriptors_tool/ HOST_OS=$(HOST_OS) TARGET_OS=$(TARGET_OS)
endif
Expand Down Expand Up @@ -1017,6 +1019,7 @@ config:
echo "The following features are unavailable on your machine: $(UNSUPPORTED_FEATURES)" \
exit 1; \
fi
@echo "Checking for program \"sphinx-build\": $(HAS_SPHINXBUILD)"

%.o: %.c | config
$(CC) -MMD $(CFLAGS) $(CPPFLAGS) $(FLASHROM_CFLAGS) $(FEATURE_FLAGS) -D'FLASHROM_VERSION=$(VERSION)' -o $@ -c $<
Expand All @@ -1028,9 +1031,13 @@ libflashrom.a: $(OBJS)
$(AR) rcs $@ $^
$(RANLIB) $@

SPHINXBUILD ?= sphinx-build
man8/$(PROGRAM).8: doc/*
@FLASHROM_VERSION=$(VERSION) $(SPHINXBUILD) -b man doc .
@if [ "$(HAS_SPHINXBUILD)" = "yes" ]; then \
$(SPHINXBUILD) -Drelease=$(VERSION) -b man doc .; \
else \
echo "$(SPHINXBUILD) not found. Can't build man-page"; \
exit 1; \
fi

$(PROGRAM).bash: util/$(PROGRAM).bash-completion.tmpl
@# Add to the bash completion file a list of enabled programmers.
Expand All @@ -1047,13 +1054,15 @@ clean:
man8 .doctrees $(PROGRAM).bash $(BUILD_DETAILS_FILE)
@+$(MAKE) -C util/ich_descriptors_tool/ clean

install: $(PROGRAM)$(EXEC_SUFFIX) man8/$(PROGRAM).8 $(PROGRAM).bash
install: $(PROGRAM)$(EXEC_SUFFIX) $(call has_dependency, $(HAS_SPHINXBUILD), man8/$(PROGRAM).8) $(PROGRAM).bash
mkdir -p $(DESTDIR)$(PREFIX)/sbin
mkdir -p $(DESTDIR)$(MANDIR)/man8
mkdir -p $(DESTDIR)$(BASHCOMPDIR)
$(INSTALL) -m 0755 $(PROGRAM)$(EXEC_SUFFIX) $(DESTDIR)$(PREFIX)/sbin
$(INSTALL) -m 0644 man8/$(PROGRAM).8 $(DESTDIR)$(MANDIR)/man8
mkdir -p $(DESTDIR)$(BASHCOMPDIR)
$(INSTALL) -m 0644 $(PROGRAM).bash $(DESTDIR)$(BASHCOMPDIR)
ifeq ($(HAS_SPHINXBUILD), yes)
mkdir -p $(DESTDIR)$(MANDIR)/man8
$(INSTALL) -m 0644 man8/$(PROGRAM).8 $(DESTDIR)$(MANDIR)/man8
endif

libinstall: libflashrom.a include/libflashrom.h
mkdir -p $(DESTDIR)$(PREFIX)/lib
Expand Down
4 changes: 4 additions & 0 deletions Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ define dependency_version
$(call debug_shell, $(if $(PKG_CONFIG_LIBDIR),PKG_CONFIG_LIBDIR=$(PKG_CONFIG_LIBDIR),) $(PKG_CONFIG) --modversion $1 2>/dev/null)
endef

define has_dependency # $1: dependency, $2: action/target
$(if $(findstring $(strip $1),yes), $(strip $2))
endef

define dependency_cflags
$(call debug_shell, $(if $(PKG_CONFIG_LIBDIR),PKG_CONFIG_LIBDIR=$(PKG_CONFIG_LIBDIR),) $(PKG_CONFIG) --cflags $1 2>/dev/null)
endef
Expand Down

0 comments on commit fc7810e

Please sign in to comment.