diff --git a/Makefile b/Makefile index 0cf327b..f53cbf6 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,8 @@ # ======================= # # >> Created by Ryuu Mitsuki +# Recommended Make version: 4.4.*+ + # WARNING! Don't change this version manually, it's autogenerated! VERSION := 1.1.0 PREFIX := [jmatrix] @@ -16,10 +18,8 @@ FLAGS ?= # and the `FLAGS` variable automatically added linter flags "-Xlint" LINT ?= -ifeq "$(LINT)" "true" - FLAGS := -Xlint -Xdoclint -endif +ALL_RULES := all compile package clean cleanbin cleandocs # Path variables PYTHON_PATH := ./src/main/python/ @@ -30,12 +30,18 @@ CLASSES_PATH := ./target/classes/ PACKAGE_PATH := com/mitsuki/jmatrix/ MANIFEST := META-INF/MANIFEST.MF +MAKE_USAGE_TXC := docs/makefile-usage.txcc +MAKE_USAGE_TXT := docs/makefile-usage.txt +DOCS_PATH := docs/jmatrix + SOURCES_LIST := target/generated-list/sourceFiles.lst CLASSES_LIST := target/generated-list/outputFiles.lst SRCFILES := $(shell find $(SOURCES_PATH) -type f -name '*.java') ifneq "$(wildcard $(CLASSES_PATH))" "" CLSFILES := $(shell find $(CLASSES_PATH) -type f -name '*.class') +else + CLSFILES := endif jar := $(OUTPUT_PATH)jmatrix-$(VERSION).jar @@ -56,7 +62,7 @@ endif ifndef VERBOSE MAKE_VERBOSE := else -ifeq ($(VERBOSE),true) +ifeq "$(VERBOSE)" "true" MAKE_VERBOSE := true else MAKE_VERBOSE := @@ -82,56 +88,49 @@ endif endif -# This to avoid 'Make' options treated as file -.PHONY: all compile package clean +# Get the index of "build-docs" rule on command line args +ifeq "$(filter build-docs,$(MAKECMDGOALS))" "build-docs" +ifdef VERBOSE + CMD = bash bin/get_argument.sh -v $(MAKECMDGOALS) -s build-docs +else + CMD = bash bin/get_argument.sh $(MAKECMDGOALS) -s build-docs +endif + +BUILD_DOCS_ARG := $(shell $(CMD)) + + +# Check if the "build-docs"'s index is not at first argument, +# then it will returns error +ifneq "$(BUILD_DOCS_ARG)" "-1" +ifneq "$(words $(MAKECMDGOALS))" "1" +$(error $(PREFIX) 'build-docs' rule must be a standalone rule) +endif +endif + +endif + +# This to prevent all `Make`'s rules treated as file by default +.PHONY: $(ALL_RULES) all: $(info [Makefile-jmatrix]) - @echo "Options:" - @echo " * compile - Compile the program." - @echo " * package - Create archived package (jar) of compiled program." - @echo " WARNING: Program need to be compiled first!" - @echo " * clean - Clean all of compiled program and created jar." - @echo " * cleanbin - Clean all generated class files only." - @echo " * check-verbose - Check the verbose status." - @echo " * usage - Print the example usages for build the project." - @echo "" - @echo "Additional Options:" - @echo " * Activating verbose output" - @echo "" - @echo " \`export VERBOSE=true\`" - @echo "" - @echo " Or:" - @echo "" - @echo " \`make [options] VERBOSE=true\`" - @echo "" - @echo "" - @echo " * Include source files while packaging" - @echo "" - @echo " \`make [options] INCLUDE-SRC=true\`" - @echo "" - @echo "" - @echo " * Invoke the linter" - @echo "" - @echo " \`make [options] LINT=true\`" - @echo "" - @echo "" - @echo " * Add some options or flags to compiler" - @echo "" - @echo " \`make [options] FLAGS[=]\`" - @echo "" - @echo "Usage:" - @echo " $$ make [options] [...] [arguments]" - @echo " $$ make [options] VERBOSE[=] INCLUDE-SRC[=]" - @echo " $$ make [options] (LINT[=] | FLAGS[=])" - @echo "" - @echo "Tips:" - @echo " - Combine the options, Makefile can understand multiple rules." - @echo "" - @echo "Author:" - @echo " Ryuu Mitsuki" +# This check whether the user using Bash as shell environment or else +# On Bash shell it will have OSTYPE as built-in variable +ifneq "$$OSTYPE" "" +ifneq "$(wildcard $(MAKE_USAGE_TXC))" "$(MAKE_USAGE_TXC)" + $(error $(PREFIX) File "$(MAKE_USAGE_TXC)" is missing) +endif +# The color coded only works on Bash shell, on CMD neither Powershell +# it would not display the prefixes color codes. + @cat $(MAKE_USAGE_TXC) +else +ifneq "$(wildcard $(MAKE_USAGE_TXT))" "$(MAKE_USAGE_TXT)" + $(error $(PREFIX) File "$(MAKE_USAGE_TXT)" is missing) +endif + @cat $(MAKE_USAGE_TXT) +endif check-verbose: ifneq "$(MAKE_VERBOSE)" "true" @@ -146,11 +145,22 @@ compile: $(SOURCES_LIST) $(SRCFILES) @echo "" @echo ">> [ COMPILE PROGRAM ] <<" - $(if $(shell [ $(LINT) = "true" ] && echo 1),\ - @echo "$(PREFIX) Linter is ACTIVATED."\ - ) +ifeq "$(LINT)" "true" + @echo "$(PREFIX) Linter is ACTIVATED." + $(eval LINT_FLAGS := -Xlint -Xdoclint) +else + $(eval LINT_FLAGS :=) +endif + +ifeq "$(MAKE_VERBOSE)" "true" + @echo "$(PREFIX) Verbose output is ACTIVATED." + $(eval VERBOSE_FLAGS := -verbose) +else + $(eval VERBOSE_FLAGS :=) +endif + @echo "$(PREFIX) Compiling all source files..." - @$(CC) -d $(CLASSES_PATH) @$< $(FLAGS) + @$(CC) -d $(CLASSES_PATH) @$< $(LINT_FLAGS) $(VERBOSE_FLAGS) $(FLAGS) @echo "$(PREFIX) Successfully compiled all source files." $(eval HAS_COMPILED := $(wildcard $(CLASSES_PATH))) @@ -210,28 +220,131 @@ endif @echo "SAVED IN: \"$(jar)\"" +build-docs: $(SOURCES_LIST) + @echo +ifndef VERBOSE + @echo "$(PREFIX) Verbose mode: QUIET" + $(eval VERBOSE_FLAGS := -quiet) +else + +# Check whether the VERBOSE's value is "true" +ifeq "$(VERBOSE)" "true" + @echo "$(PREFIX) Verbose mode: NORMAL" + $(eval VERBOSE_FLAGS :=) +endif + +# Check whether the VERBOSE's value is "all" +ifeq "$(VERBOSE)" "all" + @echo "$(PREFIX) Verbose mode: ALL" + $(eval VERBOSE_FLAGS := -verbose) +endif + +# Check whether the VERBOSE's value is "false" +ifeq "$(VERBOSE)" "false" + @echo "$(PREFIX) Verbose mode: QUIET" + $(eval VERBOSE_FLAGS := -quiet) +endif + +# If VERBOSE's value does not match with (all, true, false) +# then the verbose mode would be override to NORMAL mode. +ifneq "$(shell \ + [ $(VERBOSE) = 'all' ] || [ $(VERBOSE) = 'true' ] || [ $(VERBOSE) != 'false' ] && echo 'false'\ +)" "false" + @echo "$(PREFIX) Verbose mode: NORMAL" + $(eval VERBOSE_FLAGS :=) +endif +endif + + @echo + @echo ">> [ BUILD DOCS ] <<" + @echo "$(PREFIX) Build the JMatrix docs..." + @javadoc -author -version -d $(DOCS_PATH) -Xdoclint \ + @$^ --release 11 -windowtitle "JMatrix" -doctitle "JMatrix v$(VERSION)" \ + -tag param -tag return -tag throws -tag warning:a:"Warning:" -tag author -tag license:a:"License:" -tag see \ + -Xdoclint/package:-com.mitsuki.jmatrix.core \ + -bottom "Copyright (c) 2023 Ryuu Mitsuki." \ + -group "Core Packages" "com.mitsuki.jmatrix*:com.mitsuki.jmatrix.core" \ + -group "Utilities Packages" "com.mitsuki.jmatrix.util" $(VERBOSE_FLAGS) $(FLAGS) + + @echo "$(PREFIX) Successfully build the JMatrix docs." + @echo + @echo "SAVED IN: \"$(DOCS_PATH)/\"" + clean: +# Check whether the verbose is activated +ifeq "$(MAKE_VERBOSE)" "true" + $(eval VERBOSE_FLAGS := -v) +else + $(eval VERBOSE_FLAGS :=) +endif + @echo "" @echo ">> [ CLEAN WORKING DIRECTORY ] <<" - @echo "$(PREFIX) Cleaning the \"$(OUTPUT_PATH)\" directory recursively..." - @-rm -r $(OUTPUT_PATH) + @echo "$(PREFIX) Cleaning the \"$(subst ./,,$(OUTPUT_PATH))\" directory recursively..." + + @-rm -r $(OUTPUT_PATH) $(VERBOSE_FLAGS) + @echo "$(PREFIX) Classes directory cleaned up." + +# Clean the temporary directory "tmp/", only if exist + $(if $(shell [ -d tmp/ ] && echo 1),\ + @echo && echo "$(PREFIX) Cleaning the \"tmp/\" directory recursively..." &&\ + rm -r tmp $(VERBOSE_FLAGS) &&\ + echo "$(PREFIX) Temporary directory cleaned up."\ + ) + +# Clean the generated HTML pages directory "docs/jmatrix/", only if exist + $(if $(shell [ -d $(DOCS_PATH) ] && echo 1),\ + @echo && echo "$(PREFIX) Cleaning the \"$(DOCS_PATH)/\" directory recursively..." &&\ + rm -r $(DOCS_PATH) $(VERBOSE_FLAGS) &&\ + echo "$(PREFIX) Generated HTML pages cleaned up."\ + ) @echo "" @echo "$(PREFIX) All cleaned up." cleanbin: +# Check whether the verbose is activated +ifeq "$(MAKE_VERBOSE)" "true" + $(eval VERBOSE_FLAGS := -v) +else + $(eval VERBOSE_FLAGS :=) +endif + @echo "" - @echo ">> [ CLEAN ONLY CLASS OBJECTS ] <<" - @echo "$(PREFIX) Cleaning the class files only..." - @-rm -r $(CLASSES_PATH) + @echo ">> [ CLEAN ONLY THE CLASS OBJECTS ] <<" + @echo "$(PREFIX) Cleaning the class files..." + @-rm -r $(CLASSES_PATH) $(VERBOSE_FLAGS) @echo "" @echo "$(PREFIX) All cleaned up." - $(if $(shell test -e $(jar) && echo "1"),\ + $(if $(shell test -f $(jar) && echo "1"),\ @echo 'File "$(subst ./,,$(jar))" is still exists.',\ @echo 'File "$(subst ./,,$(jar))" is missing or has been deleted.'\ ) +cleandocs: +# Check whether the verbose is activated +ifeq "$(MAKE_VERBOSE)" "true" + $(eval VERBOSE_FLAGS := -v) +else + $(eval VERBOSE_FLAGS :=) +endif + + $(info ) + $(info >> [ CLEAN ONLY THE GENERATED DOCS ] <<) + +# Check whether the `docs/jmatrix` directory is exist +ifeq "$(shell [ -d $(DOCS_PATH) ] && echo 1)" "1" + @echo "$(PREFIX) Cleaning the generated HTML pages..." + @-rm -r $(DOCS_PATH) $(VERBOSE_FLAGS) +else +# Send warning message if the directory does not exist + $(warning $(PREFIX) Directory does not exist: "$(DOCS_PATH)") +endif + + @echo + @echo "$(PREFIX) All cleaned up." + $(SOURCES_LIST): $(wildcard $(PYTHON_PATH)*.py) @echo "" @@ -248,7 +361,7 @@ endif usage: - @echo "[Makefile Usage]" + @echo "[Makefile Basic Usage]" @echo "" @echo "Parameters:" diff --git a/bin/get_argument.sh b/bin/get_argument.sh new file mode 100755 index 0000000..fe5597c --- /dev/null +++ b/bin/get_argument.sh @@ -0,0 +1,117 @@ +#!/usr/bin/bash + +################################################################# +# This script processes command-line arguments and searches +# for a specific argument in the list. It supports an +# optional "-s" switch to specify a specific argument. +# The script outputs the index of the desired argument in +# the modified argument list. +################################################################# + +# Usage function to display instructions on how to use the script +usage() { + echo -e "\033[1mUSAGE\033[0m" + echo " $ . get_argument.sh [OPTIONS] ARGUMENTS" + echo " $ bash get_argument.sh [OPTIONS] ARGUMENTS" + echo -e "\n\033[1mDESCRIPTION\033[0m" + echo " This script processes command-line arguments and searches " + echo " for a specific argument in the list, then outputs the index" + echo " of the desired argument." + echo -e "\n\033[1mOPTIONS\033[0m" + echo " -s ARG Specify a specific argument to search for." + echo " -v, --verbose Enable verbose output (saved in \"tmp/\")." + echo " -h, --help Show this help message." + echo -e "\n\033[1mAUTHOR\033[0m" + echo " Ryuu Mitsuki" +} + + +args=("$@") # Store the command-line arguments in an array +length=${#args[@]} # Get the total number of arguments +wanted_arg="" + +new_args=() # Initialize an empty array for the modified arguments + +skip_next=0 # Variable to skip the argument following the "-s" switch +verbose=0 + +curdir=`pwd` +tmpfile=$curdir/tmp/index.tmp +log=$curdir/tmp/get_argument.log + +[ -f $log ] && > $log # Clear the log file if exist + +info() { + [ $1 = "Info" ] && echo -ne "[\033[1;92m$1\033[0m]${@/$1}\n" &>>$log + [ $1 = "Warning" ] && echo -ne "[\033[1;93m$1\033[0m]${@/$1}\n" &>>$log +} + +# Print usage if no arguments givem +[ $# -eq 0 ] && usage && return 0 + +for (( i=0; i < $length; i++ )); do + arg="${args[i]}" + + if [ $skip_next -eq 1 ]; then + skip_next=0 + continue + fi + + case $arg in + -s) + if (( i+1 < $length )); then + skip_next=1 + wanted_arg="${args[i+1]}" + continue + else + echo "Error: Switch '-s' need an argument" + return -1 + fi + ;; + + -v | --verbose) + verbose=1 + + # Only create temporary directory if the + # verbose activated + mkdir -p `dirname $tmpfile` + continue + ;; + + -h | --help) + usage + return 0 + ;; + esac + + new_args+=("$arg") +done +unset arg args i skip_next length + +if [ $verbose -eq 1 ]; then + info "Info" "Arguments : ${new_args[@]} (${#new_args[@]})" + info "Info" "Wanted argument : $wanted_arg" +fi + +found_index=-1 # Initialize the index of the desired argument as -1 + +for (( i=0; i < ${#new_args[@]}; i++ )); do + arg="${new_args[i]}" + + if [ $arg = $wanted_arg ]; then + found_index=$i + break + fi +done +unset arg i new_args + +if [ $verbose -eq 1 ]; then + echo &>>$log + info "Info" "Index of '$wanted_arg': $found_index" + if [ $found_index -eq -1 ]; then + info "Warning" "Index -1 means the argument not found" + fi +fi + +echo $(( $found_index + 1 )) +unset found_index curdir tmpfile verbose info log diff --git a/docs/makefile-usage.txcc b/docs/makefile-usage.txcc new file mode 100644 index 0000000..b58678d --- /dev/null +++ b/docs/makefile-usage.txcc @@ -0,0 +1,54 @@ +Usage: + $ make [rules] [...] [options] [...] + +Rules: + build-docs - Builds the HTML pages of JMatrix's javadocs. + check-verbose - Checks the verbose status. + clean - Cleans the working directory thoroughly. + cleanbin - Cleans all compiled class files only. + cleandocs - Cleans all generated HTML documentations only. + compile - Compiles all project's source files (.java). + package - Creates archived package of compiled classes. + usage - Prints the basic usages for building the project. + +Options: + FLAGS - Append flags to specific command or rule. + + Example: + $ make [rules] FLAGS[=] + + + INCLUDE-SRC - Whether to include the source files while packaging. + + Example: + $ make package INCLUDE-SRC[=] + + + LINT - Whether to invoke the linter during the compilation. + + Example: + $ make compile LINT[=] + + + VERBOSE - Whether to activate the verbose output. + + Example: + $ export VERBOSE[=(|all)] && make [rules] [options] + $ make [rules] VERBOSE[=] + $ make build-docs VERBOSE[=(|all)] + + Only the build-docs rule that has 3 verbose modes: + - Quiet Mode: *no argument + - Normal Mode: VERBOSE=true + - All Mode: VERBOSE=all + +Tips: + Combine the rules; Make can understand multiple rules. + Except for build-docs rule, it was built as a standalone rule. + +Issues: + Report any issues or suggestions, and help improve JMatrix. + + +Author: + Ryuu Mitsuki diff --git a/docs/makefile-usage.txt b/docs/makefile-usage.txt new file mode 100644 index 0000000..ca40872 --- /dev/null +++ b/docs/makefile-usage.txt @@ -0,0 +1,54 @@ +Usage: + $ make [rules] [...] [options] [...] + +Rules: + build-docs - Builds the HTML pages of JMatrix's javadocs. + check-verbose - Checks the verbose status. + clean - Cleans the working directory thoroughly. + cleanbin - Cleans all compiled class files only. + cleandocs - Cleans all generated HTML documentations only. + compile - Compiles all project's source files (.java). + package - Creates archived package of compiled classes. + usage - Prints the basic usages for building the project. + +Options: + FLAGS - Append flags to specific command or rule. + + Example: + $ make [rules] FLAGS[=] + + + INCLUDE-SRC - Whether to include the source files while packaging. + + Example: + $ make package INCLUDE-SRC[=] + + + LINT - Whether to invoke the linter during the compilation. + + Example: + $ make compile LINT[=] + + + VERBOSE - Whether to activate the verbose output. + + Example: + $ export VERBOSE[=(|all)] && make [rules] [options] + $ make [rules] VERBOSE[=] + $ make build-docs VERBOSE[=(|all)] + + Only the build-docs rule that has 3 verbose modes: + - Quiet Mode: *no argument + - Normal Mode: VERBOSE=true + - All Mode: VERBOSE=all + +Tips: + Combine the rules; Make can understand multiple rules. + Except for build-docs rule, it was built as a standalone rule. + +Issues: + Report any issues or suggestions, and help improve JMatrix. + + +Author: + Ryuu Mitsuki