source: trunk/plugins/plugins.mk @ 517

Last change on this file since 517 was 517, checked in by amain, 6 years ago

Merge contrib branch 340:516. Main features added:

  • updated plugin architecture
  • improved patch system
  • bitten continous integration support
  • sever build fixed over time to remain in sync with OpenWrt
File size: 4.8 KB
Line 
1# DebWrt - Debian on Embedded devices
2#
3# Copyright (C) 2011-2012 Johan van Zoomeren <amain@debwrt.net>
4#
5# Copyright (C) 2012 Elliott Mitchell <ehem+debwrt@m5p.com>
6#       2012-10-06  merged OpenWRT patching with DebWRT's patching of OpenWRT
7#       2012-10-06  added ability to include Makefile from plugins
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
22PLUGINS_AVAILABLE:=$(shell find $(PLUGINS_DIR) \
23                                -maxdepth 1 \
24                                -mindepth 1 \
25                                -type d ! \
26                                -name '.*' \
27                                -printf '%f\n') 
28PLUGIN_CHOICE_BEGIN = \
29choice\n\
30   prompt \"Target Plugin\"\n\
31   default PLUGIN_NONE \n\
32   help\n\
33     Select a target plugin\n\
34\nconfig PLUGIN_NONE\n\
35  bool\n\
36  prompt \"None\"\n\
37
38PLUGIN_CHOICE_END = \
39endchoice\n
40
41PLUGIN_CONFIG_LINE = \
42config PLUGIN_$${plugin_up}\n\
43  bool\n\
44  prompt \"$${plugin}\"\n\
45  deselect HAS_SUBTARGETS\n\
46  deselect DO_CONF_TARGETS\n\
47
48
49# Register target
50#
51# $(1): target
52# $(2): prerequisite(s)
53define register_target
54$(1): $(2)
55endef
56
57# Register target for plugin
58#
59# $(1): plugin name
60# $(2): debwrt target
61#
62# Check if CONFIG_PLUGIN_<plugin_name>_ENABLE =  y
63# Check if CONFIG_PLUGIN_<plugin_name>_UUID   == PLUGIN_<plugin_name>_UUID
64#
65# Register target
66#
67# - make plugin specific target a prerequitite of the DebWrt target
68# - when DebWrt target is rebuild, first the plugin specic target is rebuild
69#
70# target: plugin/<pluging_name>/target
71#
72# or on UUID mismatch:
73#
74# target: plugin/<plugin_name>/uuid-error
75define register_plugin_target
76ifeq ($(CONFIG_PLUGIN_$(call upper,$(1))_ENABLE),y)
77ifeq ($(call qstrip,$(CONFIG_PLUGIN_$(call upper,$(1))_UUID)),$(PLUGIN_$(call upper,$(1))_UUID))
78REGISTERED_TARGETS+=plugin/$(1)/$(2)
79ifeq ($(2),plugins/check)
80$(call register_target,$(2),plugin/$(call lower,$(1))/uuid-success)
81else
82$(call register_target,$(2),plugin/$(call lower,$(1))/$(2))
83endif
84else
85$(call register_target,$(2),plugin/$(call lower,$(1))/uuid-error)
86endif
87endif
88endef
89
90# Call-back for plugins: register plugin targets and mandatory plugins/check target
91#
92# $(1): plugin name
93# $(2): list of targets
94#
95define register
96$(eval $(foreach target,$(2) plugins/check,$(eval $(call register_plugin_target,$(1),$(target)))))
97endef
98
99# Include a plugin
100#
101# $(1): plugin name
102#
103# Define plugin specific variables, before including and
104# evaluating plugins/<plugin_name>/plugin.mk.
105define include_plugin
106ifneq ($(1),)
107PLUGIN_NAME:=$(call upper,$(1))
108plugin_name:=$(call lower,$(1))
109target=plugins/$(call lower,$(1))
110include $(PLUGINS_DIR)/$(call lower,$(1))/plugin.mk
111endif
112endef
113
114# Inlcude plugin.mk for each plugin
115$(foreach plugin,$(PLUGINS_AVAILABLE),$(eval $(call include_plugin,$(plugin))))
116
117plugin/%/uuid-success:
118ifeq ($(findstring plugins/check,$(MAKECMDGOALS)),plugins/check)
119        @echo "Version verified for plugin $(call upper,$*)"
120        @echo "  Configured UUID: $(PLUGIN_$(call upper,$*)_UUID) (Config.in)"
121        @echo "  Plugin UUID    : $(CONFIG_PLUGIN_$(call upper,$*)_UUID) (plugin.mk)"
122else
123        @true
124endif
125
126plugin/%/uuid-error:
127        @echo "Version mismatch for plugin $(call upper,$*)"
128        @echo "  Configured UUID: $(PLUGIN_$(call upper,$*)_UUID) (Config.in)"
129        @echo "  Plugin UUID    : $(CONFIG_PLUGIN_$(call upper,$*)_UUID) (plugin.mk)"
130ifneq ($(findstring plugins/check,$(MAKECMDGOALS)),plugins/check)
131        @exit 1
132endif
133
134plugins/generate-config:
135        @mkdir $(TMP_DIR)
136        @/bin/echo -e "$(PLUGIN_CHOICE_BEGIN)" >$(TMP_DIR)/plugins-generated.in
137        @for plugin in $(PLUGINS_AVAILABLE); \
138        do \
139          plugin_up=$$(echo $${plugin} | tr [a-z] [A-Z]); \
140          echo "Generating config for plugin: $${plugin_up}"; \
141          /bin/echo -e "$(PLUGIN_CONFIG_LINE)" >>$(TMP_DIR)/plugins-generated.in; \
142        done
143        @/bin/echo -e "$(PLUGIN_CHOICE_END)" >>$(TMP_DIR)/plugins-generated.in
144        touch $@
145
146plugins/list:
147        @for plugin in $(PLUGINS_AVAILABLE); \
148        do \
149           echo $${plugin}; \
150        done
151
152plugins/targets/registered:
153        @for target in $(REGISTERED_TARGETS); \
154        do \
155           echo $${target}; \
156        done
157
158plugins/enabled/list:
159        @echo $(PLUGINS_ENABLED)
160        @for plugin in $(PLUGINS_ENABLED); \
161        do \
162           echo $${plugin}; \
163        done
164
165plugins/clean:
166
167plugins/check:
168
169test:
170        @echo "Test Plugins"
171
172register:
173        @echo "Register plugins"
174
175
176.PHONY: plugins/list \
177        plugins/targets/registered \
178        plugins/enabled/list \
179        plugin/%/uuid-error \
180        plugin/%/uuid-success \
181        plugins/clean \
182        plugins/check
183
Note: See TracBrowser for help on using the repository browser.