-
Notifications
You must be signed in to change notification settings - Fork 48
/
Makefile_plugin.common
87 lines (73 loc) · 2.59 KB
/
Makefile_plugin.common
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# -*- Makefile -*-
# 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
# |-- ...
# Either find yosys in system and use its path or use the given path
YOSYS_PATH ?= $(realpath $(dir $(shell which yosys))/..)
# Find yosys-config, throw an error if not found
YOSYS_CONFIG = $(YOSYS_PATH)/bin/yosys-config
ifeq (,$(wildcard $(YOSYS_CONFIG)))
$(error "Didn't find 'yosys-config' under '$(YOSYS_PATH)'")
endif
CXX ?= $(shell $(YOSYS_CONFIG) --cxx)
CXXFLAGS = $(shell $(YOSYS_CONFIG) --cxxflags) #-DSDC_DEBUG
LDFLAGS = $(shell $(YOSYS_CONFIG) --ldflags)
LDLIBS = $(shell $(YOSYS_CONFIG) --ldlibs)
EXTRA_FLAGS ?=
DATA_DIR = $(DESTDIR)$(shell $(YOSYS_CONFIG) --datdir)
PLUGINS_DIR = $(DATA_DIR)/plugins
OBJS := $(patsubst %.cc,%.o,$(SOURCES))
DEPS ?=
$(PLUGINS_DIR):
@mkdir -p $@
all: $(NAME).so
$(OBJS): %.o: %.cc $(DEPS)
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(EXTRA_FLAGS) -c -o $@ $(filter %.cc, $^)
$(NAME).so: $(OBJS)
$(CXX) $(CXXFLAGS) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS)
../pmgen.py:
@$(MAKE) -C .. pmgen.py
install_plugin: $(NAME).so | $(PLUGINS_DIR)
install -D $< $(PLUGINS_DIR)/$<
test:
@$(MAKE) -C tests all
.PHONY: install
install: install_plugin
clean:
rm -f *.d *.o *.so
$(MAKE) -C tests clean