Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New features for Makefile 🐧 #57

Merged
merged 31 commits into from
Jul 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
4e15857
Added new rule `build-docs`
mitsuki31 Jul 5, 2023
b666d5d
Added new file `makefile-usage.txt`
mitsuki31 Jul 5, 2023
3b42540
Refactor the `all` rule
mitsuki31 Jul 5, 2023
214c20b
Small fix and improve clarity
mitsuki31 Jul 5, 2023
d304043
Revert "Small fix and improve clarity"
mitsuki31 Jul 5, 2023
e31da55
Small fix and improve the clarity
mitsuki31 Jul 5, 2023
e186c3a
Added shell script file (`Bash`)
mitsuki31 Jul 6, 2023
e4c41f1
Refactoring the `build-docs`
mitsuki31 Jul 6, 2023
f5eef19
Added `FLAGS` for additional flags
mitsuki31 Jul 6, 2023
9406c00
Remove unused code
mitsuki31 Jul 6, 2023
99a987d
Now `build-docs` supported with options
mitsuki31 Jul 6, 2023
acd9d6c
Update the Make's usage
mitsuki31 Jul 6, 2023
0c224f5
Fixed some bad grammars
mitsuki31 Jul 6, 2023
309e900
Update the `clean` rule
mitsuki31 Jul 6, 2023
f2c2a06
Fixed the generated temporary directory
mitsuki31 Jul 6, 2023
51ba40e
Improve the `VERBOSE` checker
mitsuki31 Jul 6, 2023
b883c3d
The `clean` rule now clean generated docs
mitsuki31 Jul 7, 2023
cbd64c6
Added new rule named `cleandocs`
mitsuki31 Jul 7, 2023
a4f791b
Several changes for `Makefile`
mitsuki31 Jul 7, 2023
6a39b4d
Fixed the options issue
mitsuki31 Jul 7, 2023
48c76f7
Fixed the options issue
mitsuki31 Jul 7, 2023
ba4e744
Now `compile` rule supported `VERBOSE` option
mitsuki31 Jul 7, 2023
e5805d0
Revert "Now `compile` rule supported `VERBOSE` option"
mitsuki31 Jul 7, 2023
3784aee
Now `compile` rule supported `VERBOSE` option
mitsuki31 Jul 7, 2023
f656e3c
Minor fix on `build-docs` rule
mitsuki31 Jul 8, 2023
9766050
Now `clean` rule supported `VERBOSE` option
mitsuki31 Jul 8, 2023
496fd82
Now `cleanbin` rule supported `VERBOSE` option
mitsuki31 Jul 8, 2023
dadad9d
Now `cleandocs` rule supported `VERBOSE` option
mitsuki31 Jul 8, 2023
64cccb2
Fixed typo in Makefile
mitsuki31 Jul 8, 2023
0e03306
Separated the `makefile-usage` into 2 files
mitsuki31 Jul 8, 2023
8b1c88e
Refactored the `all` rule
mitsuki31 Jul 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
233 changes: 173 additions & 60 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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/
Expand All @@ -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
Expand All @@ -56,7 +62,7 @@ endif
ifndef VERBOSE
MAKE_VERBOSE :=
else
ifeq ($(VERBOSE),true)
ifeq "$(VERBOSE)" "true"
MAKE_VERBOSE := true
else
MAKE_VERBOSE :=
Expand All @@ -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[=<flags>]\`"
@echo ""
@echo "Usage:"
@echo " $$ make [options] [...] [arguments]"
@echo " $$ make [options] VERBOSE[=<bool>] INCLUDE-SRC[=<bool>]"
@echo " $$ make [options] (LINT[=<bool>] | FLAGS[=<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"
Expand All @@ -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)))
Expand Down Expand Up @@ -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 "<b>JMatrix</b> 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 "<font size="-1">Copyright (c) 2023 <a href="https://github.com/mitsuki31">Ryuu Mitsuki</a>.</font>" \
-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 ""
Expand All @@ -248,7 +361,7 @@ endif


usage:
@echo "[Makefile Usage]"
@echo "[Makefile Basic Usage]"

@echo ""
@echo "Parameters:"
Expand Down
Loading