--- /dev/null
+#!/usr/bin/env bash
+
+# Ensure the script is sourced
+if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
+ echo "This script must be sourced, not executed. Exiting."
+ return 1
+fi
+
+
+# Note these suffixes:
+# _FL = File List
+# _FPL = File Path List
+# _DL = Directory List
+
+# _PRIMARY = stuff not built
+# _IN things input to some program
+# _OUT things output by some program
+
+#--------------------------------------------------------------------------------
+# directories
+#
+
+# ANTLR directories
+export ANTLR_IN_PRIMARY_DIR="ANTLR"
+export ANTLR_OUT_DIR="javac/ANTLR"
+export ANTLR_OUT_DIR_PARENT="javac"
+
+# JAVA directories
+export JAVA_COMP_IN_PRIMARY_DIR="javac"
+export JAVA_COMP_IN_ANTLR_DIR="${ANTLR_OUT_DIR}"
+export JAVA_COMP_IN_DL="${JAVA_COMP_IN_PRIMARY_DIR}:${JAVA_COMP_IN_ANTLR_DIR}"
+export JAVA_COMP_OUT_DIR="jvm"
+
+# JVM
+export JVM_IN_DIR="${JAVA_COMP_OUT_DIR}"
+export CLASSPATH="${CLASSPATH}:${JVM_IN_DIR}"
+
+#--------------------------------------------------------------------------------
+# tools used
+#
+# set by project manager: JAVA_HOME, ANTLR_JAR, DEVELOPER_HOME
+#
+export JAVA_COMP="${JAVA_HOME}/bin/javac"
+export JAVA_INTERP="${JAVA_HOME}/bin/java"
+export JAVA_ARCHIVE="${JAVA_HOME}/bin/jar"
+export CLASSPATH="$ANTLR_JAR"
+
+#--------------------------------------------------------------------------------
+# to be built
+#
+export PROGRAM_PrintRuleNameList="executor/PrintRuleNameList"
+export PROGRAM_SyntaxTree_Test="executor/SyntaxTree_Test"
+export PROGRAM_SyntaxTree_20240412="executor/SyntaxTree_20240412"
+
+# an all programs list
+export PROGRAM_FPL="${PROGRAM_PrintRuleNameList} ${PROGRAM_SyntaxTree_Test} ${PROGRAM_SyntaxTree_20240412}"
+
+#--------------------------------------------------------------------------------
+# misc
+#
+export TEMP_DIR="$DEVELOPER_HOME"/temporary
+
+#--------------------------------------------------------------------------------
+# ANTLR files
+#
+
+export ANTLR_IN_FPL=$(ls ${ANTLR_IN_PRIMARY_DIR}/*.g4 2>/dev/null)
+export ANTLR_GRAMMAR_LIST=$(basename -s .g4 ${ANTLR_IN_FPL})
+if [ -z "${ANTLR_IN_FPL}" ]; then
+ echo "No ANTLR input grammar files found"
+fi
+
+# This function accepts a grammar name, or a grammar name with an extension;
+# and sets a variable of the form ANTLR_OUT_<grammar>_FPL to a list of
+# files that ANTLR would produce for <grammar>.
+set_ANTLR_out_fpl_var() {
+ local grammar=$1
+ export ANTLR_OUT_${grammar}_FPL="${ANTLR_OUT_DIR}/${grammar}Lexer.java ${ANTLR_OUT_DIR}/${grammar}Parser.java ${ANTLR_OUT_DIR}/${grammar}BaseVisitor.java ${ANTLR_OUT_DIR}/${grammar}Visitor.java"
+}
+
+# Generate ANTLR_OUT_<grammar>_FPL for each grammar
+for grammar in ${ANTLR_GRAMMAR_LIST}; do
+ set_ANTLR_out_fpl_var ${grammar}
+done
+
+# Combine all individual file lists into ANTLR_OUT_FPL
+ANTLR_OUT_FPL=""
+for grammar in ${ANTLR_GRAMMAR_LIST}; do
+ ANTLR_OUT_FPL="${ANTLR_OUT_FPL} $(eval echo \$ANTLR_OUT_${grammar}_FPL)"
+done
+export ANTLR_OUT_FPL
+
+#--------------------------------------------------------------------------------
+# Java files
+#
+
+# JAVA input files
+export JAVA_COMP_IN_PRIMARY_FPL=$(ls ${JAVA_COMP_IN_PRIMARY_DIR}/*.java 2>/dev/null)
+export JAVA_COMP_IN_ANTLR_FPL=${ANTLR_OUT_FPL}
+export JAVA_COMP_IN_FPL="${JAVA_COMP_IN_PRIMARY_FPL} ${JAVA_COMP_IN_ANTLR_FPL}"
+
+# JAVA will produce these output files
+export JAVA_COMP_OUT_PRIMARY_FPL=$(echo ${JAVA_COMP_IN_PRIMARY_FPL} | sed "s|${JAVA_COMP_IN_PRIMARY_DIR}/|${JAVA_COMP_OUT_DIR}/|g" | sed "s|.java|.class|g")
+export JAVA_COMP_OUT_ANTLR_FPL=$(echo ${JAVA_COMP_IN_ANTLR_FPL} | sed "s|${JAVA_COMP_IN_ANTLR_DIR}/|${JAVA_COMP_OUT_DIR}/|g" | sed "s|.java|.class|g")
+export JAVA_COMP_OUT_FPL="${JAVA_COMP_OUT_PRIMARY_FPL} ${JAVA_COMP_OUT_ANTLR_FPL}"
+
+#--------------------------------------------------------------------------------
+# JAR files
+#
+
+# List of JAR files to be built
+JAR_OUT_FPL=""
+for program_path in ${PROGRAM_FPL}; do
+ program_name=$(basename ${program_path})
+ class_file="${JAVA_COMP_OUT_DIR}/${program_name}.class"
+ # Check if the .class file is in JAVA_COMP_OUT_FPL
+ for item in ${JAVA_COMP_OUT_FPL}; do
+ # if so add it to the JAR_OUT_FPL
+ if [[ "${item}" == "${class_file}" ]]; then
+ jar_file="${JAVA_COMP_OUT_DIR}/${program_name}.jar"
+ JAR_OUT_FPL="${JAR_OUT_FPL} ${jar_file}"
+ break
+ fi
+ done
+done
+export JAR_OUT_FPL
+
--- /dev/null
+#!/usr/bin/env bash
+/var/user_data/Thomas-developer/GQL_to_Cypher/tool/jdk-22.0.1+8/bin/java -cp jvm/PrintRuleNameList.jar PrintRuleNameList $@
#!/usr/bin/env bash
+#!/usr/bin/env bash
# Clean targets:
#
# 2. General clean targets:
#
# > clean all # removes all things make built, and thus can be replaced by running make again.
-# > clean all- # same as clean:all except not the program files (and their .jar if any)
-# > clean program # remove all built ./executor/<program> and ./jvm/<program.jar> files
+# > clean program # removes all built executor scripts and corresponding jar files
# > clean class # removes the class files
# > clean grammar # removes the generated java grammar files
#
# 3. Specific clean targets:
#
-# > clean program <program_name> # similar to clean:program, but only for the named program
-# - clean all <program_name> # basically clean:all but only for the named program
-# - clean all- <program_name> # basically clean:all- but only for the named program
-# - clean grammar <grammar_name> - similar to clean:grammar, but only for the named grammar
+# > clean all <program_name> # cleans all files built while building the program
+# > clean program <program_name> # removes the script and jar file for the given program
+# > clean grammar <grammar_name> - similar to clean:grammar, but only for the named grammar
# Function to display usage message
display_usage() {
- echo "Usage: clean <all[-] [<program>] | program <name> | grammar <name> | class | temp[orary]>"
+ echo "Usage: clean <all [<program_name>] | program [<program_name>] | grammar [<name>] | class | temp[orary]>"
}
# Command parser
clean_command_parser() {
- local token_list=($1)
+ local token_list=($@)
local token_count=${#token_list[@]}
local command=${token_list[0]}
local arg=${token_list[1]}
"all")
clean_directory "$TEMP_DIR"
clean_grammar
- clean_files "JAVA_COMP_OUT_FPL"
- clean_files "PROGRAM_FPL"
- ;;
- "all-")
- clean_directory "$TEMP_DIR"
- clean_grammar
- clean_files "JAVA_COMP_OUT_PRIMARY_FPL"
+ clean_file_list "JAVA_COMP_OUT_FPL"
+ clean_file_list "JAR_OUT_FPL"
+ clean_file_list "PROGRAM_FPL"
;;
"program")
- clean_files "PROGRAM_FPL"
+ clean_file_list "JAR_OUT_FPL"
+ clean_file_list "PROGRAM_FPL"
;;
"class")
- clean_files "JAVA_COMP_OUT_FPL"
+ clean_file_list "JAVA_COMP_OUT_FPL"
;;
"grammar")
clean_grammar
esac
elif [ "$token_count" -eq 2 ]; then
case "$command" in
- "program")
- clean_files "$JAVA_COMP_OUT_DIR/$arg.jar executor/$arg"
- ;;
"all")
- clean_files "$JAVA_COMP_OUT_DIR/$arg.jar executor/$arg"
- clean_directory "$TEMP_DIR"
- clean_grammar "$arg"
+ clean_file_list "executor/$arg $JAVA_COMP_OUT_DIR/$arg.jar $JAVA_COMP_OUT_DIR/$arg.class"
+ # program specific cleaning
+ case "$arg" in
+ "SyntaxTree_Test")
+ clean_grammar "GQL_Test"
+ ;;
+ "SyntaxTree_20240412")
+ clean_grammar "GQL_20240412"
+ ;;
+ "PrintRuleNameList")
+ :
+ ;;
+ *)
+ echo "Unknown program: $arg"
+ ;;
+ esac
;;
- "all-")
- clean_files "$JAVA_COMP_OUT_DIR/$arg.class $JAVA_COMP_OUT_DIR/$arg.BaseVisitor.class $JAVA_COMP_OUT_DIR/$arg.Visitor.class $JAVA_COMP_OUT_DIR/$arg.Parser.class $JAVA_COMP_OUT_DIR/$arg.Lexer.class"
- clean_directory "$TEMP_DIR"
+ "program")
+ clean_file_list "executor/$arg"
+ clean_file_list "$JAVA_COMP_OUT_DIR/$arg.jar"
;;
"grammar")
clean_grammar "$arg"
fi
}
-# Main script logic
-if [ $# -eq 0 ]; then
- display_usage
-else
- clean_command_parser "$*"
-fi
+clean_command_parser $@
#!/usr/bin/env bash
-source /path/to/env.sh
if [ -z "$1" ]; then
echo "Error: Directory argument is empty"
#!/usr/bin/env bash
-source /path/to/env.sh
if [ -z "$1" ]; then
echo "Error: File list name is not provided."
# Function to delete a specific grammar
delete_grammar() {
local grammar=$1
+ echo "Attempting to delete grammar: $grammar"
if [ -z "$grammar" ]; then
echo "Error: Grammar name is empty"
elif echo "$ANTLR_GRAMMAR_LIST" | grep -qw "$grammar"; then
# If no argument is given, delete all grammars
if [ -z "$1" ]; then
+ echo "No argument provided, deleting all grammars"
for grammar in $ANTLR_GRAMMAR_LIST; do
delete_grammar "$grammar"
done
else
+ echo "Argument provided: $1"
delete_grammar "$1"
fi
return 1
fi
-
# Note these suffixes:
# _FL = File List
# _FPL = File Path List
# _OUT things output by some program
#--------------------------------------------------------------------------------
-# tools
+# directories
+#
+
+# ANTLR directories
+export ANTLR_IN_PRIMARY_DIR="ANTLR"
+export ANTLR_OUT_DIR="javac/ANTLR"
+export ANTLR_OUT_DIR_PARENT="javac"
+
+# JAVA directories
+export JAVA_COMP_IN_PRIMARY_DIR="javac"
+export JAVA_COMP_IN_ANTLR_DIR="${ANTLR_OUT_DIR}"
+export JAVA_COMP_IN_DL="${JAVA_COMP_IN_PRIMARY_DIR}:${JAVA_COMP_IN_ANTLR_DIR}"
+export JAVA_COMP_OUT_DIR="jvm"
+
+# JVM
+export JVM_IN_DIR="${JAVA_COMP_OUT_DIR}"
+export CLASSPATH="${CLASSPATH}:${JVM_IN_DIR}"
+
+#--------------------------------------------------------------------------------
+# tools used
#
# set by project manager: JAVA_HOME, ANTLR_JAR, DEVELOPER_HOME
#
export TEMP_DIR="$DEVELOPER_HOME"/temporary
#--------------------------------------------------------------------------------
-# ANTLR environment
+# ANTLR files
#
-# ANTLR directories
-export ANTLR_PRIMARY_DIR="ANTLR"
-export ANTLR_IN_DIR="${ANTLR_PRIMARY_DIR}"
-export ANTLR_OUT_DIR="javac/ANTLR"
-export ANTLR_OUT_DIR_PARENT="javac"
-
-# ANTLR input files
-ANTLR_IN_FPL=$(ls ${ANTLR_IN_DIR}/*.g4 2>/dev/null)
+export ANTLR_IN_FPL=$(ls ${ANTLR_IN_PRIMARY_DIR}/*.g4 2>/dev/null | tr '\n' ' ')
export ANTLR_GRAMMAR_LIST=$(basename -s .g4 ${ANTLR_IN_FPL})
if [ -z "${ANTLR_IN_FPL}" ]; then
echo "No ANTLR input grammar files found"
fi
-# ANTLR will produce these output files.
-#
# This function accepts a grammar name, or a grammar name with an extension;
# and sets a variable of the form ANTLR_OUT_<grammar>_FPL to a list of
# files that ANTLR would produce for <grammar>.
export ANTLR_OUT_FPL
#--------------------------------------------------------------------------------
-# Java environment
+# Java files
#
-# JAVA directories
-export JAVA_COMP_IN_PRIMARY_DIR="javac"
-export JAVA_COMP_IN_ANTLR_DIR="${ANTLR_OUT_DIR}"
-export JAVA_COMP_IN_DL="${JAVA_COMP_IN_PRIMARY_DIR}:${JAVA_COMP_IN_ANTLR_DIR}"
-export JAVA_COMP_OUT_DIR="jvm"
-
# JAVA input files
-JAVA_COMP_IN_PRIMARY_FPL=$(ls ${JAVA_COMP_IN_PRIMARY_DIR}/*.java 2>/dev/null)
-JAVA_COMP_IN_ANTLR_FPL=${ANTLR_OUT_FPL}
+export JAVA_COMP_IN_PRIMARY_FPL=$(ls ${JAVA_COMP_IN_PRIMARY_DIR}/*.java 2>/dev/null | tr '\n' ' ')
+export JAVA_COMP_IN_ANTLR_FPL=${ANTLR_OUT_FPL}
export JAVA_COMP_IN_FPL="${JAVA_COMP_IN_PRIMARY_FPL} ${JAVA_COMP_IN_ANTLR_FPL}"
# JAVA will produce these output files
-JAVA_COMP_OUT_PRIMARY_FPL=$(echo ${JAVA_COMP_IN_PRIMARY_FPL} | sed "s|${JAVA_COMP_IN_PRIMARY_DIR}/|${JAVA_COMP_OUT_DIR}/|g" | sed "s|.java|.class|g")
-JAVA_COMP_OUT_ANTLR_FPL=$(echo ${JAVA_COMP_IN_ANTLR_FPL} | sed "s|${JAVA_COMP_IN_ANTLR_DIR}/|${JAVA_COMP_OUT_DIR}/|g" | sed "s|.java|.class|g")
+export JAVA_COMP_OUT_PRIMARY_FPL=$(echo ${JAVA_COMP_IN_PRIMARY_FPL} | sed "s|${JAVA_COMP_IN_PRIMARY_DIR}/|${JAVA_COMP_OUT_DIR}/|g" | sed "s|.java|.class|g")
+export JAVA_COMP_OUT_ANTLR_FPL=$(echo ${JAVA_COMP_IN_ANTLR_FPL} | sed "s|${JAVA_COMP_IN_ANTLR_DIR}/|${JAVA_COMP_OUT_DIR}/|g" | sed "s|.java|.class|g")
export JAVA_COMP_OUT_FPL="${JAVA_COMP_OUT_PRIMARY_FPL} ${JAVA_COMP_OUT_ANTLR_FPL}"
-
#--------------------------------------------------------------------------------
-# JVM environment
+# JAR files
#
-export JVM_IN_DIR="${JAVA_COMP_OUT_DIR}"
-export CLASSPATH="${CLASSPATH}:${JVM_IN_DIR}"
+
+# List of JAR files to be built
+JAR_OUT_FPL=""
+for program_path in ${PROGRAM_FPL}; do
+ program_name=$(basename ${program_path})
+ class_file="${JAVA_COMP_OUT_DIR}/${program_name}.class"
+ # Check if the .class file is in JAVA_COMP_OUT_FPL
+ for item in ${JAVA_COMP_OUT_FPL}; do
+ # if so add it to the JAR_OUT_FPL
+ if [[ "${item}" == "${class_file}" ]]; then
+ jar_file="${JAVA_COMP_OUT_DIR}/${program_name}.jar"
+ JAR_OUT_FPL="${JAR_OUT_FPL} ${jar_file}"
+ break
+ fi
+ done
+done
+export JAR_OUT_FPL
all: setup $(PROGRAM_FPL)
-grammar: setup $(ANTLR_OUT_FPL)
-
SyntaxTree_Test: $(ANTLR_OUT_GQL_Test_FPL)
make $(PROGRAM_SyntaxTree_Test)
PrintRuleNameList: $(PROGRAM_PrintRuleNameList)
+grammar: setup $(ANTLR_OUT_FPL)
+
+# Compile all the .java files.
+java: setup $(JAVA_COMP_OUT_FPL)
+
# Specific grammar targets. Run them like this:
# > make <grammar_name>
# e.g. > make GQL_test
$(foreach grammar,$(ANTLR_GRAMMAR_LIST),$(eval $(grammar): $(value ANTLR_OUT_$(grammar)_FPL)))
-# Compile all the .java files.
-java: setup $(JAVA_COMP_OUT_FPL)
-
.PHONY: version
version:
$(info ANTLR_JAR is '$(notdir $(ANTLR_JAR))')
@ echo "makefile 0.2"
.PHONY: setup
+# ANTLR automatically creates $(ANTLR_OUT_DIR)
setup:
- # ANTLR automatically creates $(ANTLR_OUT_DIR)
mkdir -p $(ANTLR_IN_DIR) $(JAVA_COMP_IN_PRIMARY_DIR) $(JVM_IN_DIR)
mkdir -p executor test deprecated experiment documentation temporary
-.PHONY: clean\:%
-clean\:%:
- clean $(subst :, ,$*))
-
# Default clean target
-.PHONY: clean
+.PHONY: setup
clean:
- clean
+ @echo "Use the clean script from the executor directory instead of \`make clean\`"
+ @executor/clean
#useful for distinguishing initial make error messages and message generated by rules firing
nothing:
#================================================================================
# recipes
+# Without this, GNU make deletes .jar files after making them.
+# Surely this is part of a spat between GNU and Sun Microsysitems, where they
+# now produce tools that delete each others files ;-)
+.PRECIOUS: $(JAVA_COMP_OUT_DIR)/%.jar
+
$(ANTLR_OUT_DIR)/%Lexer.java \
$(ANTLR_OUT_DIR)/%Parser.java \
$(ANTLR_OUT_DIR)/%BaseVisitor.java \
@echo "making grammar from:" $<
$(JAVA_INTERP) -jar $(ANTLR_JAR) -Dlanguage=Java -visitor -o $(ANTLR_OUT_DIR_PARENT) $<
-$(JAVA_COMP_OUT_DIR)/%.jar: $(JAVA_COMP_IN_PRIMARY_DIR)/%.java
- @echo "Building $*..."
+# Rule to build .class files from .java files
+$(JAVA_COMP_OUT_DIR)/%.class: $(JAVA_COMP_IN_PRIMARY_DIR)/%.java
+ @echo "Compiling $<..."
$(JAVA_COMP) -d $(JAVA_COMP_OUT_DIR) -sourcepath $(JAVA_COMP_IN_DL) $<
- $(JAVA_ARCHIVE) cf $@ -C $(JVM_IN_DIR) $*.class
@echo "Created $@"
-.PRECIOUS: $(JAVA_COMP_OUT_DIR)/%.jar
+# Rule to build .jar files from .class files
+$(JAVA_COMP_OUT_DIR)/%.jar: $(JAVA_COMP_OUT_DIR)/%.class
+ @echo "Building $*..."
+ $(JAVA_ARCHIVE) cf $@ -C $(JAVA_COMP_OUT_DIR) $*.class
+ @echo "Created $@"
+
+# Rule to create executable scripts from .jar files
executor/%: $(JAVA_COMP_OUT_DIR)/%.jar
@echo "Creating script for $*..."
@echo "#!/usr/bin/env bash" > executor/$*