Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ jobs:
include:
- suffix: x64-win-dx11
os: windows-latest
build_cmd: bin\build.bat /DWIN32_DX11
build_cmd: .\build.bat --gl-api=DX11
- suffix: x64-win-gl
os: windows-latest
build_cmd: bin\build.bat /DWIN32_OPENGL
build_cmd: .\build.bat --gl-api=OpenGL
- suffix: x64-linux
os: ubuntu-latest
build_cmd: sudo apt update -y && sudo apt install build-essential libx11-dev libxfixes-dev libglx-dev mesa-common-dev libasound2-dev libfreetype-dev libfontconfig-dev -y && ./bin/build-linux.sh
build_cmd: sudo apt update -y && sudo apt install build-essential libx11-dev libxfixes-dev libglx-dev mesa-common-dev libasound2-dev libfreetype-dev libfontconfig-dev -y && ./build.sh
- suffix: x64-mac
os: macos-15-intel
build_cmd: ./bin/build-mac.sh
build_cmd: ./build.sh
# - suffix: arm64-mac
# os: macos-latest
# build_cmd: arch -arch x86_64 ./bin/build-mac.sh
Expand All @@ -29,7 +29,7 @@ jobs:
- uses: actions/checkout@v4
- uses: ilammy/msvc-dev-cmd@v1.4.1 # this is a no-op on Linux and macOS
- name: Build 4cc-${{ matrix.suffix }}
run: cd code && ${{ matrix.build_cmd }} && cd ..
run: ${{ matrix.build_cmd }}
- name: Generate 4cc Artifacts
uses: actions/upload-artifact@v4.6.0
with:
Expand Down
73 changes: 41 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,49 @@

# Building

## Windows
## Build script parameter

> [!NOTE]
> 4coder needs the MSVC compiler and windows SDK from the "Desktop development with C++" component. If you don’t have this already, you can download the installer [here](https://visualstudio.microsoft.com/downloads/). Make sure to at least click on "Desktop development with C++" and tick the boxes for MSVC and the Windows SDK.
```
Usage: build [options]

1. Setup the MSVC toolchain in your environment, this can be done either with the `code/custom/bin/setup_cl_x64.bat` script or by using the development shell in windows terminal
2. Execute this command from the root of the project (the resulting executable will be under the `build` folder in the root of the repo)
Options:
-m=<string>, --mode=<string>
Sets build mode
Available modes:
- debug
- release
Default: debug

-gl=<string> --gl-api=<string>
Sets the graphics API to use
Available backends:
- OpenGL
- DX11 (Windows only)
Default: OpenGL

-s, --symbols
Adds debug symbols. Already set by --mode=debug.

-o, --optimizations
Adds optimizations. Already set by --mode=release.

-h, --help
Display this help text and exit

-v, --verbose
Display build debug information like command currentely executing

```batch
cd code && .\bin\build.bat
```

In addition to the parameter listed below, you can specify which backend to use by passing one of those parameters to the build scripts:
- `/DWIN32_OPENGL` (default) to use the OpenGL backend.
- `/DWIN32_DX11` to use the Direct3D 11 backend.
Comment thread
saccarosium marked this conversation as resolved.
## Windows

> [!NOTE]
> 4coder needs the MSVC compiler and windows SDK from the "Desktop development with C++" component. If you don’t have this already, you can download the installer [here](https://visualstudio.microsoft.com/downloads/). Make sure to at least click on "Desktop development with C++" and tick the boxes for MSVC and the Windows SDK.

1. Execute this command from the root of the project (the resulting executable will be under the `build` folder in the root of the repo)

```batch
cd code && .\bin\build.bat /DWIN32_DX11
```cmd
.\build.bat
```

## Linux
Expand All @@ -35,7 +60,7 @@ sudo apt install build-essential libx11-dev libxfixes-dev libglx-dev mesa-common
2. Execute this command from the root of the project (the resulting executable will be under the `build` folder in the root of the repo)

```sh
cd code && ./bin/build-linux.sh
./build.sh
```

## Mac
Expand All @@ -45,27 +70,11 @@ cd code && ./bin/build-linux.sh
1. Execute this command from the root of the project (the resulting executable will be under the `build` folder in the root of the repo)

```sh
cd code && ./bin/build-mac.sh
./build.sh
# For M1+ Macs
arch -arch x86_64 ./build.sh
```

### Older Macs, 10.15.7 Catalina

If you are using an older version of mac, such as 10.15.7 Catalina you need to install the realpath command:

1. `$ sudo port install coreutils`
2. macports names the `realpath` command `grealpath`, so make a symbolic link in order to use build-mac.sh:
`$ sudo ln -s /opt/local/bin/grealpath /opt/local/bin/realpath`

## Build script parameter

The build script accepts a parameter (mutually exclusive):
- `/DDEV_BUILD` (default value) : build without optimizations.
Produces debug symbols.
Defines: `FRED_INTERNAL`, `FRED_SUPER`, `DO_CRAZY_EXPENSIVE_ASSERTS` (on Windows) macros.
- `/DOPT_BUILD` (similar to `build_optimized` script): build with optimizations.
Doesn't produce debug symbols.
Defines `FRED_SUPER` macro.

## API generators

4coder uses several small programs to generate some headers and source files. Those do not run automatically, you must build them and run them when needed (which shouldn't really happen).
Expand Down
27 changes: 27 additions & 0 deletions build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@echo off

set prev_cwd=%cd%

rem Make sure we are at the root of the project
cd /D "%~dp0"

set src_root=%cd%\code
set custom_root=%src_root%\custom
set build_root=%cd%\build

rem If the user want's 32 bits they need to setup MSVC before calling the script.
call %custom_root%\bin\setup_cl_x64.bat

set opts=/nologo /FC /Zi /I%src_root% /I%custom_root%

if not exist "%build_root%" mkdir %build_root%
pushd %build_root%
call cl %opts% %src_root%\4ed_build.cpp /Febuild
popd

if %ERRORLEVEL% neq 0 goto END

%build_root%\build.exe %*

:END
cd /D "%prev_cwd%"
38 changes: 38 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/sh

# '/bin/sh' is the most portable way to write a shellscript but doesn't
# support some features that bash does (e.g. using '[[' is not supported
# you can you '[').
#
# To be sure that the script is portable and fully POSIX # compliant use a
# tool like shellcheck to validate it.
#
# https://github.com/koalaman/shellcheck

# shellcheck disable=SC2048,SC2086

set -e

# Make sure we are at the root of the project
cd "$(realpath "$(dirname "$0")")"

SRC_ROOT="$PWD/code"
CUSTOM_ROOT="$SRC_ROOT/custom"
BUILD_ROOT="$PWD/build"

# c++ is the default toolchain's compiler installed on the machine
if [ -z "$CC" ]; then
CC=c++
fi

CFLAGS="-D_GNU_SOURCE -fPIC -fpermissive -Wno-write-strings -Wno-comment"
CFLAGS="$CFLAGS -Wno-null-dereference -Wno-logical-op-parentheses -Wno-switch"
CFLAGS="$CFLAGS -I$SRC_ROOT -I$CUSTOM_ROOT"

if [ ! -d "$BUILD_ROOT" ]; then
mkdir -p "$BUILD_ROOT"
fi

eval "$CC $CFLAGS $SRC_ROOT/4ed_build.cpp -g -o $BUILD_ROOT/build"

"$BUILD_ROOT/build" $*
Loading
Loading