Merge pull request #656 from nlhintz/pull-request
[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:=$(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.ms=Bahasa Melayu (Malay)
27 LUCI_LANG.no=Norsk (Norwegian)
28 LUCI_LANG.pl=Polski (Polish)
29 LUCI_LANG.pt-br=Português do Brasil (Brazialian Portuguese)
30 LUCI_LANG.pt=Português (Portuguese)
31 LUCI_LANG.ro=Română (Romanian)
32 LUCI_LANG.ru=Русский (Russian)
33 LUCI_LANG.sk=Slovenčina (Slovak)
34 LUCI_LANG.sv=Svenska (Swedish)
35 LUCI_LANG.tr=Türkçe (Turkish)
36 LUCI_LANG.uk=украї́нська (Ukrainian)
37 LUCI_LANG.vi=Tiếng Việt (Vietnamese)
38 LUCI_LANG.zh-cn=普通话 (Chinese)
39 LUCI_LANG.zh-tw=臺灣華語 (Taiwanese)
40
41 # Submenu titles
42 LUCI_MENU.col=1. Collections
43 LUCI_MENU.mod=2. Modules
44 LUCI_MENU.app=3. Applications
45 LUCI_MENU.theme=4. Themes
46 LUCI_MENU.proto=5. Protocols
47 LUCI_MENU.lib=6. Libraries
48
49
50 PKG_NAME?=$(LUCI_NAME)
51
52 PKG_VERSION?=$(if $(DUMP),x,$(strip $(shell \
53 if svn info >/dev/null 2>/dev/null; then \
54 revision="svn-r$$(LC_ALL=C svn info | sed -ne 's/^Revision: //p')"; \
55 elif git log -1 >/dev/null 2>/dev/null; then \
56 revision="svn-r$$(LC_ALL=C git log -1 | sed -ne 's/.*git-svn-id: .*@\([0-9]\+\) .*/\1/p')"; \
57 if [ "$$revision" = "svn-r" ]; then \
58 set -- $$(git log -1 --format="%ct %h"); \
59 secs="$$(($$1 % 86400))"; \
60 yday="$$(date --utc --date="@$$1" "+%y.%j")"; \
61 revision="$$(printf 'git-%s.%05d-%s' "$$yday" "$$secs" "$$2")"; \
62 fi; \
63 else \
64 revision="unknown"; \
65 fi; \
66 echo "$$revision" \
67 )))
68
69 PKG_GITBRANCH?=$(if $(DUMP),x,$(strip $(shell \
70 variant="LuCI"; \
71 if git log -1 >/dev/null 2>/dev/null; then \
72 branch="$$(git symbolic-ref --short -q HEAD 2>/dev/null)"; \
73 if [ "$$branch" != "master" ]; then \
74 variant="LuCI $$branch branch"; \
75 else \
76 variant="LuCI Master"; \
77 fi; \
78 fi; \
79 echo "$$variant" \
80 )))
81
82 PKG_RELEASE?=1
83 PKG_INSTALL:=$(if $(realpath src/Makefile),1)
84 PKG_BUILD_DEPENDS += lua/host luci-base/host $(LUCI_BUILD_DEPENDS)
85 PKG_CONFIG_DEPENDS += CONFIG_LUCI_SRCDIET
86
87 PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
88
89 include $(INCLUDE_DIR)/package.mk
90
91 define Package/$(PKG_NAME)
92 SECTION:=luci
93 CATEGORY:=LuCI
94 SUBMENU:=$(if $(LUCI_MENU.$(LUCI_TYPE)),$(LUCI_MENU.$(LUCI_TYPE)),$(LUCI_MENU.app))
95 TITLE:=$(if $(LUCI_TITLE),$(LUCI_TITLE),LuCI $(LUCI_NAME) $(LUCI_TYPE))
96 DEPENDS:=$(LUCI_DEPENDS)
97 $(if $(LUCI_PKGARCH),PKGARCH:=$(LUCI_PKGARCH))
98 endef
99
100 ifneq ($(LUCI_DESCRIPTION),)
101 define Package/$(PKG_NAME)/description
102 $(strip $(LUCI_DESCRIPTION))
103 endef
104 endif
105
106 # Language selection for luci-base
107 ifeq ($(PKG_NAME),luci-base)
108 define Package/luci-base/config
109 config LUCI_SRCDIET
110 bool "Minify Lua sources"
111 default n
112
113 menu "Translations"$(foreach lang,$(LUCI_LANGUAGES),
114
115 config LUCI_LANG_$(lang)
116 tristate "$(shell echo '$(LUCI_LANG.$(lang))' | sed -e 's/^.* (\(.*\))$$/\1/') ($(lang))")
117
118 endmenu
119 endef
120 endif
121
122 define Build/Prepare
123 for d in luasrc htdocs root src; do \
124 if [ -d ./$$$$d ]; then \
125 mkdir -p $(PKG_BUILD_DIR)/$$$$d; \
126 $(CP) ./$$$$d/* $(PKG_BUILD_DIR)/$$$$d/; \
127 fi; \
128 done
129 $(call Build/Prepare/Default)
130 endef
131
132 define Build/Configure
133 endef
134
135 ifneq ($(wildcard ${CURDIR}/src/Makefile),)
136 MAKE_PATH := src/
137 MAKE_VARS += FPIC="$(FPIC)" LUCI_VERSION="$(PKG_VERSION)" LUCI_GITBRANCH="$(PKG_GITBRANCH)"
138
139 define Build/Compile
140 $(call Build/Compile/Default,clean compile)
141 endef
142 else
143 define Build/Compile
144 endef
145 endif
146
147 HTDOCS = /www
148 LUA_LIBRARYDIR = /usr/lib/lua
149 LUCI_LIBRARYDIR = $(LUA_LIBRARYDIR)/luci
150
151 define SrcDiet
152 $(FIND) $(1) -type f -name '*.lua' | while read src; do \
153 if LuaSrcDiet --noopt-binequiv -o "$$$$src.o" "$$$$src"; \
154 then mv "$$$$src.o" "$$$$src"; fi; \
155 done
156 endef
157
158 define SubstituteVersion
159 $(FIND) $(1) -type f -name '*.htm' | while read src; do \
160 $(SED) 's/<%# *\([^ ]*\)PKG_VERSION *%>/\1$(PKG_VERSION)/g' \
161 -e 's/"\(<%= *\(media\|resource\) *%>[^"]*\.\(js\|css\)\)"/"\1?v=$(PKG_VERSION)"/g' \
162 "$$$$src"; \
163 done
164 endef
165
166 define Package/$(PKG_NAME)/install
167 if [ -d $(PKG_BUILD_DIR)/luasrc ]; then \
168 $(INSTALL_DIR) $(1)$(LUCI_LIBRARYDIR); \
169 cp -pR $(PKG_BUILD_DIR)/luasrc/* $(1)$(LUCI_LIBRARYDIR)/; \
170 $(FIND) $(1)$(LUCI_LIBRARYDIR)/ -type f -name '*.luadoc' | $(XARGS) rm; \
171 $(if $(CONFIG_LUCI_SRCDIET),$(call SrcDiet,$(1)$(LUCI_LIBRARYDIR)/),true); \
172 $(call SubstituteVersion,$(1)$(LUCI_LIBRARYDIR)/); \
173 else true; fi
174 if [ -d $(PKG_BUILD_DIR)/htdocs ]; then \
175 $(INSTALL_DIR) $(1)$(HTDOCS); \
176 cp -pR $(PKG_BUILD_DIR)/htdocs/* $(1)$(HTDOCS)/; \
177 else true; fi
178 if [ -d $(PKG_BUILD_DIR)/root ]; then \
179 $(INSTALL_DIR) $(1)/; \
180 cp -pR $(PKG_BUILD_DIR)/root/* $(1)/; \
181 else true; fi
182 if [ -d $(PKG_BUILD_DIR)/src ]; then \
183 $(call Build/Install/Default) \
184 $(CP) $(PKG_INSTALL_DIR)/* $(1)/; \
185 else true; fi
186 endef
187
188 ifneq ($(LUCI_DEFAULTS),)
189 define Package/$(PKG_NAME)/postinst
190 [ -n "$${IPKG_INSTROOT}" ] || {$(foreach script,$(LUCI_DEFAULTS),
191 (. /etc/uci-defaults/$(script)) && rm -f /etc/uci-defaults/$(script))
192 exit 0
193 }
194 endef
195 endif
196
197
198 LUCI_BUILD_PACKAGES := $(PKG_NAME)
199
200 define LuciTranslation
201 define Package/luci-i18n-$(LUCI_BASENAME)-$(1)
202 SECTION:=luci
203 CATEGORY:=LuCI
204 TITLE:=$(PKG_NAME) - $(1) translation
205 HIDDEN:=1
206 DEFAULT:=LUCI_LANG_$(1)||(ALL&&m)
207 DEPENDS:=$(PKG_NAME)
208 PKGARCH:=all
209 endef
210
211 define Package/luci-i18n-$(LUCI_BASENAME)-$(1)/description
212 Translation for $(PKG_NAME) - $(LUCI_LANG.$(1))
213 endef
214
215 define Package/luci-i18n-$(LUCI_BASENAME)-$(1)/install
216 $$(INSTALL_DIR) $$(1)/etc/uci-defaults
217 echo "uci set luci.languages.$(subst -,_,$(1))='$(LUCI_LANG.$(1))'; uci commit luci" \
218 > $$(1)/etc/uci-defaults/luci-i18n-$(LUCI_BASENAME)-$(1)
219 $$(INSTALL_DIR) $$(1)$(LUCI_LIBRARYDIR)/i18n
220 $(foreach po,$(wildcard ${CURDIR}/po/$(1)/*.po), \
221 po2lmo $(po) \
222 $$(1)$(LUCI_LIBRARYDIR)/i18n/$(basename $(notdir $(po))).$(1).lmo;)
223 endef
224
225 define Package/luci-i18n-$(LUCI_BASENAME)-$(1)/postinst
226 [ -n "$$$${IPKG_INSTROOT}" ] || {
227 (. /etc/uci-defaults/luci-i18n-$(LUCI_BASENAME)-$(1)) && rm -f /etc/uci-defaults/luci-i18n-$(LUCI_BASENAME)-$(1)
228 exit 0
229 }
230 endef
231
232 LUCI_BUILD_PACKAGES += luci-i18n-$(LUCI_BASENAME)-$(1)
233
234 endef
235
236 $(foreach lang,$(LUCI_LANGUAGES),$(eval $(call LuciTranslation,$(lang))))
237 $(foreach pkg,$(LUCI_BUILD_PACKAGES),$(eval $(call BuildPackage,$(pkg))))