Skip to content

Commit

Permalink
Merge pull request #39 from mitsuki31/fix-makefile
Browse files Browse the repository at this point in the history
Fixes some issue on `MinGW` (Windows) 🪛
  • Loading branch information
mitsuki31 authored Jun 13, 2023
2 parents 4243350 + 37dd3b5 commit ca88104
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 83 deletions.
126 changes: 71 additions & 55 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,35 +77,36 @@ endif
all:
$(info [Makefile-jmatrix])
@echo "Options:"
@echo " * compile - Compile the program. \
\n * package - Create archived package (jar) of compiled program.\
\n WARNING: Program need to be compiled first! \
\n * clean - Clean all of compiled program and created jar. \
\n * cleanbin - Clean all generated class files only. \
\n * check-verbose - Check the verbose status. \
\n * usage - Print the example usages for build the project."

@echo "\nAdditional 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 "\n \`export VERBOSE=true\`"
@echo "\n Or:"
@echo "\n \`make [options] VERBOSE=true\`\n"

@echo ""
@echo " \`export VERBOSE=true\`"
@echo ""
@echo " Or:"
@echo ""
@echo " \`make [options] VERBOSE=true\`"
@echo ""
@echo ""
@echo " * Include source files while packaging"

@echo "\n \`export INCLUDE-SRC=true\`"
@echo "\n Or:"
@echo "\n \`make [options] INCLUDE-SRC=true\`\n"

@echo "\nUsage:"
@echo " $$ make [option1] [option2] [...]"
@echo " $$ make compile package"

@echo "\nTips:"
@echo ""
@echo " \`make [options] INCLUDE-SRC=true\`"
@echo ""
@echo "Usage:"
@echo " $$ make [options] [...] [arguments]"
@echo " $$ make [options] VERBOSE[=<bool>] INCLUDE-SRC[=<bool>]"
@echo ""
@echo "Tips:"
@echo " - Combine the options, Makefile can understand multiple rules."

@echo "\nAuthor:"
@echo ""
@echo "Author:"
@echo " Ryuu Mitsuki"


Expand All @@ -119,16 +120,18 @@ endif


compile: $(SOURCES_LIST) $(SRCFILES)
@echo "\n>> [ COMPILE PROGRAM ] <<"
@echo ""
@echo ">> [ COMPILE PROGRAM ] <<"

@echo "$(PREFIX) Compiling all source files..."
@$(CC) -d $(CLASSES_PATH) @$<
@echo "$(PREFIX) Successfully compile all source files."
@echo "$(PREFIX) Successfully compiled all source files."

$(eval HAS_COMPILED := $(wildcard $(CLASSES_PATH)))
$(eval HAS_OUTPUT := $(wildcard $(OUTPUT_PATH)))

@echo "\n>> [ GENERATE LIST ] <<"
@echo ""
@echo ">> [ GENERATE LIST ] <<"
@echo "$(PREFIX) Generating list of class files..."

ifeq "$(MAKE_VERBOSE)" "true"
Expand All @@ -145,12 +148,14 @@ package: $(CLSFILES)
$(error $(PREFIX) Program is uncompiled, compile it with `make compile` command)\
)

@echo "\n>> [ CREATE JAR ] <<"
@echo ""
@echo ">> [ CREATE JAR ] <<"

@echo "$(PREFIX) Copying all program resources to output directory..."
@cp -r $(RESOURCES_PATH)* $(CLASSES_PATH)
@echo "$(PREFIX) All resources have been copied.\n"
@cp -r --preserve=all $(RESOURCES_PATH)* $(CLASSES_PATH)
@echo "$(PREFIX) All resources have been copied."

@echo ""
@echo "$(PREFIX) Creating jar for compiled classes..."

ifeq "$(MAKE_VERBOSE)" "true"
Expand All @@ -164,7 +169,8 @@ else
endif

ifeq "$(INCLUDE-SRC)" "true"
@echo "\n$(PREFIX) INCLUDE-SRC option is ACTIVATED"
@echo ""
@echo "$(PREFIX) INCLUDE-SRC option is ACTIVATED"
@echo "$(PREFIX) Adding the source files into jar..."
ifeq "$(MAKE_VERBOSE)" "true"
@jar uvf $(jar) -C $(SOURCES_PATH) .
Expand All @@ -174,30 +180,36 @@ endif
endif

@echo "$(PREFIX) Successfully created the jar file."
@echo "\nSAVED IN: \"$(jar)\""
@echo ""
@echo "SAVED IN: \"$(jar)\""


clean:
@echo "\n>> [ CLEAN WORKING DIRECTORY ] <<"
@echo ""
@echo ">> [ CLEAN WORKING DIRECTORY ] <<"
@echo "$(PREFIX) Cleaning the \"$(OUTPUT_PATH)\" directory recursively..."
@-rm -r $(OUTPUT_PATH)
@echo "\n$(PREFIX) All cleaned up."
@echo ""
@echo "$(PREFIX) All cleaned up."


cleanbin:
@echo "\n>> [ CLEAN ONLY CLASS OBJECTS ] <<"
@echo ""
@echo ">> [ CLEAN ONLY CLASS OBJECTS ] <<"
@echo "$(PREFIX) Cleaning the class files only..."
@-rm -r $(CLASSES_PATH)
@echo "\n$(PREFIX) All cleaned up."
@echo ""
@echo "$(PREFIX) All cleaned up."

$(if $(shell test -e $(jar) && echo "1"),\
@echo 'File "$(jar:/=)" is still exists.',\
$(warning File "$(jar_name)" is missing or has been deleted.)\
@echo 'File "$(subst ./,,$(jar))" is still exists.',\
@echo 'File "$(subst ./,,$(jar))" is missing or has been deleted.'\
)


$(SOURCES_LIST): $(wildcard $(PYTHON_PATH)*.py)
@echo "\n>> [ GENERATE LIST ] <<"
@echo ""
@echo ">> [ GENERATE LIST ] <<"
@echo "$(PREFIX) Generating list of source files..."

ifeq "$(MAKE_VERBOSE)" "true"
Expand All @@ -210,22 +222,26 @@ endif


usage:
@echo "[Makefile Usage]\n"
@echo "[Makefile Usage]"

@echo "Parameters:\n $$ make [option1] [option2] [...]\n"
@echo ""
@echo "Parameters:"
@echo " $$ make [option1] [option2] [...]"

@echo ""
@echo "Generate \"jar\" file (simple)"
@echo "\
make\n\
└── compile\n\
└── package\n\
└── cleanbin (optional)\n"
@echo ""
@echo "make"
@echo " └── compile"
@echo " └── package"
@echo " └── cleanbin (optional)"

@echo ""
@echo "Generate \"jar\" file (complex)"
@echo "\
make\n\
└── compile\n\
└── package\n\
└── && mv target/*.jar .\n\
└── && make\n\
└── clean\n"
@echo ""
@echo "make"
@echo " └── compile"
@echo " └── package"
@echo " └── && mv target/*.jar ."
@echo " └── && make"
@echo " └── clean"
17 changes: 6 additions & 11 deletions src/main/java/com/mitsuki/jmatrix/util/XMLParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,14 @@

// -**- Built-in Package -**- //
import java.io.InputStream;
import java.io.IOException;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.w3c.dom.DOMException;

// -**- Local Package -**- //
import com.mitsuki.jmatrix.core.JMBaseException;
import com.mitsuki.jmatrix.util.Options;


/**
Expand Down Expand Up @@ -147,15 +142,15 @@ public XMLParser(XMLType type) {
Document doc = docBuilder.parse(configStream);
Element xml = doc.getDocumentElement();

XMLConfig.programName = xml.getElementsByTagName("program_name").item(0).getTextContent();
XMLConfig.author = xml.getElementsByTagName("author").item(0).getTextContent();
XMLConfig.version = xml.getElementsByTagName("version").item(0).getTextContent();
XMLConfig.programName = xml.getElementsByTagName("program_name").item(0).getTextContent().strip();
XMLConfig.author = xml.getElementsByTagName("author").item(0).getTextContent().strip();
XMLConfig.version = xml.getElementsByTagName("version").item(0).getTextContent().strip();
XMLConfig.releaseType = xml.getElementsByTagName("version").item(0)
.getAttributes().getNamedItem("type").getNodeValue();
XMLConfig.packageName = xml.getElementsByTagName("package").item(0).getTextContent();
.getAttributes().getNamedItem("type").getNodeValue().strip();
XMLConfig.packageName = xml.getElementsByTagName("package").item(0).getTextContent().strip();

if (!XMLConfig.version.equals("release")) {
XMLConfig.betaNum = xml.getElementsByTagName("beta_num").item(0).getTextContent();
XMLConfig.betaNum = xml.getElementsByTagName("beta_num").item(0).getTextContent().strip();
}
} catch (final Exception e) {
try {
Expand Down
28 changes: 11 additions & 17 deletions src/main/python/generate_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,24 @@

import os
import sys
import platform
from utils import Utils, FileUtils

class GenerateList:
"""
This class provides methods that generates list of source files and class files.
For generating list, this class uses command that based on the operating system.
Currently only works on Linux/Unix system, Windows user need to install MinGW and Git Bash.
Working directory:
: 'src/main/java/' - For searching all of source files (*.java).
: 'target/classes/' - For searching all of class files (*.class).
: 'target/generated-list/' - The output directory for generated list.
"""
__PATH: dict = {
('target_path'): (os.sep).join(['src', 'main', 'java']),
('class_path'): (os.sep).join(['target', 'classes']) + os.sep,
('out_path'): (os.sep).join(['target', 'generated-list']) + os.sep,
('source'): (os.sep).join(['target', 'generated-list', 'sourceFiles.lst']),
('output'): (os.sep).join(['target', 'generated-list', 'outputFiles.lst'])
('target_path'): ('/').join(['src', 'main', 'java']),
('class_path'): ('/').join(['target', 'classes']) + '/',
('out_path'): ('/').join(['target', 'generated-list']) + '/',
('source'): ('/').join(['target', 'generated-list', 'sourceFiles.lst']),
('output'): ('/').join(['target', 'generated-list', 'outputFiles.lst'])
}

__verbose: bool = False
Expand Down Expand Up @@ -125,17 +123,15 @@ def __generate_sources_list(self) -> None:
Raises:
None
"""
if platform.system().lower() in ('linux', 'unix'):
command = self.__command['unix']['source']
elif platform.system().lower() in ('win', 'win32', 'win64', 'windows'):
command = self.__command['windows']['source']
command = self.__command['unix']['source']

if self.__verbose:
Utils.pr_banner('GENERATING LIST')
Utils.info_msg('Generating list...')

err_code: int = os.system(command)

# Return if an error occured
if err_code != 0:
sys.exit(err_code)

Expand Down Expand Up @@ -178,17 +174,15 @@ def __generate_output_list(self) -> None:
Raises:
None
"""
if platform.system().lower() in ('linux', 'unix'):
cmd = self.__command['unix']['output']
elif platform.system().lower() in ('win', 'win32', 'win64', 'windows'):
cmd = self.__command['windows']['output']
cmd = self.__command['unix']['output']

if self.__verbose:
Utils.pr_banner('GENERATING LIST')
Utils.info_msg('Generating list...')

err_code: int = os.system(cmd)

# Return if an error occured
if err_code != 0:
sys.exit(err_code)

Expand All @@ -209,7 +203,7 @@ def __generate_output_list(self) -> None:

for output_file in output_lst:
for out in output_file.split():
new_output_lst.append(os.path.join(*(out.split(os.sep)[2:])))
new_output_lst.append(os.path.join(*(out.split('/')[2:])))
new_output_lst.sort()

if self.__verbose:
Expand Down

0 comments on commit ca88104

Please sign in to comment.