Create common Makefile template to be used by all plugins

Signed-off-by: Tomasz Michalak <tmichalak@antmicro.com>
diff --git a/Makefile_plugin.common b/Makefile_plugin.common
new file mode 100644
index 0000000..ab8d2f9
--- /dev/null
+++ b/Makefile_plugin.common
@@ -0,0 +1,26 @@
+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
+
+SOURCES := $(shell find -name '*.cc')
+OBJS := $(SOURCES:cc=o)
+NAME := $(patsubst %-plugin,%,$(notdir $(shell pwd)))
+
+$(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..321e17c 100644
--- a/fasm-plugin/Makefile
+++ b/fasm-plugin/Makefile
@@ -1,22 +1 @@
-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
-
+include ../Makefile_plugin.common
diff --git a/get_count-plugin/Makefile b/get_count-plugin/Makefile
index 2c860b6..321e17c 100644
--- a/get_count-plugin/Makefile
+++ b/get_count-plugin/Makefile
@@ -1,24 +1 @@
-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
+include ../Makefile_plugin.common
diff --git a/params-plugin/Makefile b/params-plugin/Makefile
index 1cce085..321e17c 100644
--- a/params-plugin/Makefile
+++ b/params-plugin/Makefile
@@ -1,25 +1 @@
-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
-
+include ../Makefile_plugin.common
diff --git a/ql-iob-plugin/Makefile b/ql-iob-plugin/Makefile
index 636ebfe..321e17c 100644
--- a/ql-iob-plugin/Makefile
+++ b/ql-iob-plugin/Makefile
@@ -1,24 +1 @@
-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
+include ../Makefile_plugin.common
diff --git a/sdc-plugin/Makefile b/sdc-plugin/Makefile
index 0c9461d..321e17c 100644
--- a/sdc-plugin/Makefile
+++ b/sdc-plugin/Makefile
@@ -1,25 +1 @@
-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
-
+include ../Makefile_plugin.common
diff --git a/selection-plugin/Makefile b/selection-plugin/Makefile
index 6c6f96f..321e17c 100644
--- a/selection-plugin/Makefile
+++ b/selection-plugin/Makefile
@@ -1,25 +1 @@
-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
-
+include ../Makefile_plugin.common
diff --git a/xdc-plugin/Makefile b/xdc-plugin/Makefile
index 10e3301..bf097a5 100644
--- a/xdc-plugin/Makefile
+++ b/xdc-plugin/Makefile
@@ -1,30 +1,8 @@
-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
+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