1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00
VILLASnode/Makefile

162 lines
4.3 KiB
Makefile
Raw Permalink Normal View History

## Main project Makefile
#
# The build system of this project is based on GNU Make and pkg-config
#
# To retain maintainability, the project is divided into multiple modules.
# Each module has its own Makefile which gets included.
#
# Please read "Recursive Make Considered Harmful" from Peter Miller
# to understand the motivation for this structure.
#
# [1] http://aegis.sourceforge.net/auug97.pdf
#
# @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
2017-04-27 13:08:17 +02:00
# @copyright 2017, Institute for Automation of Complex Power Systems, EONERC
# @license GNU General Public License (version 3)
#
# VILLASnode
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
###################################################################################
# Project modules
MODULES = clients lib plugins src tests thirdparty tools packaging doc etc web
2016-07-14 09:34:26 +02:00
# Default prefix for install target
PREFIX ?= /usr/local
# Default out-of-source build path
BUILDDIR ?= build
2016-07-26 22:07:37 +02:00
# Default debug level for executables
V ?= 2
# Common flags
LDLIBS =
CFLAGS += -I. -Iinclude -Iinclude/villas
CFLAGS += @$(BUILDDIR)/defines
CFLAGS += -std=c11 -MMD -mcx16
CFLAGS += -Wall -Werror -fdiagnostics-color=auto
LDFLAGS += -L$(BUILDDIR)
2015-11-23 17:39:01 +01:00
# Some tools
PKGCONFIG := PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/lib/pkgconfig:$(PKG_CONFIG_PATH) pkg-config
SHELL := bash
# We must compile without optimizations for gcov!
ifdef DEBUG
CFLAGS += -O0 -g
VARIANTS += debug
else
CFLAGS += -O3
VARIANTS += release
endif
ifdef PROFILE
CFLAGS += -pg
LDFLAGS += -pg
VARIANTS += profile
endif
2016-09-23 22:12:49 -04:00
ifdef COVERAGE
CFLAGS += -fprofile-arcs -ftest-coverage
LDFLAGS += --coverage
LDLIBS += -lgcov
LIB_LDFLAGS += -coverage
LIB_LDLIBS += -gcov
VARIANTS += coverage
2016-09-23 22:12:49 -04:00
endif
2016-09-07 06:23:47 +02:00
EMPTY :=
SPACE := $(EMPTY) $(EMPTY)
2015-11-23 17:39:01 +01:00
VARIANT = $(subst $(SPACE),-,$(strip $(VARIANTS)))
2017-03-06 13:03:32 -04:00
BUILDDIR := $(BUILDDIR)/$(VARIANT)
SRCDIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
2015-12-04 17:35:38 +01:00
2017-03-06 13:03:32 -04:00
# Add git revision and build variant defines
VERSION := $(shell git describe --tags --abbrev=0 --match v*)
VERSION_NUM := $(shell VERSION=$(VERSION); echo $${VERSION:1})
2017-03-06 13:03:32 -04:00
ifdef CI
GIT_REV := $(shell REV=$${CI_BUILD_REF}; echo $${REV:0:7})
2017-04-02 00:17:18 +02:00
GIT_BRANCH = ${CI_BUILD_REF_NAME}
VARIANT := $(VARIANT)-ci
2017-03-06 13:03:32 -04:00
else
GIT_REV := $(shell REV=$$(git rev-parse HEAD); echo $${REV:0:7})
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
2017-03-06 13:03:32 -04:00
endif
# pkg-config dependencies
PKGS = libconfig
######## Targets ########
2015-11-23 17:39:01 +01:00
# Add flags by pkg-config
CFLAGS += $(shell $(PKGCONFIG) --cflags ${PKGS})
LDLIBS += $(shell $(PKGCONFIG) --libs ${PKGS})
2015-11-23 17:39:01 +01:00
all: src plugins tools
2016-10-13 22:15:28 -04:00
# Build all variants: debug, coverage, ...
everything:
2017-06-13 02:51:11 +02:00
$(MAKE) RELEASE=1 tools run-tests
$(MAKE) DEBUG=1 tools run-tests
$(MAKE) COVERAGE=1 tools run-tests
$(MAKE) PROFILE=1 tools run-tests
clean-everything:
$(MAKE) RELEASE=1 clean
$(MAKE) DEBUG=1 clean
$(MAKE) COVERAGE=1 clean
$(MAKE) PROFILE=1 clean
2015-11-23 17:39:01 +01:00
# Create non-existent directories
.SECONDEXPANSION:
.PRECIOUS: %/
%/:
mkdir -p $@
define DEFINES
-DV=$(V)
-DPLUGIN_PATH=\"$(PREFIX)/share/villas/node/plugins\"
-DWEB_PATH=\"$(PREFIX)/share/villas/node/web\"
-DSYSFS_PATH=\"/sys\"
-DPROCFS_PATH=\"/proc\"
-DBUILDID=\"$(VERSION)-$(GIT_REV)-$(VARIANT)\"
-D_POSIX_C_SOURCE=200809L
-D_GNU_SOURCE=1
endef
export DEFINES
2017-06-13 02:51:11 +02:00
include $(wildcard $(BUILDDIR)/**/*.d)
include $(addsuffix /Makefile.inc,$(MODULES))
$(BUILDDIR)/defines: | $$(dir $$@)
echo "$${DEFINES}" > $@
echo -e "$(addprefix \n-DWITH_, $(shell echo ${PKGS} | tr a-z- A-Z_ | tr -dc ' A-Z0-9_' ))" >> $@
echo -e "$(addprefix \n-DWITH_, $(shell echo ${LIB_PKGS} | tr a-z- A-Z_ | tr -dc ' A-Z0-9_' ))" >> $@
2017-06-13 02:51:11 +02:00
install: $(addprefix install-,$(filter-out thirdparty,$(MODULES)))
clean: $(addprefix clean-,$(MODULES))
rm -f $(BUILDDIR)/defines
2017-06-13 02:51:11 +02:00
.PHONY: all clean install everything clean-everything