From ef91d352e1ffe993d19e4c3c741ece8e30f8af00 Mon Sep 17 00:00:00 2001 From: Benjamin Block Date: Wed, 3 Sep 2014 14:53:17 +0200 Subject: [PATCH] tooling: extracts common install-definitions into a central include After adding install-rules to the tools- and root-Makefile we have some redundancies in some variables and definitions (e.g.: $(INSTALL)). To fix this, extract all duplications and general definitions concerning the install-process into one central Makefile-include `install.mk`. This also unifies the way directories are created for installation-rules. Previously we would just create them every time without checking if that is needed. Now we add them as prerequisite to the install-rule and generate a rule for each of them in `install.mk`. This way `make` will figure out if the need to be created. This also lowers the verboseness of the Makefile. Signed-off-by: Benjamin Block [Jan: moved install.mk to scripts folder] Signed-off-by: Jan Kiszka --- Makefile | 18 ++++-------------- scripts/install.mk | 42 ++++++++++++++++++++++++++++++++++++++++++ tools/Makefile | 34 +++++++++++----------------------- 3 files changed, 57 insertions(+), 37 deletions(-) create mode 100644 scripts/install.mk diff --git a/Makefile b/Makefile index d7beede..9a3f3a1 100644 --- a/Makefile +++ b/Makefile @@ -10,18 +10,12 @@ # the COPYING file in the top-level directory. # -firmwaredir ?= /lib/firmware - -# all directories listed here will be created using a generic rule below -INSTALL_DIRECTORIES := $(DESTDIR)$(firmwaredir) - -INSTALL ?= install -INSTALL_DATA ?= $(INSTALL) -m 644 -INSTALL_DIR ?= $(INSTALL) -d -m 755 - # no recipes above this one (also no includes) all: modules tools +# includes installation-related variables and definitions +include scripts/install.mk + # out-of-tree build for our kernel-module, firmware and inmates KDIR ?= /lib/modules/`uname -r`/build @@ -43,16 +37,12 @@ clean: $(run-kbuild) $(MAKE) -C tools $@ -# create all necessary install-directories -$(INSTALL_DIRECTORIES): - $(INSTALL_DIR) $@ - modules_install: modules $(run-kbuild) depmod -aq firmware_install: hypervisor/jailhouse.bin $(DESTDIR)$(firmwaredir) - $(INSTALL_DATA) $(filter-out $(lastword $^),$^) $(lastword $^) + $(INSTALL_DATA) $^ install: modules_install firmware_install $(MAKE) -C tools $@ diff --git a/scripts/install.mk b/scripts/install.mk new file mode 100644 index 0000000..c35b12f --- /dev/null +++ b/scripts/install.mk @@ -0,0 +1,42 @@ +# +# Jailhouse, a Linux-based partitioning hypervisor +# +# Copyright (c) Siemens AG, 2014 +# +# Authors: +# Jan Kiszka +# Benjamin Block +# +# This work is licensed under the terms of the GNU GPL, version 2. See +# the COPYING file in the top-level directory. +# + +prefix ?= /usr/local +exec_prefix ?= $(prefix) +bindir ?= $(exec_prefix)/bin +libexecdir ?= $(exec_prefix)/libexec +datarootdir ?= $(prefix)/share +datadir ?= $(datarootdir) +firmwaredir ?= /lib/firmware + +# all directories listed here will be created using a generic rule below +INSTALL_DIRECTORIES := $(prefix) \ + $(exec_prefix) \ + $(bindir) \ + $(libexecdir) \ + $(datarootdir) \ + $(datadir) \ + $(firmwaredir) + +INSTALL ?= install +INSTALL_PROGRAM ?= $(INSTALL) +INSTALL_DATA ?= $(INSTALL) -m 644 +INSTALL_DIR ?= $(INSTALL) -d -m 755 + +# creates a rule for each dir in $(INSTALL_DIRECTORIES) under the current +# $(DESTDIR) and additionally to that for each of these dirs a subdir named +# `jailhouse`. These can be used as prerequirement for install-rules and will +# thus be created on demand (or not at all if not used in that way). +$(sort $(INSTALL_DIRECTORIES:%=$(DESTDIR)%) \ + $(INSTALL_DIRECTORIES:%=$(DESTDIR)%/jailhouse)): + $(INSTALL_DIR) $@ diff --git a/tools/Makefile b/tools/Makefile index 2649b1c..5b22901 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -10,24 +10,12 @@ # the COPYING file in the top-level directory. # -prefix ?= /usr/local -exec_prefix ?= $(prefix) -bindir ?= $(exec_prefix)/bin -libexecdir ?= $(exec_prefix)/libexec -datarootdir ?= $(prefix)/share -datadir ?= $(datarootdir) - ifeq ($(V),1) Q = else Q = @ endif -INSTALL ?= install -INSTALL_PROGRAM ?= $(INSTALL) -INSTALL_DATA ?= $(INSTALL) -m 644 -INSTALL_DIR ?= $(INSTALL) -d -m 755 - CC = $(CROSS_COMPILE)gcc CFLAGS = -g -O3 -I.. -DLIBEXECDIR=\"$(libexecdir)\" \ @@ -58,8 +46,12 @@ define patch_datadir_var sed -i 's|^datadir = None|datadir = "$(datadir)"|' $1 endef +# no recipes above this one (also no includes) all: $(TARGETS) +# includes installation-related variables and definitions +include ../scripts/install.mk + jailhouse: jailhouse.c ../jailhouse.h ../VERSION $(CC) $(CFLAGS) -o $@ $< @@ -67,19 +59,15 @@ jailhouse-config-collect: jailhouse-config-create jailhouse-config-collect.tmpl ./$< -g $@ $(Q)chmod +x $@ -install-bin: $(INST_TARGETS) - $(INSTALL_DIR) $(DESTDIR)$(bindir) - $(INSTALL_PROGRAM) $^ $(DESTDIR)$(bindir) +install-bin: $(INST_TARGETS) $(DESTDIR)$(bindir) + $(INSTALL_PROGRAM) $^ -install-libexec: $(HELPERS) - $(INSTALL_DIR) $(DESTDIR)$(libexecdir)/jailhouse - $(INSTALL_PROGRAM) $^ $(DESTDIR)$(libexecdir)/jailhouse - $(Q)$(call patch_datadir_var, \ - $(DESTDIR)$(libexecdir)/jailhouse/jailhouse-config-create) +install-libexec: $(HELPERS) $(DESTDIR)$(libexecdir)/jailhouse + $(INSTALL_PROGRAM) $^ + $(Q)$(call patch_datadir_var, $(lastword $^)/jailhouse-config-create) -install-data: $(TEMPLATES) - $(INSTALL_DIR) $(DESTDIR)$(datadir)/jailhouse - $(INSTALL_DATA) $^ $(DESTDIR)$(datadir)/jailhouse +install-data: $(TEMPLATES) $(DESTDIR)$(datadir)/jailhouse + $(INSTALL_DATA) $^ install: install-bin install-libexec install-data -- 2.39.2