Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add var in C API makefile to change compilation mode #301

Merged
merged 2 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
39 changes: 33 additions & 6 deletions crates/gosub-bindings/Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,43 @@
# "global" compile settings
INCLUDE_DIR := include
SRC_DIR := src
CPPFLAGS := -I$(INCLUDE_DIR) -I$(INCLUDE_DIR)/nodes

# compilation mode Release or Debug
MODE?=Release

CFLAGS_DEBUG := -std=c99 -g -Wall -Wextra -O0
CFLAGS_RELEASE := -std=c99 -Wall -Wextra -O2
CFLAGS := $(CFLAGS_DEBUG)

TARGET_DIR_DEBUG := ../../target/debug
TARGET_DIR_RELEASE := ../../target/release

ifeq ($(MODE), Release)
$(info ***** COMPILING IN RELEASE MODE *****)
CFLAGS = $(CFLAGS_RELEASE)
TARGET_DIR = $(TARGET_DIR_RELEASE)
else ifeq ($(MODE), Debug)
$(info ***** COMPILING IN DEBUG MODE *****)
CFLAGS = $(CFLAGS_DEBUG)
TARGET_DIR = $(TARGET_DIR_DEBUG)
else
$(warning ***** UNKNOWN MODE. DEFAULTING TO RELEASE MODE *****)
CFLAGS = $(CFLAGS_RELEASE)
TARGET_DIR = $(TARGET_DIR_RELEASE)
endif

CC := gcc
TARGET_DIR := ../../target/debug

LDFLAGS := -L$(TARGET_DIR)
INCLUDE_DIR := include
SRC_DIR := src
NODE_SRC_DIR := $(SRC_DIR)/nodes

CPPFLAGS := -I$(INCLUDE_DIR) -I$(INCLUDE_DIR)/nodes
LDFLAGS := -L$(TARGET_DIR)

bindings: # build gosub static library to be used externally
ifeq ($(MODE), Debug)
cargo build
else
cargo build --release
endif
$(CC) $(CFLAGS) $(CPPFLAGS) -c $(SRC_DIR)/gosub_api.c $(SRC_DIR)/nodes.c $(NODE_SRC_DIR)/text.c
ar rcs libgosub.a gosub_api.o nodes.o text.o
rm *.o
Expand Down
18 changes: 18 additions & 0 deletions crates/gosub-bindings/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Gosub Bindings
These are the bindings the expose some of Gosub's engine to the world via a C API. Typically these will be used by user agents.
Kiyoshika marked this conversation as resolved.
Show resolved Hide resolved

## Building
By default, the bindings will be built in release mode. You can modify this by specifying a `MODE` variable:
```text
export MODE=Debug # or MODE=Release (default)
make bindings
make test
```

or alternatively specify it manually (not recommended)
```text
make bindings MODE=Debug
make test MODE=Debug
```

This approach is not recommended because if you forget to specify it, it will default to release mode and you may be using the wrong version.