From: Thomas Walker Lynch Date: Wed, 4 Sep 2024 14:41:58 +0000 (+0000) Subject: various cleanup, first/rough pass on a build doc, some comments X-Git-Url: https://git.reasoningtechnology.com/style/rt_dark_doc.css?a=commitdiff_plain;h=cfc2c15f6af46864b4cc680e28c9252a46a404e0;p=GQL-to-Cypher various cleanup, first/rough pass on a build doc, some comments --- diff --git a/developer/executor/env_build b/developer/executor/env_build index b8f9ef1..a631a60 100755 --- a/developer/executor/env_build +++ b/developer/executor/env_build @@ -1,39 +1,44 @@ #!/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: +# The build environment. +# +# Hopefully no edits are required here to build this project's programs. +# +# The most common edit here is to add the name of a new program to the EXECUTOR_IN_FL. +# That variable is found in the next section. +# +# The `env_dev` script should have been sourced already. (env_dev is analogous +# to the Python virutal environment `activate`.) `env_dev` will set `developer/executor/` +# first in the search PATH. In that directory there is a script called `make` which +# is a wrapper to `/bin/make`. That script sources this file. Hence, this file +# is the environment for make, aka the build environment. +# +# Note these suffixes found on variable names: # _FL = File List # _FP = File Path # _FPL = File Path List # _DL = Directory List # _DP = Directory path # _DPL = Directory path list - +# # _PRIMARY = stuff not built # _IN things input to some program # _OUT things output by some program +# +# Relative paths values are relative to the $REPO_HOME/developer directory, unless +# for good reason which is obvious or stated in a comment adjacent to the variable. -#-------------------------------------------------------------------------------- -# commands - -export BIN_MAKE=/bin/make +# Ensure the script is sourced rather than run directly +if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then + echo "This script must be sourced, not executed. Exiting." + return 1 +fi #-------------------------------------------------------------------------------- -# to be built +# programs to be built +# each new executable will also need a custom target in makefile-project.mk -# export PROGRAM_PrintRuleNameList="executor/PrintRuleNameList" -# export PROGRAM_SyntaxTree_Arithmetic="executor/SyntaxTree_Arithmetic" -# export PROGRAM_Test__SyntaxTree_Arithmetic="executor/Test__SyntaxTree_Arithmetic" -# export PROGRAM_SyntaxTree_20240412="executor/SyntaxTree_20240412" - - -# Add each new executable to this list, and give it a custom target in the makefile. export EXECUTOR_IN_FL="\ PrintRuleNameList\ TerminalToCategory\ @@ -81,6 +86,7 @@ export CLASSPATH="${CLASSPATH}:${JVM_IN_DP}" # # set by project manager: JAVA_HOME, ANTLR_JAR, DEVELOPER_HOME # +export BIN_MAKE=/bin/make export JAVA_COMP="${JAVA_HOME}/bin/javac" export JAVA_INTERP="${JAVA_HOME}/bin/java" export JAVA_ARCHIVE="${JAVA_HOME}/bin/jar" @@ -94,35 +100,12 @@ export TEMP_DIR="$DEVELOPER_HOME"/temporary #-------------------------------------------------------------------------------- # ANTLR files # - export ANTLR_IN_PRIMARY_FPL=$(ls ${ANTLR_IN_PRIMARY_DIR}/*.g4 2>/dev/null | tr '\n' ' ') export ANTLR_GRAMMAR_LIST=$(basename -s .g4 ${ANTLR_IN_PRIMARY_FPL}) if [ -z "${ANTLR_IN_PRIMARY_FPL}" ]; then echo "No ANTLR input grammar files found" fi -# replaced with a tool called ANTLR_OUR_FL -# -# This function accepts a grammar name, or a grammar name with an extension; -# and sets a variable of the form ANTLR_OUT__FPL to a list of -# files that ANTLR would produce for . -# 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__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 # diff --git a/developer/executor/make b/developer/executor/make index 714a070..fcc76d3 100755 --- a/developer/executor/make +++ b/developer/executor/make @@ -12,4 +12,11 @@ cd "$DEVELOPER_HOME" # in case there have been edits to the environment source "${EXECUTOR_IN_DIR}"/env_build +# If make is called with no arguments, we will make the entire project. +# Making the project has a dependency on the tools, so if they have not +# been made, they will be made before the project is made. +if [[ $# -eq 0 ]]; then + set -- "project" +fi + ${BIN_MAKE} --no-print-directory -f "${EXECUTOR_IN_DIR}"/makefile-top.mk $@ diff --git a/developer/executor/makefile-project.mk b/developer/executor/makefile-project.mk index b406cd1..badb939 100644 --- a/developer/executor/makefile-project.mk +++ b/developer/executor/makefile-project.mk @@ -1,62 +1,70 @@ - -$(info makefile: $(MAKEFILE_LIST)) -$(info project_MAKECMDGOALS: $(MAKECMDGOALS)) +#-------------------------------------------------------------------------------- +# Project build +# # turn off implicit rules .SUFFIXES: MAKEFLAGS += -r # `make` always tries to make its makefiles as targets. This prevents that. -.SECONDARY: $(MAKEFILE_LIST) +.PHONY: $(MAKEFILE_LIST) +.PRECIOUS: $(MAKEFILE_LIST) + +$(info makefile: $(MAKEFILE_LIST)) +$(info project_MAKECMDGOALS: $(MAKECMDGOALS)) #================================================================================ # Custom make targets # project: $(EXECUTOR_IN_FPL) - PrintRuleNameList: $(EXECUTOR_IN_DIR)/PrintRuleNameList #----------------------------------------------- # Arithmetic -ANTLR_OUT_Arithmetic_FL := $(shell ANTLR_OUT_FL Arithmetic.g4 -visitor -no-listener -no-tokens) -ANTLR_OUT_Arithmetic_FPL := $(addprefix $(ANTLR_OUT_DIR)/, $(ANTLR_OUT_Arithmetic_FL)) -Arithmetic_Echo: $(ANTLR_OUT_Arithmetic_FPL) $(JAVA_COMP_IN_PRIMARY_DIR)/Arithmetic_Echo_PrintVisitor.java +ANTLR_OUT_Arithmetic_FPL $(shell ANTLR_OUT_FL Arithmetic -path $(ANTLR_OUT_DIR)) +Arithmetic_Echo:\ + $(ANTLR_OUT_Arithmetic_FPL) + $(JAVA_COMP_IN_PRIMARY_DIR)/Arithmetic_Echo_PrintVisitor.java @if [ -z "$(ANTLR_OUT_Arithmetic_FPL)" ]; then \ echo "variable ANTLR_OUT_Arithmetic_FPL empty."; \ exit 1; \ fi make $(EXECUTOR_IN_DIR)/Arithmetic_Echo -# Arithmetic_Echo__Test: $(ANTLR_OUT_Arithmetic_FPL) $(JAVA_COMP_IN_PRIMARY_DIR)/Arithmetic_Echo_PrintVisitor.java -# @if [ -z "$(ANTLR_OUT_Arithmetic_FPL)" ]; then \ -# echo "variable ANTLR_OUT_Arithmetic_FPL empty."; \ -# exit 1; \ -# fi -# $(BIN_MAKE) $(EXECUTOR_IN_DIR)/Arithmetic_Echo__Test - -# Arithmetic_Syntax: $(ANTLR_OUT_Arithmetic_FPL) $(JAVA_COMP_IN_PRIMARY_DIR)/Arithmetic_Syntax_PrintVisitor.java -# @if [ -z "$(ANTLR_OUT_Arithmetic_FPL)" ]; then \ -# echo "variable ANTLR_OUT_Arithmetic_FPL empty."; \ -# exit 1; \ -# fi -# $(BIN_MAKE) $(EXECUTOR_IN_DIR)/Arithmetic_Syntax - -# Arithmetic_Syntax__Test: $(ANTLR_OUT_Arithmetic_FPL) $(JAVA_COMP_IN_PRIMARY_DIR)/Arithmetic_Syntax_PrintVisitor.java -# @if [ -z "$(ANTLR_OUT_Arithmetic_FPL)" ]; then \ -# echo "variable ANTLR_OUT_Arithmetic_FPL empty."; \ -# exit 1; \ -# fi -# $(BIN_MAKE) $(EXECUTOR_IN_DIR)/Arithmetic_Syntax__Test +Arithmetic_Echo__Test:\ + $(ANTLR_OUT_Arithmetic_FPL) + $(JAVA_COMP_IN_PRIMARY_DIR)/Arithmetic_Echo_PrintVisitor.java + @if [ -z "$(ANTLR_OUT_Arithmetic_FPL)" ]; then \ + echo "variable ANTLR_OUT_Arithmetic_FPL empty."; \ + exit 1; \ + fi + $(BIN_MAKE) $(EXECUTOR_IN_DIR)/Arithmetic_Echo__Test + +Arithmetic_Syntax:\ + $(ANTLR_OUT_Arithmetic_FPL) + $(JAVA_COMP_IN_PRIMARY_DIR)/Arithmetic_Syntax_PrintVisitor.java + @if [ -z "$(ANTLR_OUT_Arithmetic_FPL)" ]; then \ + echo "variable ANTLR_OUT_Arithmetic_FPL empty."; \ + exit 1; \ + fi + $(BIN_MAKE) $(EXECUTOR_IN_DIR)/Arithmetic_Syntax + +Arithmetic_Syntax__Test:\ + $(ANTLR_OUT_Arithmetic_FPL) + $(JAVA_COMP_IN_PRIMARY_DIR)/Arithmetic_Syntax_PrintVisitor.java + @if [ -z "$(ANTLR_OUT_Arithmetic_FPL)" ]; then \ + echo "variable ANTLR_OUT_Arithmetic_FPL empty."; \ + exit 1; \ + fi + $(BIN_MAKE) $(EXECUTOR_IN_DIR)/Arithmetic_Syntax__Test #----------------------------------------------- # GQL_20240412 -ANTLR_OUT_GQL_20240412_FL := $(shell ANTLR_OUT_FL GQL_20240412.g4 -visitor -no-listener -no-tokens) -ANTLR_OUT_GQL_20240412_FPL := $(addprefix $(ANTLR_OUT_DIR)/, $(ANTLR_OUT_GQL_20240412_FL)) - +ANTLR_OUT_GQL_20240412_FPL := $(shell ANTLR_OUT_FL GQL_20240412 -path $(ANTLR_OUT_DIR)) GQL_20240412_Syntax: $(ANTLR_OUT_GQL_20240412_FPL) $(JAVA_COMP_IN_PRIMARY_DIR)/GQL_20240412_Syntax_PrintVisitor.java @if [ -z "$(ANTLR_OUT_GQL_20240412_FPL)" ]; then \ echo "variable ANTLR_OUT_GQL_20240412_FPL empty."; \ diff --git a/developer/executor/makefile-tool.mk b/developer/executor/makefile-tool.mk index 2972b10..db4037c 100644 --- a/developer/executor/makefile-tool.mk +++ b/developer/executor/makefile-tool.mk @@ -1,13 +1,14 @@ -$(info makefile: $(MAKEFILE_LIST)) -$(info project_MAKECMDGOALS: $(MAKECMDGOALS)) - # turn off implicit rules .SUFFIXES: MAKEFLAGS += -r # `make` always tries to make its makefiles as targets. This prevents that. -.SECONDARY: $(MAKEFILE_LIST) +.PHONY: $(MAKEFILE_LIST) +.PRECIOUS: $(MAKEFILE_LIST) + +$(info makefile: $(MAKEFILE_LIST)) +$(info project_MAKECMDGOALS: $(MAKECMDGOALS)) #================================================================================ # Custom make targets diff --git a/developer/executor/makefile-top.mk b/developer/executor/makefile-top.mk index 649a083..4e88b53 100644 --- a/developer/executor/makefile-top.mk +++ b/developer/executor/makefile-top.mk @@ -1,20 +1,26 @@ -$(info makefile: $(MAKEFILE_LIST)) -$(info project_MAKECMDGOALS: $(MAKECMDGOALS)) +# In GNU make, pattern matches can not be empty strings. +# `> make project`, or `make project-project` makes the entire project +# `> make tool-tool` makes all the tools (while not making the project). # turn off implicit rules .SUFFIXES: MAKEFLAGS += -r -# `make` always tries to make its makefiles as targets. This prevents that. -.SECONDARY: $(MAKEFILE_LIST) +# `make` always tries to make its make files as target files. This prevents that. +.PHONY: $(MAKEFILE_LIST) +.PRECIOUS: $(MAKEFILE_LIST) + +$(info makefile: $(MAKEFILE_LIST)) +$(info project_MAKECMDGOALS: $(MAKECMDGOALS)) + #================================================================================ # Custom make targets # -.PHONY: top version clean setup tool- project- +.PHONY: top version clean setup # The 'all' target now depends on 'tool' and 'project' -top: setup tool- project- +top: setup tool-tool project-project # for distinguishing between make syntax errors and build errors nothing: @@ -29,18 +35,17 @@ version: # `clean` is program independent of `make` clean: - @echo "Use the clean script from the $(EXECUTOR_IN_DIR) directory instead of \`make clean\`" - @$(EXECUTOR_IN_DIR)/clean + @echo "Use the command `clean