Skip to content
Snippets Groups Projects
Select Git revision
  • master default protected
  • 1.31
  • 4.15.4
  • 4.15.3
  • 4.15.2
  • 4.15.1
  • 4.15.0
  • 4.14.0
  • 4.13.1
  • 4.13.0
  • 4.12.0
  • 4.11.1
  • 4.11.0
  • 4.10.4
  • 4.10.3
  • 4.10.2
  • 4.10.1
  • 4.10.0
  • 4.9.0
  • 4.8.0
  • 4.7.0
  • 4.6.1
22 results

Makefile

Blame
  • Makefile 14.74 KiB
    #############################################################################################
    #############################################################################################
    ##
    ## PROJECT-DEFINITIONS
    ##
    #############################################################################################
    #############################################################################################
    
    COPYRIGHT_TEXT       := © 2021 schukai GmbH, Released under the AGPL 3.0 License.
    
    #############################################################################################
    #############################################################################################
    ##
    ## more general block with standard definitions
    ##
    #############################################################################################
    #############################################################################################
    
    # get Makefile directory name: http://stackoverflow.com/a/5982798/376773
    THIS_MAKEFILE_PATH:=$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
    THIS_DIR:=$(shell cd $(dir $(THIS_MAKEFILE_PATH));pwd)/
    THIS_MAKEFILE:=$(THIS_DIR)$(THIS_MAKEFILE_PATH)
    
    # colors
    BLACK        := $(shell tput -Txterm setaf 0)
    RED          := $(shell tput -Txterm setaf 1)
    GREEN        := $(shell tput -Txterm setaf 2)
    YELLOW       := $(shell tput -Txterm setaf 3)
    LIGHTPURPLE  := $(shell tput -Txterm setaf 4)
    PURPLE       := $(shell tput -Txterm setaf 5)
    BLUE         := $(shell tput -Txterm setaf 6)
    WHITE        := $(shell tput -Txterm setaf 7)
    RESET        := $(shell tput -Txterm sgr0)
    
    INFO    := $(GREEN)
    COMMENT := $(YELLOW)
    
    # Output control and standard outputs
    MARKER           := $(BLUE)[+]$(RESET)
    ERRORMARKER      := $(RED)[-]$(RESET)
    ## Deactivate the quite mode by overwriting the value with space
    
    ifndef DEBUG
        QUIET = @
    else
        QUIET = 
    endif
    
    ECHO             := @echo
    ECHOMARKER       := @echo "$(MARKER) $0"
    ECHOERRORMARKER  := @echo "$(ERRORMARKER) $0"
    
    # Use bash instead of sh
    ## Sets the shell used
    SHELL            =  bash
    
    # path and binaries
    AWK              := awk
    CP               := cp
    CD               := cd
    KILL             := /bin/kill
    M4               := m4
    MV               := mv
    RM               := rm -f
    MKDIR            := mkdir -p
    SED              := sed
    FIND             := find
    SORT             := sort
    TOUCH            := touch
    WGET             := wget
    CHMOD            := chmod
    RSYNC            := rsync
    DOCKER           := docker
    NPX              := npx
    AWS              := aws
    XARGS            := xargs
    GREP             := grep
    NPM              := npm
    
    # Executable Programs the Installed be have to
    EXECUTABLES = $(AWK) $(CP) $(KILL) $(M4) $(MV) rm mkdir $(SED) $(SORT) $(TOUCH) $(WGET) $(CHMOD) $(NPX) $(FIND) $(XARGS) $(GREP) $(NPM) 
    K := $(foreach exec,$(EXECUTABLES),\
            $(if $(shell which $(exec)),some string,$(error "Missing $(exec) in PATH; please install")))
    
    check_defined = \
        $(strip $(foreach 1,$1, \
            $(call __check_defined,$1,$(strip $(value 2)),$3)))
    __check_defined = \
        $(if $(value $1),, \
          $(ECHOERRORMARKER) $(if $2, $2, $1))
          
    
    #############################################################################################
    #############################################################################################
    ##
    ## DEFAULT-TARGETS
    ##
    #############################################################################################
    #############################################################################################
    
    # @see .PHONY https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html#Phony-Targets
    
    .DEFAULT_GOAL := help
    
    .PHONY: print
    print:
    	$(ECHO) "THIS_MAKEFILE:      $(THIS_MAKEFILE)"
    	$(ECHO) "THIS_MAKEFILE_PATH: $(THIS_MAKEFILE_PATH)"
    	$(ECHO) "THIS_DIR:           $(THIS_DIR)"
    
    # Add a comment to the public targets so that it appears
    # in this help Use two # characters for a help comment
    .PHONY: help
    help:
    	@printf "${COMMENT}Usage:${RESET}\n"
    	@printf " make [target] [arg=\"val\"...]\n\n"
    	@printf "${COMMENT}Available targets:${RESET}\n"
    	@awk '/^[a-zA-Z\-\_0-9\.@]+:/ { \
    		helpMessage = match(lastLine, /^## (.*)/); \
    		if (helpMessage) { \
    			helpCommand = substr($$1, 0, index($$1, ":")); \
    			helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
    			printf " ${INFO}%-22s${RESET} %s\n", helpCommand, helpMessage; \
    		} \
    	} \
    	{ lastLine = $$0 }' $(MAKEFILE_LIST)
    	@printf "\n${COMMENT}Available arguments:${RESET}\n\n"
    	@awk '/^(([a-zA-Z\-\_0-9\.@]+)\s=)/ { \
    		helpMessage = match(lastLine, /^## (.*)/); \
    		if (helpMessage) { \
    			helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
    			printf " ${INFO}%-22s${RESET} %s (Default: %s)\n", $$1, helpMessage, $$3; \
    		} \
    	} \
    	{ lastLine = $$0 }' $(MAKEFILE_LIST)
    
    .PHONY: variables
    ## Print all Variables
    variables:
    	@$(foreach v, $(.VARIABLES), $(if $(filter file,$(origin $(v))), $(info $(INFO)$(v)$(RESET)=$($(v))$(RESET))))
    
    #############################################################################################
    #############################################################################################
    ##
    ## DIRECTORIES
    ##
    #############################################################################################
    #############################################################################################
    
    SOURCE_PATH          :=   $(THIS_DIR)source/
    DIST_PATH            :=   $(THIS_DIR)dist/
    TEST_PATH            :=   $(THIS_DIR)test
    
    #############################################################################################
    #############################################################################################
    ##
    ## GIT-TARGETS
    ##
    #############################################################################################
    #############################################################################################
    
    ## Current Branch-Tag
    TAG := -
    
    ## Git Commit Message for git-push
    MESSAGE := current status
    
    .PHONY: git-branch
    ## create new branch (use TAG-Variable)
    git-branch:
    
    ifeq (, $(shell command -v uuidgen))
    	$(error "No uuidgen in PATH, consider doing apt-get install uuidgen")
    endif
    
    	export BRANCH="MONSTER/$(TAG)/$(shell uuidgen --random)" ; \
    	git checkout -b $${BRANCH} && \
    	RESULT=$$(git push origin $$BRANCH 2>&1) && \
        RESULT2=$$(git branch --set-upstream-to=origin/$$BRANCH $$BRANCH) && \
    	GITLABURL=$$(echo "$$RESULT" | tr '\n' '\#' | grep -o 'remote\:\s*https:\/\/gitlab\.schukai\.com[^ ]*' | cut -d " " -f2-9 | sed -e 's/^[ \t]*//') && \
    	google-chrome --profile-directory="Default" $$GITLABURL
    
    
    .PHONY: git-to-master
    ## git checkout master, fetch and merge
    git-to-master:
    	git checkout master && git fetch -pP && git merge
    
    
    .PHONY: git-push-to-server
    ## git push changes to server
    git-push-to-server:
    	git add -A
    	git commit -m"$(MESSAGE)"
    	git push
    
    .PHONY: git-push
    ## git create branch and push changes to server
    git-push: git-branch git-push-to-server
    
    #############################################################################################
    #############################################################################################
    ##
    ## DEFAULT-DEFINITIONS
    ##
    #############################################################################################
    #############################################################################################
    
    NODE_MODULES_DIR := $(THIS_DIR)node_modules/
    NODE_MODULES_BIN_DIR := $(NODE_MODULES_DIR).bin/
    
    BROWSERIFY    := $(NODE_MODULES_BIN_DIR)browserify
    BABEL         := $(NODE_MODULES_BIN_DIR)babel
    EXORCIST      := $(NODE_MODULES_BIN_DIR)exorcist
    UGLIFYJS      := $(NODE_MODULES_BIN_DIR)uglifyjs
    MOCHA         := $(NODE_MODULES_BIN_DIR)mocha
    JSDOC         := $(NODE_MODULES_BIN_DIR)jsdoc
    
    $(NODE_MODULES_DIR): $(THIS_DIR)package.json
    	$(QUIET) $(NPM) install 
    
    
    #############################################################################################
    ## UNTILITIES ###############################################################################
    #############################################################################################
    
    .PHONY: new-package
    ## init new package structure
    new-package:
    	$(QUIET) $(call check_defined, NAME, the variable NAME must be set)
    	$(QUIET) if [ ! -n "$(NAME)" ] ; then exit 3 ; fi
    	$(QUIET) $(MKDIR) $(THIS_DIR)packages/$(NAME)/
    	$(QUIET) $(CP) -r $(THIS_DIR)templates/* $(THIS_DIR)packages/$(NAME)/
    	$(QUIET) $(GREP) -rl '%%NAME%%' $(THIS_DIR)packages/$(NAME)/ | xargs sed -i 's/%%NAME%%/$(NAME)/g'
    	
    
    #############################################################################################
    ## MONSTER CORE #############################################################################
    #############################################################################################
    
    ## Name of the subpackage; ex. dom
    SUBPACKAGE = 
    
    ifneq ($(strip $(PACKAGE)),)
    SUBPACKAGE=-$(PACKAGE)
    endif
    
    MONSTER_CORE_DIR                 := $(THIS_DIR)packages/monster/
    
    MONSTER_DIR                      := $(THIS_DIR)packages/monster$(SUBPACKAGE)/
    MONSTER_SOURCE_DIR               := $(MONSTER_DIR)source/
    MONSTER_SOURCE_FILES             := $(shell find $(MONSTER_SOURCE_DIR) -name '*.js')
    MONSTER_DIST_DIR                 := $(MONSTER_DIR)dist/
    MONSTER_DIST_MODULE_DIR          := $(MONSTER_DIST_DIR)modules/
    MONSTER_DIST_MODULES_FILES       := $(subst $(MONSTER_SOURCE_DIR), $(MONSTER_DIST_MODULE_DIR), $(MONSTER_SOURCE_FILES))
    MONSTER_TEST_DIR                 := $(MONSTER_DIR)test/
    MONSTER_TEST_CASE_DIR            := $(MONSTER_TEST_DIR)cases/
    MONSTER_FILES_WITHVERSION        := $(shell grep -l -r -E "monster($(SUBPACKAGE))?@[0-9]\.[0-9]\.[0-9]" $(MONSTER_SOURCE_FILES))
    
    MONSTER_CORE_VERSION := $(shell jq -r ".version" $(MONSTER_CORE_DIR)package.json)
    MONSTER_VERSION      := $(shell jq -r ".version" $(MONSTER_DIR)package.json)
    LICENSE_C_COMMENT    := Monster $(MONSTER_VERSION), $(COPYRIGHT_TEXT)
    
    $(MONSTER_DIST_DIR): 
    	$(ECHOMARKER) "make directory $(MONSTER_DIST_DIR)"
    	$(QUIET) $(MKDIR) $(MONSTER_DIST_DIR)	
    
    
    .PHONY: version-monster
    version-monster: $(MONSTER_TEST_CASE_DIR)monster.js $(MONSTER_DIR)README.md $(MONSTER_FILES_WITHVERSION)
    
    $(MONSTER_TEST_CASE_DIR)monster.js: $(MONSTER_DIR)package.json $(MONSTER_CORE_DIR)package.json
    	$(ECHOMARKER) "write test/monster.js version $(MONSTER_VERSION)"
    	$(QUIET) $(AWK) -i inplace -v start='/**#@+' -v end='/**#@-*/' -v repl="    /**#@+ dont touch, replaced by make with package.json version */\n    monsterVersion = new Version('$(MONSTER_VERSION)')\n    /**#@-*/" '$$1 == start{del=2} $$1 == end{$$1 = repl; del=0} !del' $(MONSTER_TEST_CASE_DIR)monster.js
    
    $(MONSTER_DIR)README.md: $(MONSTER_DIR)package.json $(MONSTER_CORE_DIR)package.json
    	$(ECHOMARKER) "write README.md monster version $(MONSTER_VERSION) and monster core version $(MONSTER_CORE_VERSION)"
    	$(QUITE) $(SED) -i -E "s/(\/monster$(SUBPACKAGE)@)([0-9]+\.[0-9]+\.[0-9]+)\//\1$(MONSTER_VERSION)\//gi" $(MONSTER_DIR)README.md
    	$(QUITE) $(SED) -i -E "s/(\/monster@)([0-9]+\.[0-9]+\.[0-9]+)\//\1$(MONSTER_CORE_VERSION)\//gi" $(MONSTER_DIR)README.md
    
    $(MONSTER_FILES_WITHVERSION): $(MONSTER_DIR)package.json $(MONSTER_CORE_DIR)package.json
    	$(ECHOMARKER) "write $@ monster version $(MONSTER_VERSION) and monster core version $(MONSTER_CORE_VERSION)"
    	$(QUITE) $(SED) -i -E "s/(\/monster$(SUBPACKAGE)@)([0-9]+\.[0-9]+\.[0-9]+)\//\1$(MONSTER_VERSION)\//gi" $@
    	$(QUITE) $(SED) -i -E "s/(\/monster@)([0-9]+\.[0-9]+\.[0-9]+)\//\1$(MONSTER_CORE_VERSION)\//gi" $@
    	$(QUIET) $(AWK) -i inplace -v start='/**#@+' -v end='/**#@-*/' -v repl="    /**#@+ dont touch, replaced by make with package.json version */\n    monsterVersion = new Version('$(MONSTER_VERSION)')\n    /**#@-*/" '$$1 == start{del=2} $$1 == end{$$1 = repl; del=0} !del' $@
    
    $(MONSTER_DIST_DIR)monster.dev.js:  $(MONSTER_SOURCE_FILES)
    	$(QUIET) $(BROWSERIFY) $(MONSTER_SOURCE_DIR)monster.js -t [ babelify  --presets [ @babel/preset-env ] ] --debug | \
        	$(EXORCIST) $(MONSTER_DIST_DIR)monster.dev.js.map > $(MONSTER_DIST_DIR)monster.dev.js
    
    $(MONSTER_DIST_MODULES_FILES): $(MONSTER_SOURCE_FILES)
    	$(ECHOMARKER) "build monster modules $@"
    	$(QUIET) $(BABEL) --config-file $(THIS_DIR).babelrc.json --no-comments --out-file $@ --minified --presets @babel/preset-modules $(subst $(MONSTER_DIST_MODULE_DIR), $(MONSTER_SOURCE_DIR), $@)
    	$(QUIET) $(SED) -i '1 i /** $(LICENSE_C_COMMENT) */' $@
    
         
    $(MONSTER_DIST_DIR)monster.js: $(MONSTER_SOURCE_FILES)
    	$(ECHOMARKER) "build monster"
    	$(QUIET) echo "/** $(LICENSE_C_COMMENT) */" > $(MONSTER_DIST_DIR)monster.js
    	$(QUIET) $(BROWSERIFY) $(MONSTER_SOURCE_DIR)monster.js -t [ babelify --presets [ @babel/preset-env ] ] | $(UGLIFYJS) -- >> $(MONSTER_DIST_DIR)monster.js
    
    .PHONY: build-monster
    ## create packages
    build-monster: version-monster $(NODE_MODULES_DIR) $(MONSTER_DIST_DIR) $(MONSTER_DIST_DIR)monster.js $(MONSTER_DIST_DIR)monster.dev.js $(MONSTER_DIST_MODULES_FILES)
    
    .PHONY: test-browser-monster
    ## create test-browser-monster
    test-browser-monster:
    	$(ECHOMARKER) "create browser test and start chrome"
    	$(QUIET) $(FIND) $(MONSTER_TEST_CASE_DIR) -type f | $(SED) "s|^$(MONSTER_TEST_CASE_DIR)||" > $(MONSTER_TEST_DIR)web/import.js
    	$(QUIET) $(SED) -i 's|^|import "../cases/|' $(MONSTER_TEST_DIR)web/import.js
    	$(QUIET) $(SED) -i 's|$$|";|' $(MONSTER_TEST_DIR)web/import.js 
    	$(QUIET) $(SED) -i "1 i SharedArrayBuffer = ArrayBuffer;"  $(MONSTER_TEST_DIR)web/import.js
    	$(QUIET) $(SED) -i "1 i /** this file was created automatically by the make target test-browser-monster */"  $(MONSTER_TEST_DIR)web/import.js
    	$(QUIET) $(BROWSERIFY) $(MONSTER_TEST_DIR)web/import.js -t [ babelify --presets [ @babel/preset-env ] --plugins [ @babel/plugin-transform-runtime ]  ] > $(MONSTER_TEST_DIR)web/tests.js
    	$(QUIET) google-chrome --profile-directory="Default" $(MONSTER_TEST_DIR)web/test.html
    
    .PHONY: test-monster
    ## test library
    test-monster: build-monster
    	$(ECHOMARKER) "test monster"
    	$(QUITE) $(NPX) flow      
    	$(QUIET) $(MOCHA) --recursive $(MONSTER_TEST_CASE_DIR)**
    
    .PHONY: npm-publish-monster
    ## publish library to npm
    npm-publish-monster: build-monster
    	$(ECHOMARKER) "publish monster"
    	$(QUIET) $(CD) $(MONSTER_DIR) ; \
    		$(NPM) publish --access public ; \
    		$(CD) -
    
    .PHONY: clean-monster
    ## clean repos
    clean-monster:
    	$(QUITE) $(RM) --recursive $(MONSTER_DIST_DIR)
    
    #############################################################################################
    
    .PHONY: build
    ## clean 
    clean:
    	$(QUIET) $(RM) --recursive $(THIS_DIR)docs/
    	make clean-monster
    ## make clean-monster PACKAGE=dom
    
    .PHONY: build
    ## create all packages
    build:
    	make build-monster
    ## make build-monster PACKAGE=dom
    
    .PHONY: test
    ## test all packages
    test: 
    	make test-monster
    ## make test-monster PACKAGE=dom
    
    .PHONY: doc
    ## generate docs
    doc: test
    	$(ECHOMARKER) "create doc"
    	$(QUIET) $(JSDOC) --tutorials $(THIS_DIR)tutorials/ -c $(THIS_DIR)jsdoc.json $(THIS_DIR)README.md
    #	$(QUIET) $(GREP) -rl 'Documentation generated by' $(THIS_DIR)docs/ | $(XARGS) sed -i '/Documentation generated by/d'
    
    doc-2-aws: doc
    	$(QUIET) $(AWS) s3 cp --recursive $(THIS_DIR)docs/ s3://doc.alvine.io/en/oss/monster/snapshot/