From 1cbfd72d35ba6e9942ef36f2770126f13ee94bf3 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Sat, 8 Oct 2016 20:28:34 -0400 Subject: [PATCH] build thirdparty dependencies out-of-source as well --- .gitmodules | 6 ++++ Dockerfile | 3 +- Makefile | 61 ++++++++++++++++++++++---------------- lib/Makefile.inc | 4 +-- thirdparty/Makefile | 49 ------------------------------ thirdparty/Makefile.inc | 34 +++++++++++++++++++++ thirdparty/libxil/Makefile | 24 +++++++++++---- 7 files changed, 97 insertions(+), 84 deletions(-) delete mode 100644 thirdparty/Makefile create mode 100644 thirdparty/Makefile.inc diff --git a/.gitmodules b/.gitmodules index b6cec1228..695ea3296 100644 --- a/.gitmodules +++ b/.gitmodules @@ -16,3 +16,9 @@ [submodule "thirdparty/pciutils"] path = thirdparty/pciutils url = https://github.com/pciutils/pciutils.git +[submodule "thirdparty/jansson"] + path = thirdparty/jansson + url = https://github.com/akheron/jansson.git +[submodule "thirdparty/libcurl"] + path = thirdparty/libcurl + url = https://github.com/curl/curl.git diff --git a/Dockerfile b/Dockerfile index 1e873658a..c93218039 100644 --- a/Dockerfile +++ b/Dockerfile @@ -58,6 +58,7 @@ RUN dnf -y update && \ flex \ bison \ texinfo - + +WORKDIR /villas ENTRYPOINT /bin/bash diff --git a/Makefile b/Makefile index a6c2ad81b..90599816f 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ ################################################################################# # Project modules -MODULES = lib plugins src tests +MODULES = lib plugins src tests thirdparty # Default prefix for install target PREFIX ?= /usr/local @@ -41,30 +41,38 @@ else ifdef GIT CFLAGS += -D_GIT_REV='"$(shell git rev-parse --short HEAD)"' endif +# 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 + ifdef COVERAGE CFLAGS += -fprofile-arcs -ftest-coverage LDFLAGS += --coverage LDLIBS += -lgcov - LIB_LDFLAGS += --coverage + LIB_LDFLAGS += -coverage LIB_LDLIBS += -gcov + + VARIANTS += coverage endif -# We must compile without optimizations for gcov! -ifneq ($(or $(DEBUG),$(COVERAGE)),) - CFLAGS += -O0 -g -else - CFLAGS += -O3 -endif +SPACE := +SPACE += +BUILDDIR := $(BUILDDIR)/$(subst $(SPACE),-,$(strip $(VARIANTS))) -# Build variant -ifdef COVERAGE - BUILDDIR := $(BUILDDIR)/coverage -else ifdef DEBUG - BUILDDIR := $(BUILDDIR)/debug -else - BUILDDIR := $(BUILDDIR)/release -endif +SRCDIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) # pkg-config dependencies PKGS = libconfig @@ -77,26 +85,21 @@ CFLAGS += $(shell pkg-config --cflags ${PKGS}) LDLIBS += $(shell pkg-config --libs ${PKGS}) # Default target: build everything; no tests, docs -all: $(MODULES) +all: src everything: $(MAKE) DEBUG=1 $(MAKE) COVERAGE=1 + $(MAKE) PROFILE=1 $(MAKE) doc $(MAKE) tests .PHONY: all clean install docker doc $(MODULES) -.SECONDARY: -.SECONDEXPANSION: - -# Create non-existent directories in build directory -$(BUILDDIR)/%/: - mkdir -p $@ install: $(addprefix install-,$(MODULES)) - install -m 0755 tools/villas.sh $(PREFIX)/bin/villas + install -m 0755 tools/villas.sh $(PREFIX)/bin/villas -clean: +clean: $(addprefix clean-,$(MODULES)) rm -rf $(BUILDDIR) docker: @@ -106,5 +109,11 @@ docker: doc: ( cat Doxyfile ; echo "OUTPUT_DIRECTORY=$(BUILD)/doc/" ) | doxygen - +# Create non-existent directories +%/: + mkdir -p $@ + +.SECONDEXPANSION: + -include $(wildcard $(BUILDDIR)/**/*.d) -$(foreach MODULE,$(MODULES),$(eval -include $(MODULE)/Makefile.inc)) \ No newline at end of file +-include $(addsuffix /Makefile.inc,$(MODULES)) diff --git a/lib/Makefile.inc b/lib/Makefile.inc index bab5f1181..edb3ad7c6 100644 --- a/lib/Makefile.inc +++ b/lib/Makefile.inc @@ -83,5 +83,5 @@ install-lib: install -m 0644 $(LIBS) $(PREFIX)/lib install -m 0755 -d $(PREFIX)/include/villas/ install -m 0644 include/villas/*.h $(PREFIX)/include/villas/ - echo "note: you may need to run 'ldconfig'" - echo "note: make sure $(PREFIX)/lib is in your /etc/ld.so.conf or $$LD_LIBRARY_PATH" + @echo "note: you may need to run 'ldconfig'" + @echo "note: make sure $(PREFIX)/lib is in your /etc/ld.so.conf or $$LD_LIBRARY_PATH" diff --git a/thirdparty/Makefile b/thirdparty/Makefile deleted file mode 100644 index 6150cdf09..000000000 --- a/thirdparty/Makefile +++ /dev/null @@ -1,49 +0,0 @@ -DEPS = libxil libconfig libnl libwebsockets criterion - -.PHONY: $(DEPS) all clean - -TMPDIR ?= $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) -PREFIX ?= /usr/local - -# Install all dependencies -all: $(DEPS) - -# Install & compile libconfig dependency -libconfig: - cd $@ && \ - rm -f lib/scanner.[ch] && \ - autoreconf && \ - ./configure --prefix=$(PREFIX) --disable-examples && \ - make install - -# Install & compile libnl3 dependency -libnl: - cd $@ && \ - ./autogen.sh && \ - ./configure --prefix=$(PREFIX) --disable-cli && \ - make install - -# Install & compile libwebsockets dependency -libwebsockets: - mkdir $@/build && cd $@/build && \ - cmake -DCMAKE_INSTALL_PREFIX:PATH=$(PREFIX) .. && \ - make install - -# Install & compile Criterion unittest framework -criterion: - mkdir $@/build && cd $@/build && \ - cmake -DCMAKE_INSTALL_PREFIX:PATH=$(PREFIX) .. && \ - make install - -# Install & compile Xilinx standalone drivers -libxil: - cd $@ && \ - make install - -clean: - for DEP in ${DEPS}; do \ - pushd $$DEP; \ - git checkout . ; \ - git clean -dxf $$DEP . ; \ - popd; \ - done diff --git a/thirdparty/Makefile.inc b/thirdparty/Makefile.inc new file mode 100644 index 000000000..702cbc2da --- /dev/null +++ b/thirdparty/Makefile.inc @@ -0,0 +1,34 @@ +DEPS_CMAKE = libwebsockets criterion jansson +DEPS_AUTOCONF = libnl libconfig libcurl + +DEPS = libxil $(DEPS_CMAKE) $(DEPS_AUTOCONF) + +.PHONY: $(DEPS) + +# Install all dependencies +thirdparty: $(DEPS) + +# Install & compile autotools based projects +$(DEPS_AUTOCONF): | $(BUILDDIR)/thirdparty/$$@/ + autoreconf -fi $(SRCDIR)/thirdparty/$@ + cd $(BUILDDIR)/thirdparty/$@ && $(SRCDIR)/thirdparty/$@/configure --prefix=$(PREFIX) && make install + +# Install & compile CMake based projects +$(DEPS_CMAKE): | $(BUILDDIR)/thirdparty/$$@/ + cmake -DCMAKE_INSTALL_PREFIX:PATH=$(PREFIX) \ + -H$(SRCDIR)/thirdparty/$@ \ + -B$(BUILDDIR)/thirdparty/$@ + make -C$(BUILDDIR)/thirdparty/$@ install + +# Install & compile Xilinx standalone drivers +libxil: | $(BUILDDIR)/thirdparty/$$@/ + make -C$(BUILDDIR)/thirdparty/$@ \ + -f$(SRCDIR)/thirdparty/$@/Makefile install + +clean-thirdparty: + for DEP in $(DEPS); do \ + pushd $$DEP; \ + git checkout . ; \ + git clean -dxf $$DEP . ; \ + popd; \ + done diff --git a/thirdparty/libxil/Makefile b/thirdparty/libxil/Makefile index 9bd95f430..ad8ff1af4 100644 --- a/thirdparty/libxil/Makefile +++ b/thirdparty/libxil/Makefile @@ -2,12 +2,16 @@ LIB = libxil.so PREFIX ?= /usr/local -SRCS = $(wildcard src/*.c) -SRCS += $(wildcard orig/*/src/*.c) -OBJS = $(SRCS:c=o) +SRCDIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) + +VPATH = $(SRCDIR) + +SRCS = $(wildcard $(SRCDIR)/src/*.c) +SRCS += $(wildcard $(SRCDIR)/orig/*/src/*.c) +OBJS = $(SRCS:$(SRCDIR)/%.c=%.o) CC = gcc -CFLAGS = -O3 -fPIC -Iinclude/xilinx -Iorig/common_v1_00_a/src -Wno-int-conversion -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast +CFLAGS = -O3 -fPIC -I$(SRCDIR)/include/xilinx -Iorig/common_v1_00_a/src -Wno-int-conversion -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast ifdef DEBUG CFLAGS += -DDEBUG -DXDEBUG_WARNING -g @@ -24,5 +28,13 @@ clean: install: $(LIB) mkdir -p $(PREFIX)/include/xilinx install -m 0644 $(LIB) $(PREFIX)/lib - install -m 0644 include/xilinx/*.h $(PREFIX)/include/xilinx - ldconfig + install -m 0644 $(SRCDIR)/include/xilinx/*.h $(PREFIX)/include/xilinx + @echo "note: you may need to run 'ldconfig'" + @echo "note: make sure $(PREFIX)/lib is in your /etc/ld.so.conf or $$LD_LIBRARY_PATH" + +.SECONDEXPANSION: + +$(OBJS): | $$(dir $$@) + +%/: + mkdir -p $@ \ No newline at end of file