Merge pull request #43 from antmicro/plugin_makefile_cleanup

Create common Makefile template to be used by all plugins
diff --git a/.travis/build-and-test.sh b/.travis/build-and-test.sh
index 928f1a3..e1cd5df 100755
--- a/.travis/build-and-test.sh
+++ b/.travis/build-and-test.sh
@@ -28,7 +28,7 @@
 echo 'Building plugins..' && echo -en 'travis_fold:start:script.build\\r'
 echo
 
-make plugins
+make plugins -j`nproc`
 
 echo
 echo -en 'travis_fold:end:script.build\\r'
@@ -40,7 +40,7 @@
 echo 'Installing plugins...' && echo -en 'travis_fold:start:script.build\\r'
 echo
 
-make install
+make install -j`nproc`
 
 echo
 echo -en 'travis_fold:end:script.build\\r'
@@ -52,7 +52,7 @@
 echo 'Testing...' && echo -en 'travis_fold:start:script.test\\r'
 echo
 
-make test
+make test -j`nproc`
 
 echo
 echo -en 'travis_fold:end:script.test\\r'
diff --git a/Makefile_plugin.common b/Makefile_plugin.common
new file mode 100644
index 0000000..6215cbb
--- /dev/null
+++ b/Makefile_plugin.common
@@ -0,0 +1,62 @@
+# This Makefile template is supposed to be included in each plugin's Makefile.
+# Plugin Makefiles need to specify the plugin's name and source files.
+# The plugin name is how the final shared object will be named.
+# This shared object can be imported to Yosys with `plugin -i` command.
+#
+# Below is an example of a plugin Makefile that uses this template:
+# NAME = plugin_name
+# SOURCES = source1.cc source2.cc
+# include ../Makefile_plugin.common
+#
+# For the above example the final plugin shared object will be named plugin_name.so.
+# In order to test the plugin it has to be copied to Yosys's shared folder.
+# The install target in this Makefile copies the plugins into the shared folder
+# of the Yosys installation that is found in the PATH.
+# This is needed because the shared folder is where Yosys will look for the
+# plugin object when `plugin -i` is called in Yosys's synthesis script.
+#
+# To add tests for the plugin the Makefile_test.common Makefile should be used.
+# Refer to Makefile_test.common to learn more details.
+#
+# Below is a directory structure which shows how the plugin sources and tests
+# should be laid out
+#
+# |-- Makefile_plugin.common
+# |-- Makefile_test.common
+# |-- example-plugin
+# |   |-- Makefile
+# |   |-- source1.cc
+# |   |-- source2.cc
+# |   |-- tests
+# |       |-- Makefile
+# |       |-- test_case_1
+# |       |   |-- test_case_1.tcl
+# |       |   |-- test_case_1.v
+# |       |   |-- test_case_1.golden.ext
+# |       |   |-- ...
+# |-- example2-plugin
+# |-- ...
+CXX = $(shell yosys-config --cxx)
+CXXFLAGS = $(shell yosys-config --cxxflags)
+LDFLAGS = $(shell yosys-config --ldflags)
+LDLIBS = $(shell yosys-config --ldlibs)
+PLUGINS_DIR = $(shell yosys-config --datdir)/plugins
+
+OBJS := $(SOURCES:cc=o)
+
+$(NAME).so: $(OBJS)
+	$(CXX) $(CXXFLAGS) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS)
+
+install_plugin: $(NAME).so
+	mkdir -p $(PLUGINS_DIR)
+	cp $< $(PLUGINS_DIR)/$<
+
+test:
+	$(MAKE) -C tests all
+
+.PHONY: install
+install: install_plugin
+
+clean:
+	rm -f *.d *.o *.so
+	$(MAKE) -C tests clean
diff --git a/fasm-plugin/Makefile b/fasm-plugin/Makefile
index dc171a4..71188e0 100644
--- a/fasm-plugin/Makefile
+++ b/fasm-plugin/Makefile
@@ -1,22 +1,4 @@
-CXX = $(shell yosys-config --cxx)
-CXXFLAGS = $(shell yosys-config --cxxflags)
-LDFLAGS = $(shell yosys-config --ldflags)
-LDLIBS = $(shell yosys-config --ldlibs)
-PLUGINS_DIR = $(shell yosys-config --datdir)/plugins
-
-OBJS = fasm.o
-
-fasm.so: $(OBJS)
-	$(CXX) $(CXXFLAGS) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS)
-
-.PHONY: install
-install: fasm.so
-	mkdir -p $(PLUGINS_DIR)
-	cp $< $(PLUGINS_DIR)/$<
-
-test:
-	$(MAKE) -C tests all
-
-clean:
-	rm -f *.d *.o fasm.so
+NAME = fasm
+SOURCES = fasm.cc
+include ../Makefile_plugin.common
 
diff --git a/get_count-plugin/Makefile b/get_count-plugin/Makefile
index 2c860b6..761d82c 100644
--- a/get_count-plugin/Makefile
+++ b/get_count-plugin/Makefile
@@ -1,24 +1,3 @@
-CXX = $(shell yosys-config --cxx)
-CXXFLAGS = $(shell yosys-config --cxxflags)
-LDFLAGS = $(shell yosys-config --ldflags)
-LDLIBS = $(shell yosys-config --ldlibs)
-PLUGINS_DIR = $(shell yosys-config --datdir)/plugins
-
 NAME = get_count
-OBJS = $(NAME).o
-
-$(NAME).so: $(OBJS)
-	$(CXX) $(CXXFLAGS) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS)
-
-.PHONY: install test
-
-install: $(NAME).so
-	mkdir -p $(PLUGINS_DIR)
-	cp $(NAME).so $(PLUGINS_DIR)/$(NAME).so
-
-test: $(NAME).so
-	$(MAKE) -C tests all
-
-clean:
-	rm -f *.d *.o *.so
-	$(MAKE) -C tests clean
+SOURCES = get_count.cc
+include ../Makefile_plugin.common
diff --git a/params-plugin/Makefile b/params-plugin/Makefile
index 1cce085..ec98ed1 100644
--- a/params-plugin/Makefile
+++ b/params-plugin/Makefile
@@ -1,25 +1,3 @@
-CXX = $(shell yosys-config --cxx)
-CXXFLAGS = $(shell yosys-config --cxxflags)
-LDFLAGS = $(shell yosys-config --ldflags)
-LDLIBS = $(shell yosys-config --ldlibs)
-PLUGINS_DIR = $(shell yosys-config --datdir)/plugins
-
-OBJS = params.o
-
-params.so: $(OBJS)
-	$(CXX) $(CXXFLAGS) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS)
-
-install_plugin: params.so
-	mkdir -p $(PLUGINS_DIR)
-	cp $< $(PLUGINS_DIR)/$<
-
-test:
-	$(MAKE) -C tests all
-
-.PHONY: install
-install: install_plugin
-
-clean:
-	rm -f *.d *.o params.so
-	$(MAKE) -C tests clean
-
+NAME = params
+SOURCES = params.cc
+include ../Makefile_plugin.common
diff --git a/ql-iob-plugin/Makefile b/ql-iob-plugin/Makefile
index 636ebfe..741d031 100644
--- a/ql-iob-plugin/Makefile
+++ b/ql-iob-plugin/Makefile
@@ -1,24 +1,3 @@
-CXX = $(shell yosys-config --cxx)
-CXXFLAGS = $(shell yosys-config --cxxflags)
-LDFLAGS = $(shell yosys-config --ldflags)
-LDLIBS = $(shell yosys-config --ldlibs)
-PLUGINS_DIR = $(shell yosys-config --datdir)/plugins
-
 NAME = ql-iob
-OBJS = $(NAME).o pcf_parser.cc pinmap_parser.cc
-
-$(NAME).so: $(OBJS)
-	$(CXX) $(CXXFLAGS) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS)
-
-.PHONY: install test
-
-install: $(NAME).so
-	mkdir -p $(PLUGINS_DIR)
-	cp $(NAME).so $(PLUGINS_DIR)/$(NAME).so
-
-test: $(NAME).so
-	$(MAKE) -C tests all
-
-clean:
-	rm -f *.d *.o *.so
-	$(MAKE) -C tests clean
+SOURCES = ql-iob.cc pcf_parser.cc pinmap_parser.cc
+include ../Makefile_plugin.common
diff --git a/sdc-plugin/Makefile b/sdc-plugin/Makefile
index 0c9461d..68b0917 100644
--- a/sdc-plugin/Makefile
+++ b/sdc-plugin/Makefile
@@ -1,25 +1,3 @@
-CXX = $(shell yosys-config --cxx)
-CXXFLAGS = $(shell yosys-config --cxxflags)
-LDFLAGS = $(shell yosys-config --ldflags)
-LDLIBS = $(shell yosys-config --ldlibs)
-PLUGINS_DIR = $(shell yosys-config --datdir)/plugins
-
-OBJS = buffers.o clocks.o propagation.o sdc.o sdc_writer.o set_false_path.o set_max_delay.o
-
-sdc.so: $(OBJS)
-	$(CXX) $(CXXFLAGS) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS)
-
-install_plugin: sdc.so
-	mkdir -p $(PLUGINS_DIR)
-	cp $< $(PLUGINS_DIR)/$<
-
-test:
-	$(MAKE) -C tests all
-
-.PHONY: install
-install: install_plugin
-
-clean:
-	rm -f *.d *.o *.so
-	$(MAKE) -C tests clean
-
+NAME = sdc
+SOURCES = buffers.cc clocks.cc propagation.cc sdc.cc sdc_writer.cc set_false_path.cc set_max_delay.cc
+include ../Makefile_plugin.common
diff --git a/selection-plugin/Makefile b/selection-plugin/Makefile
index 6c6f96f..5745bbb 100644
--- a/selection-plugin/Makefile
+++ b/selection-plugin/Makefile
@@ -1,25 +1,3 @@
-CXX = $(shell yosys-config --cxx)
-CXXFLAGS = $(shell yosys-config --cxxflags)
-LDFLAGS = $(shell yosys-config --ldflags)
-LDLIBS = $(shell yosys-config --ldlibs)
-PLUGINS_DIR = $(shell yosys-config --datdir)/plugins
-
-OBJS = selection.o
-
-selection.so: $(OBJS)
-	$(CXX) $(CXXFLAGS) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS)
-
-install_plugin: selection.so
-	mkdir -p $(PLUGINS_DIR)
-	cp $< $(PLUGINS_DIR)/$<
-
-test:
-	$(MAKE) -C tests all
-
-.PHONY: install
-install: install_plugin
-
-clean:
-	rm -f *.d *.o *.so
-	$(MAKE) -C tests clean
-
+NAME = selection
+SOURCES = selection.cc
+include ../Makefile_plugin.common
diff --git a/xdc-plugin/Makefile b/xdc-plugin/Makefile
index 10e3301..bd454a1 100644
--- a/xdc-plugin/Makefile
+++ b/xdc-plugin/Makefile
@@ -1,30 +1,10 @@
-CXX = $(shell yosys-config --cxx)
-CXXFLAGS = $(shell yosys-config --cxxflags)
-LDFLAGS = $(shell yosys-config --ldflags)
-LDLIBS = $(shell yosys-config --ldlibs)
-PLUGINS_DIR = $(shell yosys-config --datdir)/plugins
-
-OBJS = xdc.o
+NAME = xdc
+SOURCES = xdc.cc
+include ../Makefile_plugin.common
 VERILOG_MODULES = BANK.v
 
-xdc.so: $(OBJS)
-	$(CXX) $(CXXFLAGS) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS)
-
-install_plugin: xdc.so
-	mkdir -p $(PLUGINS_DIR)
-	cp $< $(PLUGINS_DIR)/$<
-
 install_modules: $(VERILOG_MODULES)
 	mkdir -p $(PLUGINS_DIR)/fasm_extra_modules/
 	cp $< $(PLUGINS_DIR)/fasm_extra_modules/$<
 
-test:
-	$(MAKE) -C tests all
-
-.PHONY: install
-install: install_modules install_plugin
-
-clean:
-	rm -f *.d *.o xdc.so
-	$(MAKE) -C tests clean
-
+install: install_modules