juci/Makefile

183 lines
5.7 KiB
Makefile
Raw Normal View History

DIRS-y:=juci
PLUGINS-y:=
ifneq ($(MODULE),)
BIN:=$(MODULE)/bin
else
BIN:=bin
endif
BACKEND_BIN_DIR:=$(BIN)/usr/lib/ubus/juci/
CODE_DIR:=$(BIN)/www/js
CSS_DIR:=$(BIN)/www/css
PO_DIR:=po/templates/
TARGETS:=
PHONY:=debug release clean prepare node_modules
2015-09-18 19:43:14 +08:00
CP:=cp -Rp
Q:=@
2015-09-18 19:43:14 +08:00
INSTALL_DIR:=mkdir -p
all: release
-include Makefile.local
define Plugin/Default
2015-09-18 19:43:14 +08:00
CODE_LOAD:=10
JAVASCRIPT-y:=
TEMPLATES-y:=
STYLES-y:=
endef
define BuildDir-y
$(eval $(call Plugin/Default))
2015-09-18 19:43:14 +08:00
$(eval CODE_LOAD:=50) # same as LOAD, LOAD is deprecated
$(eval TPL_LOAD:=90)
2015-09-18 19:43:14 +08:00
$(eval STYLE_LOAD:=50)
$(eval JAVASCRIPT-y:=src/*.js src/pages/*.js src/widgets/*.js)
$(eval TEMPLATES-y:=src/widgets/*.html src/pages/*.html)
$(eval STYLES-y:=src/css/*.css)
$(eval PLUGIN_DIR:=$(2))
$(eval -include $(2)/Makefile)
$(eval $(Plugin/$(1)))
$(eval TARGETS+=$(1)-install $(2)/po/template.pot $(CODE_DIR)/$(CODE_LOAD)-$(1).js $(CODE_DIR)/$(TPL_LOAD)-$(1).tpl.js $(CSS_DIR)/$(STYLE_LOAD)-$(1).css)
$(eval JAVASCRIPT_$(1):=$(wildcard $(addprefix $(2)/,$(JAVASCRIPT-y))))
$(eval TEMPLATES_$(1):=$(wildcard $(addprefix $(2)/,$(TEMPLATES-y))))
$(eval STYLES_$(1):=$(wildcard $(addprefix $(2)/,$(STYLES-y))))
PHONY += $(1)-install
2015-09-18 19:43:14 +08:00
$(CODE_DIR)/$(CODE_LOAD)-$(1).js: $(JAVASCRIPT_$(1))
@echo -e "\033[0;33m[JS]\t$(1) -> $$@\033[m"
2015-09-18 19:43:14 +08:00
@#echo " * $$^"
@echo "" > $$@
2015-09-18 19:43:14 +08:00
$(Q)if [ "" != "$$^" ]; then for file in $$^; do cat $$$$file >> $$@; echo "" >> $$@; done; fi
$(CSS_DIR)/$(STYLE_LOAD)-$(1).css: $(STYLES_$(1))
@echo -e "\033[0;33m[CSS]\t$(1) -> $$@\033[m"
@#echo " * $$(STYLES_$(1))"
@echo "" > $$@
2015-09-18 19:43:14 +08:00
$(Q)if [ "" != "$$^" ]; then for file in $$^; do cat $$$$file >> $$@; echo "" >> $$@; done; fi
$(CODE_DIR)/$(TPL_LOAD)-$(1).tpl.js: $(TEMPLATES_$(1))
@echo -e "\033[0;33m[HTML]\t$(1) -> $$@\033[m"
2015-09-18 19:43:14 +08:00
@#echo " * $$^"
@echo "" > $$@
2015-09-18 19:43:14 +08:00
$(Q)if [ "" != "$$^" ]; then ./juci-build-tpl-cache $$^ $$@; fi
$(2)/po/template.pot: $(JAVASCRIPT_$(1)) $(TEMPLATES_$(1))
@echo -e "\033[0;33m[POT]\t$(1) -> $$@\033[m"
@mkdir -p "$$(dir $$@)"
@echo "" > $$@
$(Q)if [ "" != "$$^" ]; then ./scripts/extract-strings $$^ > $$@; msguniq $$@ > $$@.tmp; mv $$@.tmp $$@; fi
@echo "" >> $$@
@for file in `find $(2)/src/pages/ -name "*.html"`; do PAGE=$$$${file%%.*}; echo -e "# $$$$file \nmsgid \"$$$$(basename $$$$PAGE)-title\"\nmsgstr \"\"\n" >> $$@; done
@for file in `find $(2)/src/pages/ -name "*.html"`; do PAGE=$$$${file%%.*}; echo -e "# $$$$file \nmsgid \"menu-$$$$(basename $$$$PAGE)-title\"\nmsgstr \"\"\n" >> $$@; done
$(1)-install:
2015-09-18 19:43:14 +08:00
$(call Plugin/$(1)/install,$(BIN))
$(Q)if [ -d $(2)/ubus ]; then $(CP) $(2)/ubus/* $(BACKEND_BIN_DIR); fi
$(Q)if [ -d $(2)/service ]; then $(CP) $(2)/service/* $(BIN)/usr/lib/ubus-services/; fi
@-chmod +x $(BACKEND_BIN_DIR)/*
$(Q)if [ -f $(2)/menu.json ]; then $(CP) $(2)/menu.json $(BIN)/usr/share/rpcd/menu.d/$(1).json; fi
$(Q)if [ -f $(2)/access.json ]; then $(CP) $(2)/access.json $(BIN)/usr/share/rpcd/acl.d/$(1).json; fi
endef
ifneq ($(MODULE),)
$(eval $(call BuildDir-y,$(notdir $(MODULE)),$(MODULE)))
else
$(eval $(call BuildDir-$(CONFIG_PACKAGE_juci),juci,$(CURDIR)/juci/))
$(foreach th,$(wildcard plugins/*),$(eval $(call BuildDir-$(CONFIG_PACKAGE_$(notdir $(th))),$(notdir $(th)),$(CURDIR)/plugins/$(notdir $(th)))))
$(foreach th,$(wildcard themes/*),$(eval $(call BuildDir-$(CONFIG_PACKAGE_$(notdir $(th))),$(notdir $(th)),$(CURDIR)/themes/$(notdir $(th)))))
endif
2015-06-03 17:13:45 +08:00
UBUS_MODS:=
2015-07-06 20:54:13 +08:00
export CC:=$(CC)
2015-07-01 06:19:27 +08:00
export CFLAGS:=$(CFLAGS)
2015-06-03 17:13:45 +08:00
2015-09-04 18:25:38 +08:00
ifeq ($(DESTDIR),)
DESTDIR:=/
endif
ifeq ($(CONFIG_PACKAGE_juci-igmpinfo),y)
UBUS_MODS += backend/igmpinfo
endif
ifeq ($(CONFIG_PACKAGE_juci-ubus-core),y)
2015-07-21 19:25:37 +08:00
UBUS_MODS += backend/juci-core
2015-07-21 18:41:52 +08:00
endif
.cleaned: Makefile Makefile.local Makefile.basic
@make clean
@touch .cleaned
Makefile.local: ;
prepare: .cleaned
@echo "======= JUCI CONFIG ========="
@echo "TARGETS: $(TARGETS)"
@echo "BACKEND: $(UBUS_MODS)"
@echo "DIRS: $(DIRS-y)"
@echo "MODULE: $(MODULE)"
@./bootstrap.sh
@mkdir -p $(PO_DIR)
@mkdir -p $(BIN)/www/js/
@mkdir -p $(BIN)/www/css/
2015-09-18 19:43:14 +08:00
@mkdir -p $(BIN)/usr/share/lua/
@mkdir -p $(BIN)/usr/share/rpcd/menu.d/
@mkdir -p $(BIN)/usr/share/rpcd/acl.d/
@mkdir -p $(BACKEND_BIN_DIR)
2015-10-05 23:29:30 +08:00
@mkdir -p $(BIN)/usr/lib/ubus-services/
@mkdir -p $(BIN)/etc/hotplug.d/
2015-06-24 05:16:03 +08:00
2015-06-24 04:24:21 +08:00
node_modules: package.json
npm install --production
2015-09-18 21:12:21 +08:00
release: prepare $(TARGETS) node_modules $(UBUS_MODS)
@echo "======= JUCI BUILD =========="
@./juci-compile $(BIN)
@if [ "$(CONFIG_PACKAGE_juci)" = "y" ]; then ./juci-update $(BIN)/www RELEASE; fi
2015-06-24 04:24:21 +08:00
2015-09-18 21:12:21 +08:00
debug: prepare $(TARGETS) $(UBUS_MODS)
@echo -e "\033[0;33m [GRUNT] $@ \033[m"
@grunt
@echo -e "\033[0;33m [UPDATE] $@ \033[m"
@./juci-update $(BIN)/www DEBUG
2015-06-03 17:13:45 +08:00
DOCS_MD:= README.md $(wildcard juci/docs/*.md docs/*.md plugins/**/docs/*.md) docs/juci.md
DOCS_HTML:= $(patsubst %.md,%.html,$(DOCS_MD)) docs/juci.html
PHONY+=docs
docs: $(DOCS_HTML)
@echo -e "\033[0;33m [DOCS] $@ $^ \033[m"
2015-10-22 06:23:18 +08:00
@mkdir -p manual/js
@mkdir -p manual/css
@cp juci/src/lib/js/bootstrap.min.js manual/js/
@cp juci/src/lib/css/bootstrap.min.css manual/css/
@# remove juci generated md file
@rm -f docs/juci.md
docs/juci.md: $(wildcard plugins/**/docs/*.md)
@# for md in $^; do sed -i "/%PLUGINS_TOC%/a [$$(head -n 1 $$md)]($$(basename $${md%.md}))" docs/juci.md; done
@./scripts/build_docs .
%.html: %.md
@echo -e "\033[0;33m[DOC]: $^\033[m"
@mkdir -p manual
2015-10-22 06:23:18 +08:00
@ronn --pipe -f $^ > docs/.tmp.ronn
@cp docs/page.html.tpl docs/.tmp
@sed -i -e '/%CONTENT%/r docs/.tmp.ronn' -e 's///' docs/.tmp
@mv docs/.tmp $(addprefix manual/,$(notdir $@))
@rm -f docs/.tmp.ronn
2015-09-04 18:23:57 +08:00
install:
$(INSTALL_DIR) $(BIN)/usr/bin/
@cp juci-update $(BIN)/usr/bin/
2015-09-28 21:17:02 +08:00
@cp -Rp $(BIN)/* $(DESTDIR)
2015-09-04 18:23:57 +08:00
.PHONY: $(PHONY) $(UBUS_MODS)
$(UBUS_MODS):
2015-06-24 04:24:21 +08:00
@echo "Building UBUS module $@"
2015-07-01 06:19:27 +08:00
@echo "CFLAGS: $(CFLAGS)"
2015-09-28 21:17:02 +08:00
@make -i -C $@ clean
@make -C $@
@cp -Rp $@/build/* $(BIN)/
2015-06-03 17:13:45 +08:00
clean:
2015-06-24 05:16:03 +08:00
rm -rf ./bin