xref: /openbmc/linux/tools/verification/rv/Makefile (revision c595db6d7c8bcf87ef42204391fa890e5950e566)
14bc4b131SDaniel Bristot de OliveiraNAME	:=	rv
24bc4b131SDaniel Bristot de Oliveira# Follow the kernel version
34bc4b131SDaniel Bristot de OliveiraVERSION :=	$(shell cat VERSION 2> /dev/null || make -sC ../../.. kernelversion | grep -v make)
44bc4b131SDaniel Bristot de Oliveira
54bc4b131SDaniel Bristot de Oliveira# From libtracefs:
64bc4b131SDaniel Bristot de Oliveira# Makefiles suck: This macro sets a default value of $(2) for the
74bc4b131SDaniel Bristot de Oliveira# variable named by $(1), unless the variable has been set by
84bc4b131SDaniel Bristot de Oliveira# environment or command line. This is necessary for CC and AR
94bc4b131SDaniel Bristot de Oliveira# because make sets default values, so the simpler ?= approach
104bc4b131SDaniel Bristot de Oliveira# won't work as expected.
114bc4b131SDaniel Bristot de Oliveiradefine allow-override
124bc4b131SDaniel Bristot de Oliveira  $(if $(or $(findstring environment,$(origin $(1))),\
134bc4b131SDaniel Bristot de Oliveira            $(findstring command line,$(origin $(1)))),,\
144bc4b131SDaniel Bristot de Oliveira    $(eval $(1) = $(2)))
154bc4b131SDaniel Bristot de Oliveiraendef
164bc4b131SDaniel Bristot de Oliveira
174bc4b131SDaniel Bristot de Oliveira# Allow setting CC and AR, or setting CROSS_COMPILE as a prefix.
184bc4b131SDaniel Bristot de Oliveira$(call allow-override,CC,$(CROSS_COMPILE)gcc)
194bc4b131SDaniel Bristot de Oliveira$(call allow-override,AR,$(CROSS_COMPILE)ar)
204bc4b131SDaniel Bristot de Oliveira$(call allow-override,STRIP,$(CROSS_COMPILE)strip)
214bc4b131SDaniel Bristot de Oliveira$(call allow-override,PKG_CONFIG,pkg-config)
224bc4b131SDaniel Bristot de Oliveira$(call allow-override,LD_SO_CONF_PATH,/etc/ld.so.conf.d/)
234bc4b131SDaniel Bristot de Oliveira$(call allow-override,LDCONFIG,ldconfig)
244bc4b131SDaniel Bristot de Oliveira
254bc4b131SDaniel Bristot de OliveiraINSTALL	=	install
264bc4b131SDaniel Bristot de OliveiraMKDIR	=	mkdir
274bc4b131SDaniel Bristot de OliveiraFOPTS	:=	-flto=auto -ffat-lto-objects -fexceptions -fstack-protector-strong \
284bc4b131SDaniel Bristot de Oliveira		-fasynchronous-unwind-tables -fstack-clash-protection
294bc4b131SDaniel Bristot de OliveiraWOPTS	:= 	-Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -Wno-maybe-uninitialized
304bc4b131SDaniel Bristot de Oliveira
31*828be9ffSDaniel Bristot de Oliveiraifeq ($(CC),clang)
32*828be9ffSDaniel Bristot de Oliveira  FOPTS := $(filter-out -ffat-lto-objects, $(FOPTS))
33*828be9ffSDaniel Bristot de Oliveira  WOPTS := $(filter-out -Wno-maybe-uninitialized, $(WOPTS))
34*828be9ffSDaniel Bristot de Oliveiraendif
35*828be9ffSDaniel Bristot de Oliveira
364bc4b131SDaniel Bristot de OliveiraTRACEFS_HEADERS	:= $$($(PKG_CONFIG) --cflags libtracefs)
374bc4b131SDaniel Bristot de Oliveira
384bc4b131SDaniel Bristot de OliveiraCFLAGS	:=	-O -g -DVERSION=\"$(VERSION)\" $(FOPTS) $(MOPTS) $(WOPTS) $(TRACEFS_HEADERS) $(EXTRA_CFLAGS) -I include
39*828be9ffSDaniel Bristot de OliveiraLDFLAGS	:=	-flto=auto -ggdb $(EXTRA_LDFLAGS)
404bc4b131SDaniel Bristot de OliveiraLIBS	:=	$$($(PKG_CONFIG) --libs libtracefs)
414bc4b131SDaniel Bristot de Oliveira
424bc4b131SDaniel Bristot de OliveiraSRC	:=	$(wildcard src/*.c)
434bc4b131SDaniel Bristot de OliveiraHDR	:=	$(wildcard src/*.h)
444bc4b131SDaniel Bristot de OliveiraOBJ	:=	$(SRC:.c=.o)
454bc4b131SDaniel Bristot de OliveiraDIRS	:=	src
464bc4b131SDaniel Bristot de OliveiraFILES	:=	Makefile README.txt
474bc4b131SDaniel Bristot de OliveiraCEXT	:=	bz2
484bc4b131SDaniel Bristot de OliveiraTARBALL	:=	$(NAME)-$(VERSION).tar.$(CEXT)
494bc4b131SDaniel Bristot de OliveiraTAROPTS	:=	-cvjf $(TARBALL)
504bc4b131SDaniel Bristot de OliveiraBINDIR	:=	/usr/bin
514bc4b131SDaniel Bristot de OliveiraDATADIR	:=	/usr/share
52afc70ccbSDaniel Bristot de OliveiraDOCDIR	:=	$(DATADIR)/doc
534bc4b131SDaniel Bristot de OliveiraMANDIR	:=	$(DATADIR)/man
544bc4b131SDaniel Bristot de OliveiraLICDIR	:=	$(DATADIR)/licenses
554bc4b131SDaniel Bristot de OliveiraSRCTREE	:=	$(or $(BUILD_SRC),$(CURDIR))
564bc4b131SDaniel Bristot de Oliveira
57afc70ccbSDaniel Bristot de Oliveira# If running from the tarball, man pages are stored in the Documentation
58afc70ccbSDaniel Bristot de Oliveira# dir. If running from the kernel source, man pages are stored in
59afc70ccbSDaniel Bristot de Oliveira# Documentation/tools/rv/.
60afc70ccbSDaniel Bristot de Oliveiraifneq ($(wildcard Documentation/.*),)
61afc70ccbSDaniel Bristot de OliveiraDOCSRC	=	Documentation/
62afc70ccbSDaniel Bristot de Oliveiraelse
63afc70ccbSDaniel Bristot de OliveiraDOCSRC	=	$(SRCTREE)/../../../Documentation/tools/rv/
64afc70ccbSDaniel Bristot de Oliveiraendif
65afc70ccbSDaniel Bristot de Oliveira
664bc4b131SDaniel Bristot de OliveiraLIBTRACEEVENT_MIN_VERSION = 1.5
674bc4b131SDaniel Bristot de OliveiraLIBTRACEFS_MIN_VERSION = 1.3
684bc4b131SDaniel Bristot de Oliveira
694bc4b131SDaniel Bristot de Oliveira.PHONY:	all warnings show_warnings
704bc4b131SDaniel Bristot de Oliveiraall:	warnings rv
714bc4b131SDaniel Bristot de Oliveira
724bc4b131SDaniel Bristot de OliveiraTEST_LIBTRACEEVENT = $(shell sh -c "$(PKG_CONFIG) --atleast-version $(LIBTRACEEVENT_MIN_VERSION) libtraceevent > /dev/null 2>&1 || echo n")
734bc4b131SDaniel Bristot de Oliveiraifeq ("$(TEST_LIBTRACEEVENT)", "n")
744bc4b131SDaniel Bristot de OliveiraWARNINGS = show_warnings
754bc4b131SDaniel Bristot de OliveiraMISSING_LIBS += echo "**   libtraceevent version $(LIBTRACEEVENT_MIN_VERSION) or higher";
764bc4b131SDaniel Bristot de OliveiraMISSING_PACKAGES += "libtraceevent-devel"
774bc4b131SDaniel Bristot de OliveiraMISSING_SOURCE += echo "**  https://git.kernel.org/pub/scm/libs/libtrace/libtraceevent.git/ ";
784bc4b131SDaniel Bristot de Oliveiraendif
794bc4b131SDaniel Bristot de Oliveira
804bc4b131SDaniel Bristot de OliveiraTEST_LIBTRACEFS = $(shell sh -c "$(PKG_CONFIG) --atleast-version $(LIBTRACEFS_MIN_VERSION) libtracefs > /dev/null 2>&1 || echo n")
814bc4b131SDaniel Bristot de Oliveiraifeq ("$(TEST_LIBTRACEFS)", "n")
824bc4b131SDaniel Bristot de OliveiraWARNINGS = show_warnings
834bc4b131SDaniel Bristot de OliveiraMISSING_LIBS += echo "**   libtracefs version $(LIBTRACEFS_MIN_VERSION) or higher";
844bc4b131SDaniel Bristot de OliveiraMISSING_PACKAGES += "libtracefs-devel"
854bc4b131SDaniel Bristot de OliveiraMISSING_SOURCE += echo "**  https://git.kernel.org/pub/scm/libs/libtrace/libtracefs.git/ ";
864bc4b131SDaniel Bristot de Oliveiraendif
874bc4b131SDaniel Bristot de Oliveira
884bc4b131SDaniel Bristot de Oliveiradefine show_dependencies
894bc4b131SDaniel Bristot de Oliveira	@echo "********************************************";				\
904bc4b131SDaniel Bristot de Oliveira	echo "** NOTICE: Failed build dependencies";					\
914bc4b131SDaniel Bristot de Oliveira	echo "**";									\
924bc4b131SDaniel Bristot de Oliveira	echo "** Required Libraries:";							\
934bc4b131SDaniel Bristot de Oliveira	$(MISSING_LIBS)									\
944bc4b131SDaniel Bristot de Oliveira	echo "**";									\
954bc4b131SDaniel Bristot de Oliveira	echo "** Consider installing the latest libtracefs from your";			\
964bc4b131SDaniel Bristot de Oliveira	echo "** distribution, e.g., 'dnf install $(MISSING_PACKAGES)' on Fedora,";	\
974bc4b131SDaniel Bristot de Oliveira	echo "** or from source:";							\
984bc4b131SDaniel Bristot de Oliveira	echo "**";									\
994bc4b131SDaniel Bristot de Oliveira	$(MISSING_SOURCE)								\
1004bc4b131SDaniel Bristot de Oliveira	echo "**";									\
1014bc4b131SDaniel Bristot de Oliveira	echo "********************************************"
1024bc4b131SDaniel Bristot de Oliveiraendef
1034bc4b131SDaniel Bristot de Oliveira
1044bc4b131SDaniel Bristot de Oliveirashow_warnings:
1054bc4b131SDaniel Bristot de Oliveira	$(call show_dependencies);
1064bc4b131SDaniel Bristot de Oliveira
1074bc4b131SDaniel Bristot de Oliveiraifneq ("$(WARNINGS)", "")
1084bc4b131SDaniel Bristot de OliveiraERROR_OUT = $(error Please add the necessary dependencies)
1094bc4b131SDaniel Bristot de Oliveira
1104bc4b131SDaniel Bristot de Oliveirawarnings: $(WARNINGS)
1114bc4b131SDaniel Bristot de Oliveira	$(ERROR_OUT)
1124bc4b131SDaniel Bristot de Oliveiraendif
1134bc4b131SDaniel Bristot de Oliveira
1144bc4b131SDaniel Bristot de Oliveirarv: $(OBJ)
1154bc4b131SDaniel Bristot de Oliveira	$(CC) -o rv $(LDFLAGS) $(OBJ) $(LIBS)
1164bc4b131SDaniel Bristot de Oliveira
1174bc4b131SDaniel Bristot de Oliveira.PHONY: install
118afc70ccbSDaniel Bristot de Oliveirainstall: doc_install
1194bc4b131SDaniel Bristot de Oliveira	$(MKDIR) -p $(DESTDIR)$(BINDIR)
1204bc4b131SDaniel Bristot de Oliveira	$(INSTALL) rv -m 755 $(DESTDIR)$(BINDIR)
1214bc4b131SDaniel Bristot de Oliveira	$(STRIP) $(DESTDIR)$(BINDIR)/rv
1224bc4b131SDaniel Bristot de Oliveira
1234bc4b131SDaniel Bristot de Oliveira.PHONY: clean tarball
124afc70ccbSDaniel Bristot de Oliveiraclean: doc_clean
1254bc4b131SDaniel Bristot de Oliveira	@test ! -f rv || rm rv
1264bc4b131SDaniel Bristot de Oliveira	@test ! -f $(TARBALL) || rm -f $(TARBALL)
1274bc4b131SDaniel Bristot de Oliveira	@rm -rf *~ $(OBJ) *.tar.$(CEXT)
1284bc4b131SDaniel Bristot de Oliveira
1294bc4b131SDaniel Bristot de Oliveiratarball: clean
1304bc4b131SDaniel Bristot de Oliveira	rm -rf $(NAME)-$(VERSION) && mkdir $(NAME)-$(VERSION)
1314bc4b131SDaniel Bristot de Oliveira	echo $(VERSION) > $(NAME)-$(VERSION)/VERSION
1324bc4b131SDaniel Bristot de Oliveira	cp -r $(DIRS) $(FILES) $(NAME)-$(VERSION)
133afc70ccbSDaniel Bristot de Oliveira	mkdir $(NAME)-$(VERSION)/Documentation/
134afc70ccbSDaniel Bristot de Oliveira	cp -rp $(SRCTREE)/../../../Documentation/tools/rv/* $(NAME)-$(VERSION)/Documentation/
1354bc4b131SDaniel Bristot de Oliveira	tar $(TAROPTS) --exclude='*~' $(NAME)-$(VERSION)
1364bc4b131SDaniel Bristot de Oliveira	rm -rf $(NAME)-$(VERSION)
137afc70ccbSDaniel Bristot de Oliveira
138afc70ccbSDaniel Bristot de Oliveira.PHONY: doc doc_clean doc_install
139afc70ccbSDaniel Bristot de Oliveiradoc:
140afc70ccbSDaniel Bristot de Oliveira	$(MAKE) -C $(DOCSRC)
141afc70ccbSDaniel Bristot de Oliveira
142afc70ccbSDaniel Bristot de Oliveiradoc_clean:
143afc70ccbSDaniel Bristot de Oliveira	$(MAKE) -C $(DOCSRC) clean
144afc70ccbSDaniel Bristot de Oliveira
145afc70ccbSDaniel Bristot de Oliveiradoc_install:
146afc70ccbSDaniel Bristot de Oliveira	$(MAKE) -C $(DOCSRC) install
147