From 3a0691aa3bc940939feaecb8ae20ee8102f98e54 Mon Sep 17 00:00:00 2001 From: snit Date: Sat, 28 Sep 2024 01:34:31 -0500 Subject: [PATCH] initial setup --- .gitignore | 1 + CMakeLists.txt | 32 ++++++++++++++++++++++++++++++++ README.gmi | 18 ++++++++++++++++++ build.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/main.c | 8 ++++++++ 5 files changed, 104 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 README.gmi create mode 100755 build.sh create mode 100644 src/main.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..567609b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..5f04588 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,32 @@ +cmake_minimum_required(VERSION 3.10) + +# Set the project name and specify the languages +project(simworld LANGUAGES C) + +# Set compiler flags +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat=2 -Wshadow -Wwrite-strings -Wstrict-prototypes") + +# Specify the source directory +set(SOURCE_DIR ${CMAKE_SOURCE_DIR}/src) + +# Create a list of source files +file(GLOB_RECURSE SOURCES ${SOURCE_DIR}/*.c) + +# Create the executable from the source files +add_executable(${PROJECT_NAME} ${SOURCES}) + +# Dependencies +find_package(PkgConfig REQUIRED) +pkg_check_modules(LUA REQUIRED lua) + +target_link_libraries(${PROJECT_NAME} ${LUA_LIBRARIES}) +target_include_directories(${PROJECT_NAME} PRIVATE ${LUA_INCLUDE_DIRS}) + +# `#define DEBUG` if `cmake -DCMAKE_BUILD_TYPE=debug` +if(CMAKE_BUILD_TYPE STREQUAL "debug") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g") + target_compile_definitions(${PROJECT_NAME} PRIVATE BUILD_DEBUG) +else() + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2") + target_compile_definitions(${PROJECT_NAME} PRIVATE BUILD_RELEASE) +endif() diff --git a/README.gmi b/README.gmi new file mode 100644 index 0000000..d1b5dd3 --- /dev/null +++ b/README.gmi @@ -0,0 +1,18 @@ +# Simworld Lite +Simworld is a zero-player game in which players create simulated environments and ecosystems that run with no user intervention. The environments and the creatures that inhabit them are all completely defined through user-created mods. Though there's no real goal to the game, a good challenge is to create ecosystems that are self-sustaining and can thus run indefinitely. + +Note: I'm not galaxy-brained enough to do the full idea at the moment, so this is the "lite" version, contianing only the bare minimum to make the idea work. + +## Build from Source +### Dependencies +* CMake +* Lua 5.4 + +### Building +``` +mkdir -p build/ +cd build/ +cmake .. +make +./simworld +``` diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..ef09b6d --- /dev/null +++ b/build.sh @@ -0,0 +1,45 @@ +#!/bin/sh + +set -e + +run_exe=0 + +## Ensure first argument is correct +if [ "$1" = "debug" ]; then + debug=1 +elif [ "$1" = "release" ]; then + debug=0 +else + echo "Run as '$0 debug' or '$0 release'" + exit 1 +fi + +## Ensure second argument is correct +if [ "$2" = "run" ]; then + run_exe=1 +fi + +## Ensure its run in the right place +if ! [ -f "CMakeLists.txt" ]; then + echo "Run in the project root" + exit 1 +fi + +mkdir -p build +cd build || exit + +if [ ${debug} -eq 1 ]; then + echo debug + cmake -DCMAKE_BUILD_TYPE=debug .. +else + echo release + cmake -DCMAKE_BUILD_TYPE=release .. +fi + +make + +if [ ${run_exe} -eq 1 ]; then + ./simworld +fi + +cd .. diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..ab3a851 --- /dev/null +++ b/src/main.c @@ -0,0 +1,8 @@ +// main.c + +#include + +int main(void) { + puts("Hello, world!"); + return 0; +}