Browse Source

Using "end if" instead of "end" and "crawl" instead of "compile".

David Piuva 3 years ago
parent
commit
0892c3ba0a

+ 10 - 10
Source/DFPSR/DFPSR.DsrHead

@@ -10,10 +10,10 @@
 
 if Linux
 	message "Building for Linux\n"
-end
+end if
 if Windows
 	message "Building for Windows\n"
-end
+end if
 
 # Change this if the compiler uses a different prefix for linking a library.
 linkerPrefix = "-l"
@@ -27,7 +27,7 @@ if Graphics
 		message "  Using X11\n"
 		LinkerFlag linkerPrefix & "X11"
 		WindowManager = "../windowManagers/X11Window.cpp"
-	end
+	end if
 	if Windows
 		message "  Using Win32\n"
 		LinkerFlag linkerPrefix & "gdi32"
@@ -35,9 +35,9 @@ if Graphics
 		LinkerFlag linkerPrefix & "kernel32"
 		LinkerFlag linkerPrefix & "comctl32"
 		WindowManager = "../windowManagers/Win32Window.cpp"
-	end
-end
-Compile WindowManager
+	end if
+end if
+Crawl WindowManager
 
 SoundManager = "../soundManagers/NoSound.cpp"
 if Sound
@@ -46,11 +46,11 @@ if Sound
 		message "  Using Alsa\n"
 		LinkerFlag linkerPrefix & "asound"
 		SoundManager = "../soundManagers/AlsaSound.cpp"
-	end
+	end if
 	if Windows
 		message "  Using WinMM\n"
 		LinkerFlag linkerPrefix & "winmm"
 		SoundManager = "../soundManagers/WinMMSound.cpp"
-	end
-end
-Compile SoundManager
+	end if
+end if
+Crawl SoundManager

+ 3 - 3
Source/tools/builder/Machine.cpp

@@ -189,11 +189,11 @@ static void interpretLine(Machine &target, List<String> &tokens, const dsr::Read
 					target.activeStackDepth++;
 				}
 				target.currentStackDepth++;
-			} else if (string_caseInsensitiveMatch(first, U"end")) {
+			} else if (string_caseInsensitiveMatch(first, U"end") && string_caseInsensitiveMatch(second, U"if")) {
 				// End if statement
 				target.currentStackDepth--;
 				target.activeStackDepth = target.currentStackDepth;
-			} else if (string_caseInsensitiveMatch(first, U"compile")) {
+			} else if (string_caseInsensitiveMatch(first, U"crawl")) {
 				// The right hand expression is evaluated into a path relative to the build script and used as the root for searching for source code.
 				analyzeSource(PATH_EXPR(1, tokens.length() - 1));
 			} else if (string_caseInsensitiveMatch(first, U"linkerflag")) {
@@ -222,7 +222,7 @@ static void interpretLine(Machine &target, List<String> &tokens, const dsr::Read
 		} else {
 			if (string_caseInsensitiveMatch(first, U"if")) {
 				target.currentStackDepth++;
-			} else if (string_caseInsensitiveMatch(first, U"end")) {
+			} else if (string_caseInsensitiveMatch(first, U"end") && string_caseInsensitiveMatch(second, U"if")) {
 				target.currentStackDepth--;
 			}
 		}

+ 0 - 16
Source/tools/builder/build.sh

@@ -1,16 +0,0 @@
-#!/bin/bash
-
-LIBRARY_PATH=../../DFPSR
-DEPENDENCIES="${LIBRARY_PATH}/collection/collections.cpp ${LIBRARY_PATH}/api/fileAPI.cpp ${LIBRARY_PATH}/api/bufferAPI.cpp ${LIBRARY_PATH}/api/stringAPI.cpp ${LIBRARY_PATH}/base/SafePointer.cpp Machine.cpp generator.cpp"
-
-# Compile the analyzer
-g++ main.cpp -o builder ${DEPENDENCIES} -std=c++14;
-
-# Compile the wizard project to test if the build system works
-echo "Generating dfpsr_compile.sh from Wizard.DsrProj"
-./builder ../wizard/Wizard.DsrProj Graphics Sound Linux ScriptPath="/tmp/dfpsr_compile.sh";
-echo "Generating dfpsr_win32_test.bat from Wizard.DsrProj"
-./builder ../wizard/Wizard.DsrProj Graphics Sound Windows ScriptPath="/tmp/dfpsr_win32_test.bat";
-echo "Running compile.sh"
-chmod +x /tmp/dfpsr_compile.sh
-/tmp/dfpsr_compile.sh

+ 46 - 0
Source/tools/builder/buildProject.sh

@@ -0,0 +1,46 @@
+# Using buildProject.sh
+#   $1 must be the *.DsrProj path, which is relative to the caller location.
+#   $2... are variable assignments sent as input to the given project file.
+#   BUILDER_CPP_COMPILER_PATH should be modified if it does not already refer to an installed C++ compiler.
+
+echo "Running buildProject.sh $@"
+
+# Get the build system's folder, where the build system is located
+BUILDER_FOLDER=`dirname "$(realpath $0)"`
+echo "BUILDER_FOLDER = ${BUILDER_FOLDER}"
+BUILDER_EXECUTABLE="${BUILDER_FOLDER}/builder"
+echo "BUILDER_EXECUTABLE = ${BUILDER_EXECUTABLE}"
+
+BUILDER_CPP_COMPILER_PATH="g++"
+echo "Change BUILDER_CPP_COMPILER_PATH in ${BUILDER_FOLDER}/buildProject.sh if you are not using ${BUILDER_CPP_COMPILER_PATH} as your compiler."
+
+# Check if the build system is compiled
+if [ -e "${BUILDER_EXECUTABLE}" ]; then
+	echo "Found the build system's binary."
+else
+	echo "Building the Builder build system for first time use."
+	LIBRARY_PATH="$(realpath ${BUILDER_FOLDER}/../../DFPSR)"
+	SOURCE_CODE="${BUILDER_FOLDER}/main.cpp ${BUILDER_FOLDER}/Machine.cpp ${BUILDER_FOLDER}/generator.cpp ${LIBRARY_PATH}/collection/collections.cpp ${LIBRARY_PATH}/api/fileAPI.cpp ${LIBRARY_PATH}/api/bufferAPI.cpp ${LIBRARY_PATH}/api/stringAPI.cpp ${LIBRARY_PATH}/base/SafePointer.cpp"
+	"${BUILDER_CPP_COMPILER_PATH}" -o "${BUILDER_EXECUTABLE}" ${SOURCE_CODE} -std=c++14
+	if [ $? -ne 0 ]
+	then
+		echo "Failed building the Builder build system, which is needed to build your project!"
+		exit 1
+	fi
+	chmod +x "${BUILDER_EXECUTABLE}"
+fi
+
+# Call the build system with a filename for the output script, which is later given execution permission and called.
+SCRIPT_PATH="/tmp/dfpsr_compile.sh"
+echo "Generating ${SCRIPT_PATH} from $1"
+rm "${SCRIPT_PATH}"
+"${BUILDER_EXECUTABLE}" $@ "ScriptPath=${SCRIPT_PATH}";
+if [ $? -ne 0 ]
+then
+	echo "Failed building the Builder build system, which is needed to build your project!"
+	exit 1
+fi
+echo "Giving execution permission to ${SCRIPT_PATH}"
+chmod +x "${SCRIPT_PATH}"
+echo "Running ${SCRIPT_PATH}"
+"${SCRIPT_PATH}"

+ 22 - 15
Source/tools/builder/generator.cpp

@@ -273,6 +273,7 @@ void generateCompilationScript(const Machine &settings, const ReadableString& pr
 		return;
 	}
 	String compiledFiles;
+	bool hasSourceCode = false;
 	bool needCppCompiler = false;
 	for (int d = 0; d < dependencies.length(); d++) {
 		Extension extension = dependencies[d].extension;
@@ -285,23 +286,29 @@ void generateCompilationScript(const Machine &settings, const ReadableString& pr
 			string_append(compiledFiles, U" ", sourcePath);
 			if (file_getEntryType(sourcePath) != EntryType::File) {
 				throwError(U"The source file ", sourcePath, U" could not be found!\n");
+			} else {
+				hasSourceCode = true;
 			}
 		}
 	}
-	// TODO: Give a warning if a known C compiler incapable of handling C++ is given C++ source code when needCppCompiler is true.
-	script_printMessage(output, language, string_combine(U"Compiling with", compilerFlags, linkerFlags));
-	string_append(output, compilerName, U" -o ", binaryPath, compilerFlags, linkerFlags, " ", compiledFiles, U"\n");
-	script_printMessage(output, language, U"Done compiling.");
-	script_printMessage(output, language, string_combine(U"Starting ", binaryPath));
-	script_executeLocalBinary(output, language, binaryPath);
-	script_printMessage(output, language, U"The program terminated.");
-	if (language == ScriptLanguage::Batch) {
-		// Windows might close the window before you have time to read the results or error messages of a CLI application, so pause at the end.
-		string_append(output, U"pause\n");
-	}
-	if (language == ScriptLanguage::Batch) {
-		string_save(scriptPath, output);
-	} else if (language == ScriptLanguage::Bash) {
-		string_save(scriptPath, output, CharacterEncoding::BOM_UTF8, LineEncoding::Lf);
+	if (hasSourceCode) {
+		// TODO: Give a warning if a known C compiler incapable of handling C++ is given C++ source code when needCppCompiler is true.
+		script_printMessage(output, language, string_combine(U"Compiling with", compilerFlags, linkerFlags));
+		string_append(output, compilerName, U" -o ", binaryPath, compilerFlags, linkerFlags, " ", compiledFiles, U"\n");
+		script_printMessage(output, language, U"Done compiling.");
+		script_printMessage(output, language, string_combine(U"Starting ", binaryPath));
+		script_executeLocalBinary(output, language, binaryPath);
+		script_printMessage(output, language, U"The program terminated.");
+		if (language == ScriptLanguage::Batch) {
+			// Windows might close the window before you have time to read the results or error messages of a CLI application, so pause at the end.
+			string_append(output, U"pause\n");
+		}
+		if (language == ScriptLanguage::Batch) {
+			string_save(scriptPath, output);
+		} else if (language == ScriptLanguage::Bash) {
+			string_save(scriptPath, output, CharacterEncoding::BOM_UTF8, LineEncoding::Lf);
+		}
+	} else {
+		printText("Filed to find any source code to compile.\n");
 	}
 }

+ 10 - 1
Source/tools/builder/main.cpp

@@ -1,16 +1,25 @@
 
+// Because it would be slow to check if the build system needs to be recompiled every time something uses it,
+//   you must manually delete the build system's binary and try to build a project using it after making changes to the builder's source code.
+//   Otherwise buildProject.sh will just see that an old version exists and use it.
+
 // TODO:
 //  * Let the build script define a temporary folder path for lazy compilation with reused *.o files.
 //    The /tmp folder is erased when shutting down the computer, which would force recompilation of each library after each time the computer has rebooted.
 //  * Find a way to check if a file is truly unique using a combination of pathless filenames, content checksums and visibility of surrounding files from the folder.
 //    This makes sure that including the same file twice using alternative ways of writing the path can be detected and trigger a warning.
 //    Can one convert the file ID from each platform into a string or 64-bit hash sum to quickly make sure that the file is unique?
-//  * Create scripts compiling the build system when it does not exist and managing creation of a temporary folder, calling the generated script...
 //  * Implement more features for the machine, such as:
 //    * Unary negation.
 //    * else and elseif cases.
 //    * Temporarily letting the theoretical path go into another folder within a scope, similar to if statements but only affecting the path.
 //      Like writing (cd path; stmt;) in Bash but with fast parsed Basic-like syntax.
+//      The same stack used to store theoretical paths might be useful for else if cases to remember when the scope has already passed a case when not jumping with gotos.
+//  * Create portable scripted events for pre-build and post-build, translated into both Batch and Bash.
+//    Pre-build can be used to generate and transpile code before compiling.
+//    Post-build should be used to execute the resulting program.
+//      Optionally with variables from the build script as input arguments.
+//  * Should the build system detect the local system automatically, or support cross compilation using a MinGW extension?
 
 #include "../../DFPSR/api/fileAPI.h"
 #include "generator.h"

+ 0 - 17
Source/tools/wizard/Wizard.DsrProj

@@ -1,17 +0,0 @@
-Import "../../DFPSR/DFPSR.DsrHead"
-
-# The library uses C++14 by default, but you can override it with a newer version as well.
-CompilerFlag "-std=c++14"
-
-if Linux
-	CompilerPath = "g++"
-end
-if Windows
-	# Replace CompilerPath if you did not install the 64-bit MinGW distribution of CodeBlocks in C:\Program\CodeBlocks
-	CompilerPath = "C:/Program/CodeBlocks/MinGW/bin/x86_64-w64-mingw32-g++.exe"
-end
-
-Compile "main.cpp"
-ProgramPath = "wizard"
-
-ListDependencies = 0

+ 0 - 23
Source/tools/wizard/build.sh

@@ -1,23 +0,0 @@
-#!/bin/bash
-
-# Assuming that you called build.sh from its own folder, you should already be in the project folder.
-PROJECT_FOLDER=.
-# Placing your executable in the project folder allow using the same relative paths in the final release.
-TARGET_FILE=./application
-# The root folder is where DFPSR, SDK and tools are located.
-ROOT_PATH=../..
-# Select where to place temporary files.
-TEMP_DIR=${ROOT_PATH}/../../temporary
-# Select a window manager
-WINDOW_MANAGER=X11
-# Select safe debug mode or fast release mode
-#MODE=-DDEBUG #Debug mode
-MODE=-DNDEBUG #Release mode
-COMPILER_FLAGS="${MODE} -std=c++14 -O2"
-# Select external libraries
-LINKER_FLAGS=""
-
-# Give execution permission
-chmod +x ${ROOT_PATH}/tools/buildAndRun.sh;
-# Compile everything
-${ROOT_PATH}/tools/buildAndRun.sh "${PROJECT_FOLDER}" "${TARGET_FILE}" "${ROOT_PATH}" "${TEMP_DIR}" "${WINDOW_MANAGER}" "${COMPILER_FLAGS}" "${LINKER_FLAGS}";

+ 6 - 0
Source/tools/wizard/buildLinux.sh

@@ -0,0 +1,6 @@
+#!/bin/bash
+
+# Launch the build system with main.DsrProj and Linux selected as the platform.
+echo "Running buildLinux.sh $@"
+chmod +x ../builder/buildProject.sh;
+../builder/buildProject.sh ./main.DsrProj Linux;

+ 21 - 0
Source/tools/wizard/main.DsrProj

@@ -0,0 +1,21 @@
+# This project will use both sound and graphics, so we default initialize them to 1 before evaluating the library's header.
+# The caller should provide the operating system's name (Windows, Linux)
+message "Starting main.DsrProj\n"
+Graphics
+Sound
+Import "../../DFPSR/DFPSR.DsrHead"
+
+# The library uses C++14 by default, but you can override it with a newer version as well.
+CompilerFlag "-std=c++14"
+
+# Find source code included by main recursively across header and implementation files with the same names.
+Crawl "main.cpp"
+
+# Enable if you want to see which includes and connected names are used to find source code.
+ListDependencies
+
+# Extensionless path to the generated binary for this project.
+# Will automatically be named on each operating system.
+ProgramPath = "wizard"
+
+message "Ending main.DsrProj\n"