2015-02-22 10:19:23 -08:00
|
|
|
# Makefile for building a single configuration of Wren. It allows the
|
|
|
|
|
# following variables to be passed to it:
|
|
|
|
|
#
|
|
|
|
|
# MODE - The build mode, "debug" or "release".
|
|
|
|
|
# If omitted, defaults to "release".
|
|
|
|
|
# LANG - The language, "c" or "cpp".
|
|
|
|
|
# If omitted, defaults to "c".
|
|
|
|
|
# ARCH - The processor architecture, "32", "64", or nothing, which indicates
|
|
|
|
|
# the compiler's default.
|
|
|
|
|
# If omitted, defaults to the compiler's default.
|
|
|
|
|
#
|
|
|
|
|
# It builds a static library, shared library, and command-line interpreter for
|
|
|
|
|
# the given configuration. Libraries are built to "lib", and the interpreter
|
|
|
|
|
# is built to "bin".
|
|
|
|
|
#
|
|
|
|
|
# The output file is initially "wren". If in debug mode, "d" is appended to it.
|
|
|
|
|
# If the language is "cpp", then "-cpp" is appended to that. If the
|
|
|
|
|
# architecture is not the default then "-32" or "-64" is appended to that.
|
|
|
|
|
# Then, for the libraries, the correct extension is added.
|
|
|
|
|
|
|
|
|
|
# Files.
|
2015-10-24 09:23:25 -07:00
|
|
|
OPT_HEADERS := $(wildcard src/optional/*.h) $(wildcard src/optional/*.wren.inc)
|
|
|
|
|
OPT_SOURCES := $(wildcard src/optional/*.c)
|
2015-10-17 22:09:48 -07:00
|
|
|
|
2015-03-14 15:00:50 -07:00
|
|
|
CLI_HEADERS := $(wildcard src/cli/*.h)
|
|
|
|
|
CLI_SOURCES := $(wildcard src/cli/*.c)
|
2015-08-07 08:10:55 -07:00
|
|
|
|
2015-09-13 10:03:02 -07:00
|
|
|
MODULE_HEADERS := $(wildcard src/module/*.h) $(wildcard src/module/*.wren.inc)
|
2015-08-07 08:10:55 -07:00
|
|
|
MODULE_SOURCES := $(wildcard src/module/*.c)
|
|
|
|
|
|
2015-09-13 10:03:02 -07:00
|
|
|
VM_HEADERS := $(wildcard src/vm/*.h) $(wildcard src/vm/*.wren.inc)
|
2015-03-14 15:00:50 -07:00
|
|
|
VM_SOURCES := $(wildcard src/vm/*.c)
|
2015-08-07 08:10:55 -07:00
|
|
|
|
2015-08-28 23:13:56 -07:00
|
|
|
TEST_HEADERS := $(wildcard test/api/*.h)
|
2015-08-13 09:09:27 -07:00
|
|
|
TEST_SOURCES := $(wildcard test/api/*.c)
|
2015-08-28 23:13:56 -07:00
|
|
|
|
2015-02-22 10:19:23 -08:00
|
|
|
BUILD_DIR := build
|
|
|
|
|
|
2015-03-24 07:51:48 -07:00
|
|
|
C_WARNINGS := -Wall -Wextra -Werror -Wno-unused-parameter
|
2015-03-22 22:17:29 -07:00
|
|
|
# Wren uses callbacks heavily, so -Wunused-parameter is too painful to enable.
|
2015-02-22 10:19:23 -08:00
|
|
|
|
|
|
|
|
# Mode configuration.
|
|
|
|
|
ifeq ($(MODE),debug)
|
|
|
|
|
WREN := wrend
|
2015-03-24 07:51:48 -07:00
|
|
|
C_OPTIONS += -O0 -DDEBUG -g
|
2015-02-22 10:19:23 -08:00
|
|
|
BUILD_DIR := $(BUILD_DIR)/debug
|
|
|
|
|
else
|
|
|
|
|
WREN += wren
|
2015-11-10 07:33:15 -08:00
|
|
|
C_OPTIONS += -O3
|
2015-02-22 10:19:23 -08:00
|
|
|
BUILD_DIR := $(BUILD_DIR)/release
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
# Language configuration.
|
|
|
|
|
ifeq ($(LANG),cpp)
|
|
|
|
|
WREN := $(WREN)-cpp
|
2015-03-24 07:51:48 -07:00
|
|
|
C_OPTIONS += -std=c++98
|
2015-02-22 10:19:23 -08:00
|
|
|
FILE_FLAG := -x c++
|
|
|
|
|
BUILD_DIR := $(BUILD_DIR)-cpp
|
|
|
|
|
else
|
2015-08-16 09:57:47 -07:00
|
|
|
C_OPTIONS += -std=c99
|
2015-02-22 10:19:23 -08:00
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
# Architecture configuration.
|
|
|
|
|
ifeq ($(ARCH),32)
|
2015-03-24 07:51:48 -07:00
|
|
|
C_OPTIONS += -m32
|
2015-02-22 10:19:23 -08:00
|
|
|
WREN := $(WREN)-32
|
|
|
|
|
BUILD_DIR := $(BUILD_DIR)-32
|
2015-08-28 19:31:03 -07:00
|
|
|
LIBUV_ARCH := -32
|
2015-02-22 10:19:23 -08:00
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
ifeq ($(ARCH),64)
|
2015-03-24 07:51:48 -07:00
|
|
|
C_OPTIONS += -m64
|
2015-02-22 10:19:23 -08:00
|
|
|
WREN := $(WREN)-64
|
|
|
|
|
BUILD_DIR := $(BUILD_DIR)-64
|
2015-08-28 19:31:03 -07:00
|
|
|
LIBUV_ARCH := -64
|
2015-02-22 10:19:23 -08:00
|
|
|
endif
|
|
|
|
|
|
2015-03-01 09:25:48 -08:00
|
|
|
# Some platform-specific workarounds. Note that we use "gcc" explicitly in the
|
|
|
|
|
# call to get the machine name because one of these workarounds deals with $(CC)
|
|
|
|
|
# itself not working.
|
|
|
|
|
OS := $(lastword $(subst -, ,$(shell gcc -dumpmachine)))
|
|
|
|
|
|
2015-02-22 10:19:23 -08:00
|
|
|
# Don't add -fPIC on Windows since it generates a warning which gets promoted
|
|
|
|
|
# to an error by -Werror.
|
|
|
|
|
ifeq ($(OS),mingw32)
|
|
|
|
|
else ifeq ($(OS),cygwin)
|
|
|
|
|
# Do nothing.
|
|
|
|
|
else
|
2015-03-24 07:51:48 -07:00
|
|
|
C_OPTIONS += -fPIC
|
2015-02-22 10:19:23 -08:00
|
|
|
endif
|
|
|
|
|
|
2015-03-01 09:25:48 -08:00
|
|
|
# MinGW--or at least some versions of it--default CC to "cc" but then don't
|
|
|
|
|
# provide an executable named "cc". Manually point to "gcc" instead.
|
|
|
|
|
ifeq ($(OS),mingw32)
|
|
|
|
|
CC = GCC
|
|
|
|
|
endif
|
|
|
|
|
|
2015-02-22 10:19:23 -08:00
|
|
|
# Clang on Mac OS X has different flags and a different extension to build a
|
|
|
|
|
# shared library.
|
|
|
|
|
ifneq (,$(findstring darwin,$(OS)))
|
|
|
|
|
SHARED_EXT := dylib
|
|
|
|
|
else
|
|
|
|
|
SHARED_LIB_FLAGS := -Wl,-soname,$@.so
|
|
|
|
|
SHARED_EXT := so
|
2015-08-16 10:28:55 -07:00
|
|
|
|
|
|
|
|
# On Linux we need to explicitly link to these for libuv.
|
|
|
|
|
LIBUV_LIBS := -lpthread -lrt
|
2015-02-22 10:19:23 -08:00
|
|
|
endif
|
|
|
|
|
|
2015-03-24 07:51:48 -07:00
|
|
|
CFLAGS := $(C_OPTIONS) $(C_WARNINGS)
|
|
|
|
|
|
2015-10-24 09:23:25 -07:00
|
|
|
OPT_OBJECTS := $(addprefix $(BUILD_DIR)/optional/, $(notdir $(OPT_SOURCES:.c=.o)))
|
2015-08-07 08:10:55 -07:00
|
|
|
CLI_OBJECTS := $(addprefix $(BUILD_DIR)/cli/, $(notdir $(CLI_SOURCES:.c=.o)))
|
|
|
|
|
MODULE_OBJECTS := $(addprefix $(BUILD_DIR)/module/, $(notdir $(MODULE_SOURCES:.c=.o)))
|
|
|
|
|
VM_OBJECTS := $(addprefix $(BUILD_DIR)/vm/, $(notdir $(VM_SOURCES:.c=.o)))
|
|
|
|
|
TEST_OBJECTS := $(patsubst test/api/%.c, $(BUILD_DIR)/test/%.o, $(TEST_SOURCES))
|
2015-02-22 10:19:23 -08:00
|
|
|
|
2015-08-28 19:31:03 -07:00
|
|
|
LIBUV_DIR := deps/libuv
|
|
|
|
|
LIBUV := build/libuv$(LIBUV_ARCH).a
|
2015-08-02 10:43:38 -07:00
|
|
|
|
2015-08-08 08:57:57 -07:00
|
|
|
# Flags needed to compile source files for the CLI, including the modules and
|
|
|
|
|
# API tests.
|
2015-08-08 09:06:40 -07:00
|
|
|
CLI_FLAGS := -D_XOPEN_SOURCE=600 -Isrc/include -I$(LIBUV_DIR)/include \
|
2015-08-08 08:57:57 -07:00
|
|
|
-Isrc/cli -Isrc/module
|
|
|
|
|
|
2015-02-22 10:19:23 -08:00
|
|
|
# Targets ---------------------------------------------------------------------
|
|
|
|
|
|
2015-05-24 09:23:30 -07:00
|
|
|
# Builds the VM libraries and CLI interpreter.
|
2015-08-02 10:43:38 -07:00
|
|
|
all: vm cli
|
|
|
|
|
|
|
|
|
|
# Builds just the VM libraries.
|
|
|
|
|
vm: lib/lib$(WREN).a lib/lib$(WREN).$(SHARED_EXT)
|
|
|
|
|
|
|
|
|
|
# Builds just the CLI interpreter.
|
|
|
|
|
cli: bin/$(WREN)
|
2015-02-22 10:19:23 -08:00
|
|
|
|
2015-05-24 09:23:30 -07:00
|
|
|
# Builds the API test executable.
|
|
|
|
|
test: $(BUILD_DIR)/test/$(WREN)
|
2015-02-22 10:19:23 -08:00
|
|
|
|
|
|
|
|
# Command-line interpreter.
|
2015-10-24 09:23:25 -07:00
|
|
|
bin/$(WREN): $(OPT_OBJECTS) $(CLI_OBJECTS) $(MODULE_OBJECTS) $(VM_OBJECTS) \
|
2015-10-17 22:09:48 -07:00
|
|
|
$(LIBUV)
|
2015-08-28 19:31:03 -07:00
|
|
|
@ printf "%10s %-30s %s\n" $(CC) $@ "$(C_OPTIONS)"
|
|
|
|
|
@ mkdir -p bin
|
|
|
|
|
@ $(CC) $(CFLAGS) $^ -o $@ -lm $(LIBUV_LIBS)
|
2015-02-22 10:19:23 -08:00
|
|
|
|
|
|
|
|
# Static library.
|
2015-10-24 09:23:25 -07:00
|
|
|
lib/lib$(WREN).a: $(OPT_OBJECTS) $(VM_OBJECTS)
|
2015-08-28 19:31:03 -07:00
|
|
|
@ printf "%10s %-30s %s\n" $(AR) $@ "rcu"
|
|
|
|
|
@ mkdir -p lib
|
|
|
|
|
@ $(AR) rcu $@ $^
|
2015-02-22 10:19:23 -08:00
|
|
|
|
|
|
|
|
# Shared library.
|
2015-10-24 09:23:25 -07:00
|
|
|
lib/lib$(WREN).$(SHARED_EXT): $(OPT_OBJECTS) $(VM_OBJECTS)
|
2015-08-28 19:31:03 -07:00
|
|
|
@ printf "%10s %-30s %s\n" $(CC) $@ "$(C_OPTIONS) $(SHARED_LIB_FLAGS)"
|
|
|
|
|
@ mkdir -p lib
|
|
|
|
|
@ $(CC) $(CFLAGS) -shared $(SHARED_LIB_FLAGS) -o $@ $^
|
2015-02-22 10:19:23 -08:00
|
|
|
|
2015-05-24 09:23:30 -07:00
|
|
|
# Test executable.
|
2015-10-24 09:23:25 -07:00
|
|
|
$(BUILD_DIR)/test/$(WREN): $(OPT_OBJECTS) $(MODULE_OBJECTS) $(TEST_OBJECTS) \
|
2015-10-17 22:09:48 -07:00
|
|
|
$(VM_OBJECTS) $(BUILD_DIR)/cli/modules.o $(BUILD_DIR)/cli/vm.o $(LIBUV)
|
2015-08-28 19:31:03 -07:00
|
|
|
@ printf "%10s %-30s %s\n" $(CC) $@ "$(C_OPTIONS)"
|
|
|
|
|
@ mkdir -p $(BUILD_DIR)/test
|
|
|
|
|
@ $(CC) $(CFLAGS) $^ -o $@ -lm $(LIBUV_LIBS)
|
2015-05-24 09:23:30 -07:00
|
|
|
|
2015-03-14 15:00:50 -07:00
|
|
|
# CLI object files.
|
2015-08-28 19:31:03 -07:00
|
|
|
$(BUILD_DIR)/cli/%.o: src/cli/%.c $(CLI_HEADERS) $(MODULE_HEADERS) \
|
|
|
|
|
$(VM_HEADERS) $(LIBUV)
|
|
|
|
|
@ printf "%10s %-30s %s\n" $(CC) $< "$(C_OPTIONS)"
|
|
|
|
|
@ mkdir -p $(BUILD_DIR)/cli
|
|
|
|
|
@ $(CC) -c $(CFLAGS) $(CLI_FLAGS) -o $@ $(FILE_FLAG) $<
|
2015-08-07 08:10:55 -07:00
|
|
|
|
|
|
|
|
# Module object files.
|
2015-08-28 19:31:03 -07:00
|
|
|
$(BUILD_DIR)/module/%.o: src/module/%.c $(CLI_HEADERS) $(MODULE_HEADERS) \
|
|
|
|
|
$(VM_HEADERS) $(LIBUV)
|
|
|
|
|
@ printf "%10s %-30s %s\n" $(CC) $< "$(C_OPTIONS)"
|
|
|
|
|
@ mkdir -p $(BUILD_DIR)/module
|
|
|
|
|
@ $(CC) -c $(CFLAGS) $(CLI_FLAGS) -o $@ $(FILE_FLAG) $<
|
2015-03-14 15:00:50 -07:00
|
|
|
|
2015-10-17 22:09:48 -07:00
|
|
|
# Aux object files.
|
2015-10-24 09:23:25 -07:00
|
|
|
$(BUILD_DIR)/optional/%.o: src/optional/%.c $(VM_HEADERS) $(OPT_HEADERS)
|
2015-10-17 22:09:48 -07:00
|
|
|
@ printf "%10s %-30s %s\n" $(CC) $< "$(C_OPTIONS)"
|
2015-10-24 09:23:25 -07:00
|
|
|
@ mkdir -p $(BUILD_DIR)/optional
|
2015-10-17 22:09:48 -07:00
|
|
|
@ $(CC) -c $(CFLAGS) -Isrc/include -Isrc/vm -o $@ $(FILE_FLAG) $<
|
|
|
|
|
|
2015-03-14 15:00:50 -07:00
|
|
|
# VM object files.
|
|
|
|
|
$(BUILD_DIR)/vm/%.o: src/vm/%.c $(VM_HEADERS)
|
2015-08-28 19:31:03 -07:00
|
|
|
@ printf "%10s %-30s %s\n" $(CC) $< "$(C_OPTIONS)"
|
|
|
|
|
@ mkdir -p $(BUILD_DIR)/vm
|
2015-10-24 09:23:25 -07:00
|
|
|
@ $(CC) -c $(CFLAGS) -Isrc/include -Isrc/optional -Isrc/vm -o $@ $(FILE_FLAG) $<
|
2015-05-24 09:23:30 -07:00
|
|
|
|
|
|
|
|
# Test object files.
|
2015-10-24 09:23:25 -07:00
|
|
|
$(BUILD_DIR)/test/%.o: test/api/%.c $(OPT_HEADERS) $(MODULE_HEADERS) \
|
2015-10-17 22:09:48 -07:00
|
|
|
$(VM_HEADERS) $(TEST_HEADERS) $(LIBUV)
|
2015-08-28 19:31:03 -07:00
|
|
|
@ printf "%10s %-30s %s\n" $(CC) $< "$(C_OPTIONS)"
|
|
|
|
|
@ mkdir -p $(dir $@)
|
|
|
|
|
@ $(CC) -c $(CFLAGS) $(CLI_FLAGS) -o $@ $(FILE_FLAG) $<
|
|
|
|
|
|
|
|
|
|
# Download libuv.
|
2015-09-22 07:45:58 -07:00
|
|
|
$(LIBUV_DIR)/build/gyp/gyp: util/libuv.py
|
|
|
|
|
@ ./util/libuv.py download
|
2015-08-28 19:31:03 -07:00
|
|
|
|
|
|
|
|
# Build libuv to a static library.
|
2015-09-22 07:45:58 -07:00
|
|
|
$(LIBUV): $(LIBUV_DIR)/build/gyp/gyp util/libuv.py
|
|
|
|
|
@ ./util/libuv.py build $(LIBUV_ARCH)
|
2015-05-24 09:23:30 -07:00
|
|
|
|
2015-09-13 10:03:02 -07:00
|
|
|
# Wren modules that get compiled into the binary as C strings.
|
2015-10-24 09:23:25 -07:00
|
|
|
src/optional/wren_opt_%.wren.inc: src/optional/wren_opt_%.wren util/wren_to_c_string.py
|
2015-12-26 20:11:48 -08:00
|
|
|
@ printf "%10s %-30s %s\n" str $<
|
2015-10-17 22:09:48 -07:00
|
|
|
@ ./util/wren_to_c_string.py $@ $<
|
|
|
|
|
|
2015-10-17 22:17:10 -07:00
|
|
|
src/vm/wren_%.wren.inc: src/vm/wren_%.wren util/wren_to_c_string.py
|
2015-12-26 20:11:48 -08:00
|
|
|
@ printf "%10s %-30s %s\n" str $<
|
2015-09-22 07:45:58 -07:00
|
|
|
@ ./util/wren_to_c_string.py $@ $<
|
2015-09-13 10:03:02 -07:00
|
|
|
|
2015-09-22 07:45:58 -07:00
|
|
|
src/module/%.wren.inc: src/module/%.wren util/wren_to_c_string.py
|
2015-12-26 20:11:48 -08:00
|
|
|
@ printf "%10s %-30s %s\n" str $<
|
2015-09-22 07:45:58 -07:00
|
|
|
@ ./util/wren_to_c_string.py $@ $<
|
2015-09-13 10:03:02 -07:00
|
|
|
|
2015-08-02 10:43:38 -07:00
|
|
|
.PHONY: all cli test vm
|