Merge pull request #2285 from dengqf6/luci-ssl-nginx
[project/luci.git] / luci.mk
1 #
2 # Copyright (C) 2008-2015 The LuCI Team <luci@lists.subsignal.org>
3 #
4 # This is free software, licensed under the Apache License, Version 2.0 .
5 #
6
7 LUCI_NAME?=$(notdir ${CURDIR})
8 LUCI_TYPE?=$(word 2,$(subst -, ,$(LUCI_NAME)))
9 LUCI_BASENAME?=$(patsubst luci-$(LUCI_TYPE)-%,%,$(LUCI_NAME))
10 LUCI_LANGUAGES:=$(sort $(filter-out templates,$(notdir $(wildcard ${CURDIR}/po/*))))
11 LUCI_DEFAULTS:=$(notdir $(wildcard ${CURDIR}/root/etc/uci-defaults/*))
12 LUCI_PKGARCH?=$(if $(realpath src/Makefile),,all)
13
14 # Language code titles
15 LUCI_LANG.ca=Català (Catalan)
16 LUCI_LANG.cs=Čeština (Czech)
17 LUCI_LANG.de=Deutsch (German)
18 LUCI_LANG.el=Ελληνικά (Greek)
19 LUCI_LANG.en=English
20 LUCI_LANG.es=Español (Spanish)
21 LUCI_LANG.fr=Français (French)
22 LUCI_LANG.he=עִבְרִית (Hebrew)
23 LUCI_LANG.hu=Magyar (Hungarian)
24 LUCI_LANG.it=Italiano (Italian)
25 LUCI_LANG.ja=日本語 (Japanese)
26 LUCI_LANG.ko=한국어 (Korean)
27 LUCI_LANG.ms=Bahasa Melayu (Malay)
28 LUCI_LANG.no=Norsk (Norwegian)
29 LUCI_LANG.pl=Polski (Polish)
30 LUCI_LANG.pt-br=Português do Brasil (Brazialian Portuguese)
31 LUCI_LANG.pt=Português (Portuguese)
32 LUCI_LANG.ro=Română (Romanian)
33 LUCI_LANG.ru=Русский (Russian)
34 LUCI_LANG.sk=Slovenčina (Slovak)
35 LUCI_LANG.sv=Svenska (Swedish)
36 LUCI_LANG.tr=Türkçe (Turkish)
37 LUCI_LANG.uk=Українська (Ukrainian)
38 LUCI_LANG.vi=Tiếng Việt (Vietnamese)
39 LUCI_LANG.zh-cn=中文 (Chinese)
40 LUCI_LANG.zh-tw=臺灣華語 (Taiwanese)
41
42 # Submenu titles
43 LUCI_MENU.col=1. Collections
44 LUCI_MENU.mod=2. Modules
45 LUCI_MENU.app=3. Applications
46 LUCI_MENU.theme=4. Themes
47 LUCI_MENU.proto=5. Protocols
48 LUCI_MENU.lib=6. Libraries
49
50
51 PKG_NAME?=$(LUCI_NAME)
52
53 PKG_VERSION?=$(if $(DUMP),x,$(strip $(shell \
54 if svn info >/dev/null 2>/dev/null; then \
55 revision="svn-r$$(LC_ALL=C svn info | sed -ne 's/^Revision: //p')"; \
56 elif git log -1 >/dev/null 2>/dev/null; then \
57 revision="svn-r$$(LC_ALL=C git log -1 | sed -ne 's/.*git-svn-id: .*@\([0-9]\+\) .*/\1/p')"; \
58 if [ "$$revision" = "svn-r" ]; then \
59 set -- $$(git log -1 --format="%ct %h" --abbrev=7); \
60 secs="$$(($$1 % 86400))"; \
61 yday="$$(date --utc --date="@$$1" "+%y.%j")"; \
62 revision="$$(printf 'git-%s.%05d-%s' "$$yday" "$$secs" "$$2")"; \
63 fi; \
64 else \
65 revision="unknown"; \
66 fi; \
67 echo "$$revision" \
68 )))
69
70 PKG_GITBRANCH?=$(if $(DUMP),x,$(strip $(shell \
71 variant="LuCI"; \
72 if git log -1 >/dev/null 2>/dev/null; then \
73 branch="$$(git branch --remote --verbose --no-abbrev --contains 2>/dev/null | \
74 sed -rne 's|^[^/]+/([^ ]+) [a-f0-9]{40} .+$$|\1|p' | head -n1)"; \
75 if [ "$$branch" != "master" ]; then \
76 variant="LuCI $$branch branch"; \
77 else \
78 variant="LuCI Master"; \
79 fi; \
80 fi; \
81 echo "$$variant" \
82 )))
83
84 PKG_RELEASE?=1
85 PKG_INSTALL:=$(if $(realpath src/Makefile),1)
86 PKG_BUILD_DEPENDS += lua/host luci-base/host $(LUCI_BUILD_DEPENDS)
87 PKG_CONFIG_DEPENDS += CONFIG_LUCI_SRCDIET CONFIG_LUCI_JSMIN
88
89 PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
90
91 include $(INCLUDE_DIR)/package.mk
92
93 define Package/$(PKG_NAME)
94 SECTION:=luci
95 CATEGORY:=LuCI
96 SUBMENU:=$(if $(LUCI_MENU.$(LUCI_TYPE)),$(LUCI_MENU.$(LUCI_TYPE)),$(LUCI_MENU.app))
97 TITLE:=$(if $(LUCI_TITLE),$(LUCI_TITLE),LuCI $(LUCI_NAME) $(LUCI_TYPE))
98 DEPENDS:=$(LUCI_DEPENDS)
99 $(if $(LUCI_EXTRA_DEPENDS),EXTRA_DEPENDS:=$(LUCI_EXTRA_DEPENDS))
100 $(if $(LUCI_PKGARCH),PKGARCH:=$(LUCI_PKGARCH))
101 endef
102
103 ifneq ($(LUCI_DESCRIPTION),)
104 define Package/$(PKG_NAME)/description
105 $(strip $(LUCI_DESCRIPTION))
106 endef
107 endif
108
109 # Language selection for luci-base
110 ifeq ($(PKG_NAME),luci-base)
111 define Package/luci-base/config
112 config LUCI_SRCDIET
113 bool "Minify Lua sources"
114 default n
115
116 config LUCI_JSMIN
117 bool "Minify JavaScript sources"
118 default y
119
120 menu "Translations"$(foreach lang,$(LUCI_LANGUAGES),
121
122 config LUCI_LANG_$(lang)
123 tristate "$(shell echo '$(LUCI_LANG.$(lang))' | sed -e 's/^.* (\(.*\))$$/\1/') ($(lang))")
124
125 endmenu
126 endef
127 endif
128
129 define Build/Prepare
130 for d in luasrc htdocs root src; do \
131 if [ -d ./$$$$d ]; then \
132 mkdir -p $(PKG_BUILD_DIR)/$$$$d; \
133 $(CP) ./$$$$d/* $(PKG_BUILD_DIR)/$$$$d/; \
134 fi; \
135 done
136 $(call Build/Prepare/Default)
137 endef
138
139 define Build/Configure
140 endef
141
142 ifneq ($(wildcard ${CURDIR}/src/Makefile),)
143 MAKE_PATH := src/
144 MAKE_VARS += FPIC="$(FPIC)" LUCI_VERSION="$(PKG_VERSION)" LUCI_GITBRANCH="$(PKG_GITBRANCH)"
145
146 define Build/Compile
147 $(call Build/Compile/Default,clean compile)
148 endef
149 else
150 define Build/Compile
151 endef
152 endif
153
154 HTDOCS = /www
155 LUA_LIBRARYDIR = /usr/lib/lua
156 LUCI_LIBRARYDIR = $(LUA_LIBRARYDIR)/luci
157
158 define SrcDiet
159 $(FIND) $(1) -type f -name '*.lua' | while read src; do \
160 if LUA_PATH="$(STAGING_DIR_HOSTPKG)/lib/lua/5.1/?.lua" luasrcdiet --noopt-binequiv -o "$$$$src.o" "$$$$src"; \
161 then mv "$$$$src.o" "$$$$src"; fi; \
162 done
163 endef
164
165 define JsMin
166 $(FIND) $(1) -type f -name '*.js' | while read src; do \
167 if jsmin < "$$$$src" > "$$$$src.o"; \
168 then mv "$$$$src.o" "$$$$src"; fi; \
169 done
170 endef
171
172 define SubstituteVersion
173 $(FIND) $(1) -type f -name '*.htm' | while read src; do \
174 $(SED) 's/<%# *\([^ ]*\)PKG_VERSION *%>/\1$(PKG_VERSION)/g' \
175 -e 's/"\(<%= *\(media\|resource\) *%>[^"]*\.\(js\|css\)\)"/"\1?v=$(PKG_VERSION)"/g' \
176 "$$$$src"; \
177 done
178 endef
179
180 define Package/$(PKG_NAME)/install
181 if [ -d $(PKG_BUILD_DIR)/luasrc ]; then \
182 $(INSTALL_DIR) $(1)$(LUCI_LIBRARYDIR); \
183 cp -pR $(PKG_BUILD_DIR)/luasrc/* $(1)$(LUCI_LIBRARYDIR)/; \
184 $(FIND) $(1)$(LUCI_LIBRARYDIR)/ -type f -name '*.luadoc' | $(XARGS) rm; \
185 $(if $(CONFIG_LUCI_SRCDIET),$(call SrcDiet,$(1)$(LUCI_LIBRARYDIR)/),true); \
186 $(call SubstituteVersion,$(1)$(LUCI_LIBRARYDIR)/); \
187 else true; fi
188 if [ -d $(PKG_BUILD_DIR)/htdocs ]; then \
189 $(INSTALL_DIR) $(1)$(HTDOCS); \
190 cp -pR $(PKG_BUILD_DIR)/htdocs/* $(1)$(HTDOCS)/; \
191 $(if $(CONFIG_LUCI_JSMIN),$(call JsMin,$(1)$(HTDOCS)/),true); \
192 else true; fi
193 if [ -d $(PKG_BUILD_DIR)/root ]; then \
194 $(INSTALL_DIR) $(1)/; \
195 cp -pR $(PKG_BUILD_DIR)/root/* $(1)/; \
196 else true; fi
197 if [ -d $(PKG_BUILD_DIR)/src ]; then \
198 $(call Build/Install/Default) \
199 $(CP) $(PKG_INSTALL_DIR)/* $(1)/; \
200 else true; fi
201 endef
202
203 ifneq ($(LUCI_DEFAULTS),)
204 define Package/$(PKG_NAME)/postinst
205 [ -n "$${IPKG_INSTROOT}" ] || {$(foreach script,$(LUCI_DEFAULTS),
206 (. /etc/uci-defaults/$(script)) && rm -f /etc/uci-defaults/$(script))
207 exit 0
208 }
209 endef
210 endif
211
212
213 LUCI_BUILD_PACKAGES := $(PKG_NAME)
214
215 define LuciTranslation
216 define Package/luci-i18n-$(LUCI_BASENAME)-$(1)
217 SECTION:=luci
218 CATEGORY:=LuCI
219 TITLE:=$(PKG_NAME) - $(1) translation
220 HIDDEN:=1
221 DEFAULT:=LUCI_LANG_$(1)||(ALL&&m)
222 DEPENDS:=$(PKG_NAME)
223 PKGARCH:=all
224 endef
225
226 define Package/luci-i18n-$(LUCI_BASENAME)-$(1)/description
227 Translation for $(PKG_NAME) - $(LUCI_LANG.$(1))
228 endef
229
230 define Package/luci-i18n-$(LUCI_BASENAME)-$(1)/install
231 $$(INSTALL_DIR) $$(1)/etc/uci-defaults
232 echo "uci set luci.languages.$(subst -,_,$(1))='$(LUCI_LANG.$(1))'; uci commit luci" \
233 > $$(1)/etc/uci-defaults/luci-i18n-$(LUCI_BASENAME)-$(1)
234 $$(INSTALL_DIR) $$(1)$(LUCI_LIBRARYDIR)/i18n
235 $(foreach po,$(wildcard ${CURDIR}/po/$(1)/*.po), \
236 po2lmo $(po) \
237 $$(1)$(LUCI_LIBRARYDIR)/i18n/$(basename $(notdir $(po))).$(1).lmo;)
238 endef
239
240 define Package/luci-i18n-$(LUCI_BASENAME)-$(1)/postinst
241 [ -n "$$$${IPKG_INSTROOT}" ] || {
242 (. /etc/uci-defaults/luci-i18n-$(LUCI_BASENAME)-$(1)) && rm -f /etc/uci-defaults/luci-i18n-$(LUCI_BASENAME)-$(1)
243 exit 0
244 }
245 endef
246
247 LUCI_BUILD_PACKAGES += luci-i18n-$(LUCI_BASENAME)-$(1)
248
249 endef
250
251 $(foreach lang,$(LUCI_LANGUAGES),$(eval $(call LuciTranslation,$(lang))))
252 $(foreach pkg,$(LUCI_BUILD_PACKAGES),$(eval $(call BuildPackage,$(pkg))))