[PATCH] Makefile: Install database in a share directory

Gwendal Grignou <[email protected]>
Newsgroups org.kernel.vger.smatch
Message-ID <[email protected]>
'make install' installs the database .schema files and other assets at
$DESTDIR/$(SHAREDIR)/smatch/smatch_data,
/usr/share/smatch/smatch_data by default.

This way the source code tree does not need to be present to run smatch,
and --data is not required as smatch is compiled to look for data assets
at the above location, in addition to the local directory.

Signed-off-by: Gwendal Grignou <[email protected]>
---
 Makefile | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/Makefile b/Makefile
index ec3a5a84..452e2537 100644
--- a/Makefile
+++ b/Makefile
@@ -14,7 +14,8 @@ CFLAGS ?= -g
 DESTDIR ?=
 PREFIX ?= $(HOME)
 BINDIR ?= $(PREFIX)/bin
-MANDIR ?= $(PREFIX)/share/man
+SHAREDIR ?= $(PREFIX)/share
+MANDIR ?= $(SHAREDIR)/man
 
 PKG_CONFIG ?= pkg-config
 
@@ -85,9 +86,11 @@ PROGRAMS += test-linearize
 PROGRAMS += test-parsing
 PROGRAMS += test-unssa
 
-INST_PROGRAMS=smatch sparse cgcc
-INST_MAN1=sparse.1 cgcc.1
-
+INST_PROGRAMS = smatch sparse cgcc
+INST_MAN1 = sparse.1 cgcc.1
+INST_ASSETS = $(wildcard smatch_data/db/*.schema)
+INST_ASSETS += $(wildcard smatch_data/*)
+INST_ASSETS += $(wildcard smatch_data/db/kernel.*)
 
 all:
 
@@ -106,6 +109,7 @@ cflags += -DMULTIARCH_TRIPLET=\"$(MULTIARCH_TRIPLET)\"
 
 bindir := $(DESTDIR)$(BINDIR)
 man1dir := $(DESTDIR)$(MANDIR)/man1
+smatch_datadir := $(DESTDIR)$(SHAREDIR)/smatch
 
 ########################################################################
 # target specificities
@@ -197,8 +201,6 @@ Q := $(V:1=)
 
 ########################################################################
 
-SMATCHDATADIR=$(INSTALL_PREFIX)/share/smatch
-
 SMATCH_OBJS :=
 SMATCH_OBJS += avl.o
 SMATCH_OBJS += smatch_about_fn_ptr_arg.o
@@ -317,7 +319,7 @@ check_list_local.h:
 	touch check_list_local.h
 
 smatch.o: smatch.c $(LIB_H) smatch.h check_list.h check_list_local.h
-	$(CC) $(CFLAGS) -c smatch.c -DSMATCHDATADIR='"$(SMATCHDATADIR)"'
+	$(CC) $(CFLAGS) -c smatch.c -DSMATCHDATADIR='"$(smatch_datadir)"'
 
 $(SMATCH_OBJS) $(SMATCH_CHECKS): smatch.h smatch_slist.h smatch_extra.h avl.h
 
@@ -375,14 +377,15 @@ clean-check:
 	                  \) -exec rm {} \;
 
 
-install: install-bin install-man
+install: install-bin install-man install-assets
 install-bin: $(INST_PROGRAMS:%=$(bindir)/%)
 install-man: $(INST_MAN1:%=$(man1dir)/%)
+install-assets: $(INST_ASSETS:%=$(smatch_datadir)/%)
 
 $(bindir)/%: %
 	@echo "  INSTALL $@"
 	$(Q)install -D        $< $@ || exit 1;
-$(man1dir)/%: %
+$(man1dir)/% $(smatch_datadir)/%: %
 	@echo "  INSTALL $@"
 	$(Q)install -D -m 644 $< $@ || exit 1;
 
-- 
2.27.0.290.gba653c62da-goog
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.