From 2e7fe8e888e7064f6066589a2fdc18ab893be3fd Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Wed, 15 Nov 2017 10:36:36 -0700 Subject: [PATCH] build: add 'make install' rule For now, this only installs libraries and headers; we will need to consider which binaries should be installed and what they should be named before we add them to the install rule. Change-Id: I78dc8631f793d0df88cd884b0ac66406df9e4427 Signed-off-by: Daniel Verkamp Reviewed-on: https://review.gerrithub.io/387637 Tested-by: SPDK Automated Test System Reviewed-by: Ben Walker Reviewed-by: Jim Harris --- CHANGELOG.md | 8 +++++++- CONFIG | 3 +++ Makefile | 5 ++++- autobuild.sh | 6 ++++++ configure | 9 +++++++++ dpdkbuild/Makefile | 4 +++- include/Makefile | 49 ++++++++++++++++++++++++++++++++++++++++++++++ mk/spdk.app.mk | 2 ++ mk/spdk.common.mk | 21 ++++++++++++++++++++ mk/spdk.lib.mk | 3 +++ mk/spdk.subdirs.mk | 2 ++ 11 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 include/Makefile diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b82cea3a..2243fffb5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # Changelog -## v18.01 +## v18.01: (Upcoming Release) + +### Build System + +The build system now includes a `make install` rule, including support for the common +`DESTDIR` and `prefix` variables as used in other build systems. Additionally, the prefix +may be set via the configure `--prefix` option. Example: `make install prefix=/usr`. ### RPC diff --git a/CONFIG b/CONFIG index 47c5430d1..28f4ab0e8 100644 --- a/CONFIG +++ b/CONFIG @@ -31,6 +31,9 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # +# Installation prefix +CONFIG_PREFIX?=/usr/local + # Build with debug logging. Turn off for performance testing and normal usage CONFIG_DEBUG?=n diff --git a/Makefile b/Makefile index 3ba1b0db1..51810be89 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,7 @@ S := SPDK_ROOT_DIR := $(CURDIR) include $(SPDK_ROOT_DIR)/mk/spdk.common.mk -DIRS-y += lib test examples app +DIRS-y += lib test examples app include .PHONY: all clean $(DIRS-y) config.h CONFIG.local mk/cc.mk @@ -50,6 +50,9 @@ clean: $(DIRS-y) $(Q)rm -f mk/cc.mk $(Q)rm -f config.h +install: all + $(Q)echo "Installed to $(DESTDIR)$(CONFIG_PREFIX)" + lib: $(DPDKBUILD) app: lib test: lib diff --git a/autobuild.sh b/autobuild.sh index 0ae16937a..0852dffd5 100755 --- a/autobuild.sh +++ b/autobuild.sh @@ -74,6 +74,12 @@ if [ "$STAT1" == "$STAT2" ]; then exit 1 fi +# Test 'make install' +rm -rf /tmp/spdk +mkdir /tmp/spdk +$MAKE $MAKEFLAGS install DESTDIR=/tmp/spdk prefix=/usr +ls -lR /tmp/spdk +rm -rf /tmp/spdk timing_enter doxygen if [ $SPDK_BUILD_DOC -eq 1 ] && hash doxygen; then diff --git a/configure b/configure index 6663dc0bf..b5fe02d3a 100755 --- a/configure +++ b/configure @@ -12,6 +12,9 @@ function usage() echo "" echo "General:" echo " -h, --help Display this help and exit" + echo "" + echo " --prefix=path Configure installation prefix (default: /usr/local)" + echo "" echo " --enable-debug Configure for debug builds" echo " --enable-werror Treat compiler warnings as errors" echo " --enable-asan Enable address sanitizer" @@ -50,6 +53,9 @@ for i in "$@"; do usage exit 0 ;; + --prefix=*) + CONFIG_PREFIX="${i#*=}" + ;; --enable-debug) CONFIG_DEBUG=y ;; @@ -199,6 +205,9 @@ echo -n "Creating CONFIG.local..." # Write the configuration file rm -f CONFIG.local +if [ -n "$CONFIG_PREFIX" ]; then + echo "CONFIG_PREFIX?=$CONFIG_PREFIX" >> CONFIG.local +fi if [ -n "$CONFIG_DEBUG" ]; then echo "CONFIG_DEBUG?=$CONFIG_DEBUG" >> CONFIG.local fi diff --git a/dpdkbuild/Makefile b/dpdkbuild/Makefile index fb15d5fa3..cc611156b 100644 --- a/dpdkbuild/Makefile +++ b/dpdkbuild/Makefile @@ -34,7 +34,7 @@ SPDK_ROOT_DIR := $(abspath $(CURDIR)/..) include $(SPDK_ROOT_DIR)/mk/spdk.common.mk -.PHONY: all clean +.PHONY: all clean install ifeq ($(TARGET_MACHINE),aarch64) DPDK_CONFIG := arm64-armv8a @@ -80,3 +80,5 @@ all: $(SPDK_ROOT_DIR)/dpdk/build clean: $(Q)rm -rf $(SPDK_ROOT_DIR)/dpdk/build + +install: all diff --git a/include/Makefile b/include/Makefile new file mode 100644 index 000000000..bd385c26f --- /dev/null +++ b/include/Makefile @@ -0,0 +1,49 @@ +# +# BSD LICENSE +# +# Copyright (c) Intel Corporation. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Intel Corporation nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# + +SPDK_ROOT_DIR := $(abspath $(CURDIR)/..) +include $(SPDK_ROOT_DIR)/mk/spdk.common.mk + +HEADERS := $(wildcard $(SPDK_ROOT_DIR)/include/spdk/*.h) +INSTALLED_HEADERS := $(patsubst $(SPDK_ROOT_DIR)/include%,$(DESTDIR)$(includedir)%,$(HEADERS)) + +$(DESTDIR)$(includedir)%.h: + $(INSTALL_HEADER) + +all: + +clean: + +install: $(INSTALLED_HEADERS) + +include $(SPDK_ROOT_DIR)/mk/spdk.deps.mk diff --git a/mk/spdk.app.mk b/mk/spdk.app.mk index a4a6afc40..b368be4ed 100644 --- a/mk/spdk.app.mk +++ b/mk/spdk.app.mk @@ -57,3 +57,5 @@ SPDK_LIB_LINKER_ARGS = \ $(SPDK_WHOLE_ARCHIVE_LIB_LIST:%=-lspdk_%) \ -Wl,--no-whole-archive \ $(SPDK_REMAINING_LIB_LIST:%=-lspdk_%) + +install: all diff --git a/mk/spdk.common.mk b/mk/spdk.common.mk index 037c44844..ce60662b3 100644 --- a/mk/spdk.common.mk +++ b/mk/spdk.common.mk @@ -43,6 +43,15 @@ Q ?= @ endif S ?= $(notdir $(CURDIR)) +DESTDIR?= + +ifneq ($(prefix),) +CONFIG_PREFIX=$(prefix) +endif + +libdir?=$(CONFIG_PREFIX)/lib +includedir?=$(CONFIG_PREFIX)/include + ifeq ($(MAKECMDGOALS),) MAKECMDGOALS=$(.DEFAULT_GOAL) endif @@ -192,6 +201,18 @@ LIB_C=\ CLEAN_C=\ $(Q)rm -f *.a *.o *.d *.d.tmp *.gcno *.gcda +# Install a library +INSTALL_LIB=\ + $(Q)echo " INSTALL $(DESTDIR)$(libdir)/$(notdir $(LIB))"; \ + install -d -m 755 "$(DESTDIR)$(libdir)"; \ + install -m 644 "$(LIB)" "$(DESTDIR)$(libdir)/" + +# Install a header +INSTALL_HEADER=\ + $(Q)echo " INSTALL $@"; \ + install -d -m 755 "$(DESTDIR)$(includedir)/$(dir $(patsubst $(DESTDIR)$(includedir)/%,%,$@))"; \ + install -m 644 "$(patsubst $(DESTDIR)$(includedir)/%,%,$@)" "$(DESTDIR)$(includedir)/$(dir $(patsubst $(DESTDIR)$(includedir)/%,%,$@))/" + %.o: %.c %.d $(MAKEFILE_LIST) $(COMPILE_C) diff --git a/mk/spdk.lib.mk b/mk/spdk.lib.mk index 0a0c501e9..cdb2c5b26 100644 --- a/mk/spdk.lib.mk +++ b/mk/spdk.lib.mk @@ -45,6 +45,9 @@ clean: $(DIRS-y) $(LIB): $(OBJS) $(LIB_C) +install: all + $(INSTALL_LIB) + include $(SPDK_ROOT_DIR)/mk/spdk.deps.mk include $(SPDK_ROOT_DIR)/mk/spdk.subdirs.mk diff --git a/mk/spdk.subdirs.mk b/mk/spdk.subdirs.mk index d6f5bfedb..30415bb87 100644 --- a/mk/spdk.subdirs.mk +++ b/mk/spdk.subdirs.mk @@ -33,3 +33,5 @@ $(DIRS-y) : $(Q)$(MAKE) -e -C $@ S=$S$(S:%=/)$@ $(MAKECMDGOALS) $(MAKESUBDIRFLAGS) + +install: all $(DIRS-y)