2016-10-06 17:55:35 -04:00
|
|
|
## 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/>.
|
2016-11-22 11:14:25 -05:00
|
|
|
###################################################################################
|
2016-10-06 17:55:35 -04:00
|
|
|
|
|
|
|
# Project modules
|
2017-04-24 13:06:59 +02:00
|
|
|
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
|
2015-12-13 02:04:07 +01:00
|
|
|
PREFIX ?= /usr/local
|
|
|
|
|
2016-10-06 17:55:35 -04:00
|
|
|
# Default out-of-source build path
|
|
|
|
BUILDDIR ?= build
|
2016-07-26 22:07:37 +02:00
|
|
|
|
2016-10-06 17:55:35 -04:00
|
|
|
# Default debug level for executables
|
|
|
|
V ?= 2
|
2016-06-14 01:17:58 +02:00
|
|
|
|
2016-10-06 17:55:35 -04:00
|
|
|
# Common flags
|
|
|
|
LDLIBS =
|
2017-03-29 04:04:20 +02:00
|
|
|
CFLAGS += -I. -Iinclude -Iinclude/villas
|
|
|
|
CFLAGS += @$(BUILDDIR)/defines
|
|
|
|
CFLAGS += -std=c11 -MMD -mcx16
|
2016-09-13 21:50:35 -04:00
|
|
|
CFLAGS += -Wall -Werror -fdiagnostics-color=auto
|
2016-10-06 17:55:35 -04:00
|
|
|
LDFLAGS += -L$(BUILDDIR)
|
2015-11-23 17:39:01 +01:00
|
|
|
|
2017-05-05 22:59:38 +00:00
|
|
|
# Some tools
|
2017-05-08 00:07:28 +02:00
|
|
|
PKGCONFIG := PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/lib/pkgconfig:$(PKG_CONFIG_PATH) pkg-config
|
2017-06-17 03:15:13 +02:00
|
|
|
SHELL := bash
|
2017-05-05 22:59:38 +00:00
|
|
|
|
2016-10-08 20:28:34 -04:00
|
|
|
# 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
|
2016-10-06 17:55:35 -04:00
|
|
|
CFLAGS += -fprofile-arcs -ftest-coverage
|
|
|
|
LDFLAGS += --coverage
|
|
|
|
LDLIBS += -lgcov
|
|
|
|
|
2016-10-08 20:28:34 -04:00
|
|
|
LIB_LDFLAGS += -coverage
|
2016-10-06 17:55:35 -04:00
|
|
|
LIB_LDLIBS += -gcov
|
2016-10-08 20:28:34 -04:00
|
|
|
|
|
|
|
VARIANTS += coverage
|
2016-09-23 22:12:49 -04:00
|
|
|
endif
|
2016-09-07 06:23:47 +02:00
|
|
|
|
2017-03-29 04:04:20 +02:00
|
|
|
EMPTY :=
|
|
|
|
SPACE := $(EMPTY) $(EMPTY)
|
2015-11-23 17:39:01 +01:00
|
|
|
|
2017-03-29 04:04:20 +02:00
|
|
|
VARIANT = $(subst $(SPACE),-,$(strip $(VARIANTS)))
|
2017-03-06 13:03:32 -04:00
|
|
|
BUILDDIR := $(BUILDDIR)/$(VARIANT)
|
2016-10-08 20:28:34 -04:00
|
|
|
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
|
2017-04-15 18:07:33 +02:00
|
|
|
VERSION := $(shell git describe --tags --abbrev=0 --match v*)
|
|
|
|
VERSION_NUM := $(shell VERSION=$(VERSION); echo $${VERSION:1})
|
2017-03-29 04:04:20 +02:00
|
|
|
|
2017-03-06 13:03:32 -04:00
|
|
|
ifdef CI
|
2017-04-15 18:07:33 +02:00
|
|
|
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}
|
2017-04-01 23:43:46 +02:00
|
|
|
VARIANT := $(VARIANT)-ci
|
2017-03-06 13:03:32 -04:00
|
|
|
else
|
2017-04-15 18:07:33 +02:00
|
|
|
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
|
|
|
|
|
2017-03-27 12:30:44 +02:00
|
|
|
|
2016-10-06 17:55:35 -04:00
|
|
|
# pkg-config dependencies
|
|
|
|
PKGS = libconfig
|
2016-07-11 09:17:35 +02:00
|
|
|
|
2016-10-06 17:55:35 -04:00
|
|
|
######## Targets ########
|
2015-11-23 17:39:01 +01:00
|
|
|
|
2015-12-13 02:06:08 +01:00
|
|
|
# Add flags by pkg-config
|
2017-05-08 00:07:28 +02:00
|
|
|
CFLAGS += $(shell $(PKGCONFIG) --cflags ${PKGS})
|
|
|
|
LDLIBS += $(shell $(PKGCONFIG) --libs ${PKGS})
|
2015-11-23 17:39:01 +01:00
|
|
|
|
2017-03-29 04:04:20 +02:00
|
|
|
all: src plugins tools
|
2016-10-13 22:15:28 -04:00
|
|
|
|
2017-03-29 04:04:20 +02:00
|
|
|
# Build all variants: debug, coverage, ...
|
2016-10-06 17:55:35 -04:00
|
|
|
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
|
|
|
|
2016-10-08 20:28:34 -04:00
|
|
|
# Create non-existent directories
|
2017-03-29 04:04:20 +02:00
|
|
|
.SECONDEXPANSION:
|
|
|
|
.PRECIOUS: %/
|
2016-10-08 20:28:34 -04:00
|
|
|
%/:
|
|
|
|
mkdir -p $@
|
|
|
|
|
2017-03-29 04:04:20 +02:00
|
|
|
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))
|
|
|
|
|
2017-03-29 04:04:20 +02:00
|
|
|
$(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-03-06 13:04:07 -04:00
|
|
|
|
2017-06-13 02:51:11 +02:00
|
|
|
.PHONY: all clean install everything clean-everything
|