Skip to content

Commit

Permalink
add var to change bindings compilation mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Kiyoshika committed Dec 2, 2023
1 parent 608003a commit 8f8bb4d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
34 changes: 28 additions & 6 deletions crates/gosub-bindings/Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,37 @@
# "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_RELEASE := ../../target/release
TARGET_DIR_DEBUG := ../../target/debug

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
$(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
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.

## 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.

0 comments on commit 8f8bb4d

Please sign in to comment.