mirror of https://gitlab.com/nakst/essence
move start.sh logic to util/start.script
This commit is contained in:
parent
d579ef1bae
commit
b617025460
|
@ -183,7 +183,7 @@ void PortGCC() {
|
|||
str mpcVersion = "1.2.1";
|
||||
|
||||
// Load the persistent variables.
|
||||
assert PersistRead("bin/build_gcc_state.dat");
|
||||
assert PersistRead("bin/port.script.persist");
|
||||
|
||||
str destDir = "";
|
||||
|
||||
|
|
78
start.sh
78
start.sh
|
@ -1,77 +1 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Set the current directory to the source root.
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
# Create the bin directories.
|
||||
mkdir -p bin bin/dependency_files bin/Logs bin/generated_code bin/cache bin/Object\ Files
|
||||
|
||||
# Check that we are running on a sensible platform.
|
||||
uname -a | grep Cygwin > /dev/null
|
||||
if [ $? -ne 1 ]; then
|
||||
echo Cygwin is not supported. Please install a modern GNU/Linux distro.
|
||||
exit
|
||||
fi
|
||||
|
||||
# Setup for Darwin.
|
||||
uname -a | grep Darwin > /dev/null
|
||||
if [ $? -ne 1 ]; then
|
||||
export CC=gcc-11
|
||||
export CXX=g++-11
|
||||
export CPPFLAGS=-I$(brew --prefix)/include
|
||||
export LDFLAGS=-L$(brew --prefix)/lib
|
||||
alias md5sum="md5"
|
||||
alias gcc="gcc-11"
|
||||
alias g++="g++-11"
|
||||
alias sed="gsed"
|
||||
fi
|
||||
|
||||
# Check that the source code is valid.
|
||||
md5sum util/test.txt | grep 9906c52f54b2769da1c31e77d3213d0a > /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "--------------------------------------------------------------------"
|
||||
echo " The source has been corrupted!! "
|
||||
echo " Please check that you have disabled any automatic line-ending or "
|
||||
echo " encoding conversions in Git and archive extraction tools you use. "
|
||||
echo "--------------------------------------------------------------------"
|
||||
exit
|
||||
fi
|
||||
|
||||
# Check the system compiler is reasonably recent.
|
||||
if [ ! -f "bin/good_compiler.txt" ]; then
|
||||
echo "int main() { return __GNUC__ < 9; }" > bin/check_gcc.c
|
||||
g++ -o bin/check_gcc bin/check_gcc.c
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "GCC/G++ could not be found. Please install the latest version of GCC/G++."
|
||||
exit
|
||||
fi
|
||||
bin/check_gcc
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Your system compiler is out of date. Please update to the latest version of GCC/G++."
|
||||
exit
|
||||
fi
|
||||
rm bin/check_gcc.c bin/check_gcc
|
||||
echo yes > "bin/good_compiler.txt"
|
||||
fi
|
||||
|
||||
# Check nasm is available.
|
||||
nasm --version > /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Missing nasm."
|
||||
exit
|
||||
fi
|
||||
|
||||
# Check make is available.
|
||||
make --version > /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Missing make."
|
||||
exit
|
||||
fi
|
||||
|
||||
# Compile the scripting engine.
|
||||
gcc -o bin/script util/script.c -g -Wall -Wextra -O2 -pthread
|
||||
|
||||
# Compile and run Build.
|
||||
gcc -o bin/build -g util/build.c -pthread -DPARALLEL_BUILD -D${ES_TARGET-TARGET_X86_64} \
|
||||
-Wall -Wextra -Wno-format-security -Wno-format-overflow -Wno-missing-field-initializers -Wno-unused-function -Wno-format-truncation \
|
||||
&& bin/build "$@"
|
||||
cd "$(dirname "$0")" && mkdir -p bin && gcc -o bin/script util/script.c -g -Wall -Wextra -O2 -pthread && bin/script util/start.script options="`echo $@`"
|
||||
|
|
|
@ -1555,14 +1555,6 @@ int main(int _argc, char **_argv) {
|
|||
argc = _argc;
|
||||
argv = _argv;
|
||||
|
||||
char cwd[PATH_MAX];
|
||||
getcwd(cwd, sizeof(cwd));
|
||||
|
||||
if (strchr(cwd, ' ')) {
|
||||
printf("Error: The path to your essence directory, '%s', contains spaces.\n", cwd);
|
||||
return 1;
|
||||
}
|
||||
|
||||
sh_new_strdup(applicationDependencies);
|
||||
unlink("bin/dependencies.ini");
|
||||
|
||||
|
|
|
@ -453,6 +453,7 @@ char baseModuleSource[] = {
|
|||
"bool SystemShellExecute(str x) #extcall;" // Returns true on success.
|
||||
"bool SystemShellExecuteWithWorkingDirectory(str wd, str x) #extcall;" // Returns true on success.
|
||||
"str SystemShellEvaluate(str x) #extcall;"
|
||||
"void SystemShellEnableLogging(bool x) #extcall;"
|
||||
};
|
||||
|
||||
// --------------------------------- External function calls.
|
||||
|
@ -467,6 +468,7 @@ int ExternalCharacterToByte(ExecutionContext *context, Value *returnValue);
|
|||
int ExternalSystemShellExecute(ExecutionContext *context, Value *returnValue);
|
||||
int ExternalSystemShellExecuteWithWorkingDirectory(ExecutionContext *context, Value *returnValue);
|
||||
int ExternalSystemShellEvaluate(ExecutionContext *context, Value *returnValue);
|
||||
int ExternalSystemShellEnableLogging(ExecutionContext *context, Value *returnValue);
|
||||
int ExternalSystemGetProcessorCount(ExecutionContext *context, Value *returnValue);
|
||||
int ExternalSystemGetEnvironmentVariable(ExecutionContext *context, Value *returnValue);
|
||||
int ExternalSystemSetEnvironmentVariable(ExecutionContext *context, Value *returnValue);
|
||||
|
@ -497,6 +499,7 @@ ExternalFunction externalFunctions[] = {
|
|||
{ .cName = "SystemShellExecute", .callback = ExternalSystemShellExecute },
|
||||
{ .cName = "SystemShellExecuteWithWorkingDirectory", .callback = ExternalSystemShellExecuteWithWorkingDirectory },
|
||||
{ .cName = "SystemShellEvaluate", .callback = ExternalSystemShellEvaluate },
|
||||
{ .cName = "SystemShellEnableLogging", .callback = ExternalSystemShellEnableLogging },
|
||||
{ .cName = "SystemGetProcessorCount", .callback = ExternalSystemGetProcessorCount },
|
||||
{ .cName = "SystemGetEnvironmentVariable", .callback = ExternalSystemGetEnvironmentVariable },
|
||||
{ .cName = "SystemSetEnvironmentVariable", .callback = ExternalSystemSetEnvironmentVariable },
|
||||
|
@ -4499,6 +4502,8 @@ sem_t externalCoroutineSemaphore;
|
|||
pthread_mutex_t externalCoroutineMutex;
|
||||
CoroutineState *externalCoroutineUnblockedList;
|
||||
|
||||
bool systemShellLoggingEnabled = true;
|
||||
|
||||
int ExternalStringTrim(ExecutionContext *context, Value *returnValue) {
|
||||
(void) returnValue;
|
||||
if (context->c->stackPointer < 1) return -1;
|
||||
|
@ -4622,7 +4627,7 @@ int ExternalSystemShellExecute(ExecutionContext *context, Value *returnValue) {
|
|||
if (temporary) {
|
||||
memcpy(temporary, text, bytes);
|
||||
temporary[bytes] = 0;
|
||||
PrintDebug("\033[0;32m%s\033[0m\n", temporary);
|
||||
if (systemShellLoggingEnabled) PrintDebug("\033[0;32m%s\033[0m\n", temporary);
|
||||
context->c->externalCoroutineData2 = temporary;
|
||||
pthread_t thread;
|
||||
pthread_create(&thread, NULL, SystemShellExecuteThread, context->c);
|
||||
|
@ -4670,7 +4675,7 @@ int ExternalSystemShellExecuteWithWorkingDirectory(ExecutionContext *context, Va
|
|||
memcpy(temporary2, entry2->text, entry2->bytes);
|
||||
temporary2[entry2->bytes] = 0;
|
||||
|
||||
PrintDebug("\033[0;32m(%s) %s\033[0m\n", temporary, temporary2);
|
||||
if (systemShellLoggingEnabled) PrintDebug("\033[0;32m(%s) %s\033[0m\n", temporary, temporary2);
|
||||
|
||||
pid_t pid = fork();
|
||||
|
||||
|
@ -4754,6 +4759,14 @@ int ExternalSystemShellEvaluate(ExecutionContext *context, Value *returnValue) {
|
|||
return 3;
|
||||
}
|
||||
|
||||
int ExternalSystemShellEnableLogging(ExecutionContext *context, Value *returnValue) {
|
||||
(void) returnValue;
|
||||
if (context->c->stackPointer < 1) return -1;
|
||||
systemShellLoggingEnabled = context->c->stack[--context->c->stackPointer].i;
|
||||
if (context->c->stackIsManaged[context->c->stackPointer]) return -1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ExternalPrintStdErr(ExecutionContext *context, Value *returnValue) {
|
||||
(void) returnValue;
|
||||
if (context->c->stackPointer < 1) return -1;
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
// TODO Merge util/build.c into here.
|
||||
|
||||
str options #option;
|
||||
str target #option;
|
||||
|
||||
void Start() {
|
||||
SystemShellEnableLogging(false);
|
||||
|
||||
assert PathCreateLeadingDirectories("bin/dependency_files");
|
||||
assert PathCreateLeadingDirectories("bin/Logs");
|
||||
assert PathCreateLeadingDirectories("bin/generated_code");
|
||||
assert PathCreateLeadingDirectories("bin/cache");
|
||||
assert PathCreateLeadingDirectories("bin/Object Files");
|
||||
|
||||
if SystemGetHostName() == "Cygwin" {
|
||||
PrintStdErrWarning("Building on Cygwin is not supported. Use the Windows Subsystem for Linux instead.\n");
|
||||
assert false;
|
||||
}
|
||||
|
||||
if SystemShellEvaluate("shasum -a 256 util/test.txt")
|
||||
!= "2c5622dbbf2552e0e66424a302bde0918e09379afce47eef1a21ef0198990fed util/test.txt\n" {
|
||||
PrintStdErrWarning("--------------------------------------------------------------------\n");
|
||||
PrintStdErrWarning(" The source has been corrupted!! \n");
|
||||
PrintStdErrWarning(" Please check that you have disabled any automatic line-ending or \n");
|
||||
PrintStdErrWarning(" encoding conversions in Git and archive extraction tools you use. \n");
|
||||
PrintStdErrWarning("--------------------------------------------------------------------\n");
|
||||
assert false;
|
||||
}
|
||||
|
||||
if StringContains(PathGetDefaultPrefix(), " ") {
|
||||
PrintStdErrWarning("Error: The path to your essence directory, '%PathGetDefaultPrefix()%', contains spaces.\n");
|
||||
assert false;
|
||||
}
|
||||
|
||||
if !SystemShellExecute("which gcc > /dev/null") { PrintStdErrWarning("Error: GCC was not found.\n"); assert false; }
|
||||
if !SystemShellExecute("which nasm > /dev/null") { PrintStdErrWarning("Error: Nasm was not found.\n"); assert false; }
|
||||
if !SystemShellExecute("which make > /dev/null") { PrintStdErrWarning("Error: Make was not found.\n"); assert false; }
|
||||
|
||||
if target == "" {
|
||||
target = "TARGET_X86_64";
|
||||
}
|
||||
|
||||
assert SystemShellExecute("gcc -o bin/build -g util/build.c -pthread -DPARALLEL_BUILD -D%target% "
|
||||
+ "-Wall -Wextra -Wno-missing-field-initializers");
|
||||
SystemShellExecute("bin/build %options%");
|
||||
|
||||
PrintStdErrHighlight("\n");
|
||||
}
|
Loading…
Reference in New Issue