From 5c387434bcf5b46e340fb9b849e205d9e887f60c Mon Sep 17 00:00:00 2001
From: Aaron Cuevas Lopez <aacuelo@teleco.upv.es>
Date: Wed, 21 Sep 2016 19:00:45 -0700
Subject: [PATCH] Add common lib build for Linux

---
 Builds/Linux/Makefile.plugins                 | 25 +++++++----
 .../CommonLibs/OpenEphysHDF5Lib/Makefile      | 41 +++++++++++++++++++
 Source/Plugins/KWIKFormat/Makefile            |  2 +-
 3 files changed, 59 insertions(+), 9 deletions(-)
 create mode 100644 Source/Plugins/CommonLibs/OpenEphysHDF5Lib/Makefile

diff --git a/Builds/Linux/Makefile.plugins b/Builds/Linux/Makefile.plugins
index 6928dcd0e..49c671718 100644
--- a/Builds/Linux/Makefile.plugins
+++ b/Builds/Linux/Makefile.plugins
@@ -5,13 +5,14 @@
 DEPFLAGS := $(if $(word 2, $(TARGET_ARCH)), , -MMD)
 
 PLUGIN_DIR := ../../Source/Plugins
+COMMON_DIR := ../../Source/Plugins/CommonLibs
 
 ifndef CONFIG
   CONFIG=Debug
 endif
 
 ifeq ($(CONFIG),Debug)
-  BINDIR := $(CURDIR)/build/intermediate/Debug
+  BINDIR := $(CURDIR)/build
   LIBDIR := $(CURDIR)/build/intermediate/Debug
   OBJDIR := $(CURDIR)/build/intermediate/plugins/Debug
   OUTDIR := $(CURDIR)/build/plugins
@@ -27,12 +28,12 @@ ifeq ($(CONFIG),Debug)
   LDDEPS :=
   RESFLAGS :=  -D "LINUX=1" -D "DEBUG=1" -D "_DEBUG=1" -D "JUCER_LINUX_MAKE_7346DA2A=1" -D "JUCE_APP_VERSION=0.3.5" -D "JUCE_APP_VERSION_HEX=0x305" -I /usr/include -I /usr/include/freetype2 -I $(CURDIR)/../../Source/Plugins/Headers
 
-  CLEANCMD = rm -rf $(OUTDIR)/* $(OBJDIR)
+  CLEANCMD = rm -rf $(OUTDIR)/* $(OBJDIR) $(BINDIR)/$(addsuffix .so,$(notdir $(COMMONDIRS)))
 endif
 
 ifeq ($(CONFIG),Release)
   BINDIR := $(CURDIR)/build
-  LIBDIR := $(CURDIR)/build
+  LIBDIR := $(CURDIR)/build/intermediate/Release
   OBJDIR := $(CURDIR)/build/intermediate/plugins/Release
   OUTDIR := $(CURDIR)/build/plugins
 
@@ -47,16 +48,21 @@ ifeq ($(CONFIG),Release)
   LDDEPS1 :=
   RESFLAGS :=  -D "LINUX=1" -D "NDEBUG=1" -D "JUCER_LINUX_MAKE_7346DA2A=1" -D "JUCE_APP_VERSION=0.3.5" -D "JUCE_APP_VERSION_HEX=0x305" -I /usr/include -I /usr/include/freetype2 -I $(CURDIR)/../../Source/Plugins/Headers
 
-  CLEANCMD = rm -rf $(OUTDIR)/* $(OBJDIR)
+  CLEANCMD = rm -rf $(OUTDIR)/* $(OBJDIR) $(BINDIR)/$(addsuffix .so,$(notdir $(COMMONDIRS)))
 endif
 
+LIB_PREFIX :=
+
 export
 
 SUBDIRS := $(wildcard $(PLUGIN_DIR)/*)
+COMMONDIRS := $(wildcard $(COMMON_DIR)/*)
 
-.PHONY: clean all notify $(SUBDIRS) $(notdir $(SUBDIRS))
+.PHONY: clean all notify $(SUBDIRS) $(notdir $(SUBDIRS)) clean/$(notdir $(SUBDIRS)) libs $(COMMONDIRS)
 
-all: notify $(SUBDIRS)
+all: notify libs $(SUBDIRS)
+
+libs: $(COMMONDIRS)
 
 notify:
 	@echo "Building Open-Ephys Plugins"
@@ -65,7 +71,9 @@ PLUGINNAME=$(shell echo $@ | rev | cut -d'/' -f-1 | rev)
 
 # if there are a .jucer file in the plugin folder - try to find Makefile in the Source/ folder
 $(SUBDIRS): CXXFLAGS += -D "OEPLUGIN" -I $(CURDIR)/../../Source/Plugins/CommonLibs
-$(SUBDIRS):
+$(COMMONDIRS): OUTDIR := $(BINDIR)
+$(COMMONDIRS): LIB_PREFIX := lib
+$(SUBDIRS) $(COMMONDIRS):
 	@if [ -f $@/*.jucer ] && ([ -f $@/Source/Makefile ]); then \
 		echo "Found jucer project for" $(PLUGINNAME) "..."; \
 		$(MAKE) -C $@/Source clean ; \
@@ -74,6 +82,7 @@ $(SUBDIRS):
 		$(MAKE) -C $@ ; fi \
 	fi
 
+
 .SECONDEXPANSION:
 $(notdir $(SUBDIRS)): $$(PLUGIN_DIR)/$$@
 
@@ -81,7 +90,7 @@ clean:
 	@echo Cleaning open-ephys plugins
 	@$(CLEANCMD)
 
-clean/$(notdir $(SUBDIRS)):
+$(addprefix clean/,$(notdir $(SUBDIRS))):
 	@echo Cleaning $(notdir $@)
 	$(MAKE) -C $(PLUGIN_DIR)/$(notdir $@) clean
 
diff --git a/Source/Plugins/CommonLibs/OpenEphysHDF5Lib/Makefile b/Source/Plugins/CommonLibs/OpenEphysHDF5Lib/Makefile
new file mode 100644
index 000000000..78241817a
--- /dev/null
+++ b/Source/Plugins/CommonLibs/OpenEphysHDF5Lib/Makefile
@@ -0,0 +1,41 @@
+
+LIBNAME := $(notdir $(CURDIR))
+OBJDIR := $(OBJDIR)/$(LIBNAME)
+TARGET := $(LIBNAME).so
+
+CXXFLAGS := $(CXXFLAGS) -I/usr/include/hdf5/serial -I/usr/local/hdf5/include
+LDFLAGS := $(LDFLAGS) -L/usr/lib/x86_64-linux-gnu/hdf5/serial -L/usr/local/hdf5/lib -lhdf5 -lhdf5_cpp
+
+SRC_DIR := ${shell find ./ -type d -print}
+VPATH := $(SOURCE_DIRS)
+
+SRC := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.cpp))
+OBJ := $(addprefix $(OBJDIR)/,$(notdir $(SRC:.cpp=.o)))
+
+BLDCMD := $(CXX) -shared -o $(OUTDIR)/$(TARGET) $(OBJ) $(LDFLAGS) $(RESOURCES) $(TARGET_ARCH)
+
+VPATH = $(SRC_DIR)
+
+.PHONY: objdir
+
+$(OUTDIR)/$(TARGET): objdir $(OBJ)
+	-@mkdir -p $(BINDIR)
+	-@mkdir -p $(LIBDIR)
+	-@mkdir -p $(OUTDIR)
+	@echo "Building $(TARGET)"
+	@$(BLDCMD)
+
+$(OBJDIR)/%.o : %.cpp
+	@echo "Compiling $<"
+	@$(CXX) $(CXXFLAGS) -o "$@" -c "$<"
+	
+	
+objdir:
+	-@mkdir -p $(OBJDIR)
+
+clean:
+	@echo "Cleaning $(LIBNAME)"
+	-@rm -rf $(OBJDIR)
+	-@rm -f $(OUTDIR)/$(TARGET)
+
+-include $(OBJ:%.o=%.d)
diff --git a/Source/Plugins/KWIKFormat/Makefile b/Source/Plugins/KWIKFormat/Makefile
index 78241817a..3b6cc54f6 100644
--- a/Source/Plugins/KWIKFormat/Makefile
+++ b/Source/Plugins/KWIKFormat/Makefile
@@ -4,7 +4,7 @@ OBJDIR := $(OBJDIR)/$(LIBNAME)
 TARGET := $(LIBNAME).so
 
 CXXFLAGS := $(CXXFLAGS) -I/usr/include/hdf5/serial -I/usr/local/hdf5/include
-LDFLAGS := $(LDFLAGS) -L/usr/lib/x86_64-linux-gnu/hdf5/serial -L/usr/local/hdf5/lib -lhdf5 -lhdf5_cpp
+LDFLAGS := $(LDFLAGS) -L/usr/lib/x86_64-linux-gnu/hdf5/serial -L/usr/local/hdf5/lib -lhdf5 -lhdf5_cpp -l:OpenEphysHDF5Lib.so
 
 SRC_DIR := ${shell find ./ -type d -print}
 VPATH := $(SOURCE_DIRS)
-- 
GitLab