1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-03 05:18:29 +03:00

build: fix build rules for srcdir

It's very hard to use some 'non-recurive' Makefiles with
rest of system running 'recursively'.

So ATM drop inclusion of subdir makefile and add support
for 2 new top-level targets:

unit-test  (builds test/unit dir)
run-unit-test (build & run test/unit/unit-test run)
This commit is contained in:
Zdenek Kabelac 2018-05-12 18:14:53 +02:00
parent ac768a9d2b
commit e2c766d37e
3 changed files with 51 additions and 37 deletions

View File

@ -1,6 +1,6 @@
# #
# Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. # Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
# Copyright (C) 2004-2015 Red Hat, Inc. All rights reserved. # Copyright (C) 2004-2018 Red Hat, Inc. All rights reserved.
# #
# This file is part of LVM2. # This file is part of LVM2.
# #
@ -61,6 +61,9 @@ po: tools daemons
man: tools man: tools
all_man: tools all_man: tools
scripts: liblvm libdm scripts: liblvm libdm
test: lib
unit-test: lib
run-unit-test: unit-test
lib.device-mapper: include.device-mapper lib.device-mapper: include.device-mapper
libdm.device-mapper: include.device-mapper libdm.device-mapper: include.device-mapper
@ -96,7 +99,7 @@ endif
DISTCLEAN_TARGETS += cscope.out DISTCLEAN_TARGETS += cscope.out
CLEAN_DIRS += autom4te.cache CLEAN_DIRS += autom4te.cache
check check_system check_cluster check_local check_lvmetad check_lvmpolld check_lvmlockd_test check_lvmlockd_dlm check_lvmlockd_sanlock: all check check_system check_cluster check_local check_lvmetad check_lvmpolld check_lvmlockd_test check_lvmlockd_dlm check_lvmlockd_sanlock unit-test run-unit-test: all
$(MAKE) -C test $(@) $(MAKE) -C test $(@)
conf.generate man.generate: tools conf.generate man.generate: tools
@ -210,10 +213,6 @@ endif
endif endif
include test/unit/Makefile
include device-mapper/Makefile
ifneq ($(shell which ctags),) ifneq ($(shell which ctags),)
.PHONY: tags .PHONY: tags
tags: tags:

View File

@ -27,7 +27,7 @@ datarootdir = @datarootdir@
LVM_TEST_RESULTS ?= results LVM_TEST_RESULTS ?= results
SUBDIRS = api SUBDIRS = api unit
SOURCES = lib/not.c lib/harness.c SOURCES = lib/not.c lib/harness.c
CXXSOURCES = lib/runner.cpp CXXSOURCES = lib/runner.cpp
CXXFLAGS += $(EXTRA_EXEC_CFLAGS) CXXFLAGS += $(EXTRA_EXEC_CFLAGS)
@ -37,9 +37,9 @@ include $(top_builddir)/make.tmpl
T ?= . T ?= .
S ?= @ # never match anything by default S ?= @ # never match anything by default
VERBOSE ?= 0 VERBOSE ?= 0
ALL := $(shell find -L $(srcdir) \( -path \*/shell/\*.sh -or -path \*/api/\*.sh \) | $(SORT)) ALL := $(shell find -L $(srcdir) \( -path \*/shell/\*.sh -or -path \*/api/\*.sh -or -path \*/unit/\*.sh \) | $(SORT))
comma = , comma = ,
RUN := $(shell find -L $(srcdir) -regextype posix-egrep \( -path \*/shell/\*.sh -or -path \*/api/\*.sh \) -and -regex "$(srcdir)/.*($(subst $(comma),|,$(T))).*" -and -not -regex "$(srcdir)/.*($(subst $(comma),|,$(S))).*" | $(SORT)) RUN := $(shell find -L $(srcdir) -regextype posix-egrep \( -path \*/shell/\*.sh -or -path \*/api/\*.sh -or -path \*/unit/\*.sh \) -and -regex "$(srcdir)/.*($(subst $(comma),|,$(T))).*" -and -not -regex "$(srcdir)/.*($(subst $(comma),|,$(S))).*" | $(SORT))
RUN_BASE = $(subst $(srcdir)/,,$(RUN)) RUN_BASE = $(subst $(srcdir)/,,$(RUN))
ifeq ("@BUILD_LVMETAD@", "yes") ifeq ("@BUILD_LVMETAD@", "yes")
@ -83,6 +83,7 @@ help:
@echo " check_lvmlockd_sanlock Run tests with lvmlockd and sanlock." @echo " check_lvmlockd_sanlock Run tests with lvmlockd and sanlock."
@echo " check_lvmlockd_dlm Run tests with lvmlockd and dlm." @echo " check_lvmlockd_dlm Run tests with lvmlockd and dlm."
@echo " check_lvmlockd_test Run tests with lvmlockd --test." @echo " check_lvmlockd_test Run tests with lvmlockd --test."
@echo " run-unit-test Run only unit tests (root not needed)."
@echo " clean Clean dir." @echo " clean Clean dir."
@echo " help Display callable targets." @echo " help Display callable targets."
@echo -e "\nSupported variables:" @echo -e "\nSupported variables:"
@ -190,6 +191,9 @@ check_lvmlockd_test: .tests-stamp
--flavours udev-lvmlockd-test --only $(T) --skip $(S) --flavours udev-lvmlockd-test --only $(T) --skip $(S)
endif endif
run-unit-test unit-test:
$(MAKE) -C unit $(@)
DATADIR = $(datadir)/lvm2-testsuite DATADIR = $(datadir)/lvm2-testsuite
EXECDIR = $(libexecdir)/lvm2-testsuite EXECDIR = $(libexecdir)/lvm2-testsuite

View File

@ -10,38 +10,49 @@
# along with this program; if not, write to the Free Software Foundation, # along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
UNIT_SOURCE=\ srcdir = @srcdir@
base/data-struct/radix-tree.c \ top_srcdir = @top_srcdir@
device-mapper/vdo/status.c \ top_builddir = @top_builddir@
SOURCES=\
radix-tree.c \
status.c \
\ \
test/unit/bcache_t.c \ bcache_t.c \
test/unit/bcache_utils_t.c \ bcache_utils_t.c \
test/unit/bitset_t.c \ bitset_t.c \
test/unit/config_t.c \ config_t.c \
test/unit/dmlist_t.c \ dmlist_t.c \
test/unit/dmstatus_t.c \ dmstatus_t.c \
test/unit/io_engine_t.c \ framework.c \
test/unit/radix_tree_t.c \ io_engine_t.c \
test/unit/matcher_t.c \ matcher_t.c \
test/unit/framework.c \ percent_t.c \
test/unit/percent_t.c \ radix_tree_t.c \
test/unit/run.c \ run.c \
test/unit/string_t.c \ string_t.c \
test/unit/vdo_t.c vdo_t.c
TARGETS += unit-test
# Using vpath for other src dirs
# FIXME: hopefully later we will just link libs without need to extract sources
# via usage of vpath
vpath %.c \
$(top_srcdir)/base/data-struct \
$(top_srcdir)/device-mapper/vdo
include $(top_builddir)/make.tmpl
UNIT_DEPENDS=$(subst .c,.d,$(UNIT_SOURCE))
UNIT_OBJECTS=$(UNIT_SOURCE:%.c=%.o)
CLEAN_TARGETS+=$(UNIT_DEPENDS) $(UNIT_OBJECTS)
UNIT_LDLIBS += $(LVMINTERNAL_LIBS) -ldevmapper -laio UNIT_LDLIBS += $(LVMINTERNAL_LIBS) -ldevmapper -laio
INCLUDES += -I$(top_srcdir)
test/unit/unit-test: $(UNIT_OBJECTS) libdm/libdevmapper.$(LIB_SUFFIX) lib/liblvm-internal.a unit-test: $(OBJECTS) $(top_builddir)/libdm/libdevmapper.$(LIB_SUFFIX) $(top_builddir)/lib/liblvm-internal.a
@echo " [LD] $@" @echo " [LD] $@"
$(Q) $(CC) $(CFLAGS) $(LDFLAGS) $(EXTRA_EXEC_LDFLAGS) -L$(top_builddir)/libdm \ $(Q) $(CC) $(CFLAGS) $(LDFLAGS) $(EXTRA_EXEC_LDFLAGS) -L$(top_builddir)/libdm \
-o $@ $(UNIT_OBJECTS) $(UNIT_LDLIBS) -o $@ $(OBJECTS) $(UNIT_LDLIBS)
.PHONEY: run-unit-test .PHONY: run-unit-test
run-unit-test: test/unit/unit-test run-unit-test: unit-test
@echo Running unit tests @echo Running unit tests
LD_LIBRARY_PATH=libdm test/unit/unit-test run LD_LIBRARY_PATH=$(top_builddir)/libdm ./unit-test run
-include $(UNIT_DEPENDS)