forked from Mirror/wren
Reorganize build scripts for libuv.
- Create separate libs for each architecture. OS X doesn't need this (we just build a universal binary), but it will help Linux. - Move the libuv build stuff into wren.mk where the actual dependency on the lib is. - Download libuv to deps/ instead of build/. That way "make clean" doesn't blow it away. - Don't redownload libuv unless needed.
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,6 +5,7 @@ wren
|
|||||||
|
|
||||||
# Intermediate files.
|
# Intermediate files.
|
||||||
build/
|
build/
|
||||||
|
deps/
|
||||||
.sass-cache/
|
.sass-cache/
|
||||||
|
|
||||||
# I leave a temporary Wren script at the top level so that I can quickly test
|
# I leave a temporary Wren script at the top level so that I can quickly test
|
||||||
|
|||||||
19
Makefile
19
Makefile
@ -4,18 +4,16 @@
|
|||||||
|
|
||||||
# Executables are built to bin/. Libraries are built to lib/.
|
# Executables are built to bin/. Libraries are built to lib/.
|
||||||
|
|
||||||
LIBUV := build/libuv/out/Release/libuv.a
|
|
||||||
|
|
||||||
# A normal, optimized release build for the current CPU architecture.
|
# A normal, optimized release build for the current CPU architecture.
|
||||||
release: $(LIBUV)
|
release:
|
||||||
@ $(MAKE) -f script/wren.mk
|
@ $(MAKE) -f script/wren.mk
|
||||||
@ cp bin/wren wren # For convenience, copy the interpreter to the top level.
|
@ cp bin/wren wren # For convenience, copy the interpreter to the top level.
|
||||||
|
|
||||||
# A debug build for the current architecture.
|
# A debug build for the current architecture.
|
||||||
debug: $(LIBUV)
|
debug:
|
||||||
@ $(MAKE) -f script/wren.mk MODE=debug
|
@ $(MAKE) -f script/wren.mk MODE=debug
|
||||||
|
|
||||||
# A release build of just the VM. Does not require libuv.
|
# A release build of just the VM.
|
||||||
vm:
|
vm:
|
||||||
@ $(MAKE) -f script/wren.mk vm
|
@ $(MAKE) -f script/wren.mk vm
|
||||||
|
|
||||||
@ -32,16 +30,17 @@ all: debug release
|
|||||||
@ $(MAKE) -f script/wren.mk MODE=debug ARCH=64
|
@ $(MAKE) -f script/wren.mk MODE=debug ARCH=64
|
||||||
@ $(MAKE) -f script/wren.mk MODE=debug LANG=cpp ARCH=64
|
@ $(MAKE) -f script/wren.mk MODE=debug LANG=cpp ARCH=64
|
||||||
|
|
||||||
# Download and build libuv to a static library.
|
# Remove all build outputs and intermediate files. Does not remove downloaded
|
||||||
$(LIBUV): script/libuv.py
|
# dependencies. Use cleanall for that.
|
||||||
@ ./script/libuv.py
|
|
||||||
|
|
||||||
# Remove all build outputs and intermediate files.
|
|
||||||
clean:
|
clean:
|
||||||
@ rm -rf bin
|
@ rm -rf bin
|
||||||
@ rm -rf build
|
@ rm -rf build
|
||||||
@ rm -rf lib
|
@ rm -rf lib
|
||||||
|
|
||||||
|
# Remove all build outputs, intermediate files, and downloaded dependencies.
|
||||||
|
cleanall: clean
|
||||||
|
@ rm -rf deps
|
||||||
|
|
||||||
# Run the tests against the debug build of Wren.
|
# Run the tests against the debug build of Wren.
|
||||||
test: debug
|
test: debug
|
||||||
@ $(MAKE) -f script/wren.mk MODE=debug test
|
@ $(MAKE) -f script/wren.mk MODE=debug test
|
||||||
|
|||||||
@ -12,7 +12,7 @@ import subprocess
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
LIB_UV_VERSION = "v1.6.1"
|
LIB_UV_VERSION = "v1.6.1"
|
||||||
LIB_UV_DIR = "build/libuv"
|
LIB_UV_DIR = "deps/libuv"
|
||||||
|
|
||||||
def ensure_dir(dir):
|
def ensure_dir(dir):
|
||||||
"""Creates dir if not already there."""
|
"""Creates dir if not already there."""
|
||||||
@ -22,6 +22,7 @@ def ensure_dir(dir):
|
|||||||
|
|
||||||
os.makedirs(dir)
|
os.makedirs(dir)
|
||||||
|
|
||||||
|
|
||||||
def remove_dir(dir):
|
def remove_dir(dir):
|
||||||
"""Recursively removes dir."""
|
"""Recursively removes dir."""
|
||||||
|
|
||||||
@ -31,10 +32,11 @@ def remove_dir(dir):
|
|||||||
subprocess.check_call(
|
subprocess.check_call(
|
||||||
['cmd', '/c', 'rd', '/s', '/q', dir.replace('/', '\\')])
|
['cmd', '/c', 'rd', '/s', '/q', dir.replace('/', '\\')])
|
||||||
else:
|
else:
|
||||||
shutil.rmtree(LIB_UV_DIR)
|
shutil.rmtree(dir)
|
||||||
|
|
||||||
|
|
||||||
def download_libuv():
|
def download_libuv():
|
||||||
"""Clones libuv into build/libuv and checks out the right version."""
|
"""Clones libuv into deps/libuv and checks out the right version."""
|
||||||
|
|
||||||
# Delete it if already there so we ensure we get the correct version if the
|
# Delete it if already there so we ensure we get the correct version if the
|
||||||
# version number in this script changes.
|
# version number in this script changes.
|
||||||
@ -42,7 +44,7 @@ def download_libuv():
|
|||||||
print("Cleaning output directory...")
|
print("Cleaning output directory...")
|
||||||
remove_dir(LIB_UV_DIR)
|
remove_dir(LIB_UV_DIR)
|
||||||
|
|
||||||
ensure_dir("build")
|
ensure_dir("deps")
|
||||||
|
|
||||||
print("Cloning libuv...")
|
print("Cloning libuv...")
|
||||||
run([
|
run([
|
||||||
@ -90,7 +92,7 @@ def build_libuv_mac():
|
|||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
def build_libuv_linux():
|
def build_libuv_linux(arch):
|
||||||
run(["python", "gyp_uv.py", "-f", "make"], cwd=LIB_UV_DIR)
|
run(["python", "gyp_uv.py", "-f", "make"], cwd=LIB_UV_DIR)
|
||||||
run(["make", "-C", "out", "BUILDTYPE=Release"], cwd=LIB_UV_DIR)
|
run(["make", "-C", "out", "BUILDTYPE=Release"], cwd=LIB_UV_DIR)
|
||||||
|
|
||||||
@ -99,17 +101,24 @@ def build_libuv_windows():
|
|||||||
run(["cmd", "/c", "vcbuild.bat", "release"], cwd=LIB_UV_DIR)
|
run(["cmd", "/c", "vcbuild.bat", "release"], cwd=LIB_UV_DIR)
|
||||||
|
|
||||||
|
|
||||||
def build_libuv():
|
def build_libuv(arch, out):
|
||||||
if platform.system() == "Darwin":
|
if platform.system() == "Darwin":
|
||||||
build_libuv_mac()
|
build_libuv_mac()
|
||||||
elif platform.system() == "Linux":
|
elif platform.system() == "Linux":
|
||||||
build_libuv_linux()
|
build_libuv_linux(arch)
|
||||||
elif platform.system() == "Windows":
|
elif platform.system(arch) == "Windows":
|
||||||
build_libuv_windows()
|
build_libuv_windows()
|
||||||
else:
|
else:
|
||||||
print("Unsupported platform: " + platform.system())
|
print("Unsupported platform: " + platform.system())
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
# Copy the build library to the build directory for Mac and Linux where we
|
||||||
|
# support building for multiple architectures.
|
||||||
|
if platform.system() != "Windows":
|
||||||
|
ensure_dir(os.path.dirname(out))
|
||||||
|
shutil.copyfile(
|
||||||
|
os.path.join(LIB_UV_DIR, "out", "Release", "libuv.a"), out)
|
||||||
|
|
||||||
|
|
||||||
def run(args, cwd=None):
|
def run(args, cwd=None):
|
||||||
"""Spawn a process to invoke [args] and mute its output."""
|
"""Spawn a process to invoke [args] and mute its output."""
|
||||||
@ -117,8 +126,29 @@ def run(args, cwd=None):
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
download_libuv()
|
expect_usage(len(sys.argv) >= 2)
|
||||||
build_libuv()
|
|
||||||
|
if sys.argv[1] == "download":
|
||||||
|
download_libuv()
|
||||||
|
elif sys.argv[1] == "build":
|
||||||
|
expect_usage(len(sys.argv) <= 3)
|
||||||
|
arch = ""
|
||||||
|
if len(sys.argv) == 3:
|
||||||
|
arch = sys.argv[2]
|
||||||
|
|
||||||
|
out = os.path.join("build", "libuv" + arch + ".a")
|
||||||
|
|
||||||
|
build_libuv(arch, out)
|
||||||
|
else:
|
||||||
|
expect_usage(false)
|
||||||
|
|
||||||
|
|
||||||
|
def expect_usage(condition):
|
||||||
|
if (condition): return
|
||||||
|
|
||||||
|
print("Usage: libuv.py download")
|
||||||
|
print(" libuv.py build [-32|-64]")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|||||||
@ -60,12 +60,14 @@ ifeq ($(ARCH),32)
|
|||||||
C_OPTIONS += -m32
|
C_OPTIONS += -m32
|
||||||
WREN := $(WREN)-32
|
WREN := $(WREN)-32
|
||||||
BUILD_DIR := $(BUILD_DIR)-32
|
BUILD_DIR := $(BUILD_DIR)-32
|
||||||
|
LIBUV_ARCH := -32
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(ARCH),64)
|
ifeq ($(ARCH),64)
|
||||||
C_OPTIONS += -m64
|
C_OPTIONS += -m64
|
||||||
WREN := $(WREN)-64
|
WREN := $(WREN)-64
|
||||||
BUILD_DIR := $(BUILD_DIR)-64
|
BUILD_DIR := $(BUILD_DIR)-64
|
||||||
|
LIBUV_ARCH := -64
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Some platform-specific workarounds. Note that we use "gcc" explicitly in the
|
# Some platform-specific workarounds. Note that we use "gcc" explicitly in the
|
||||||
@ -107,8 +109,8 @@ MODULE_OBJECTS := $(addprefix $(BUILD_DIR)/module/, $(notdir $(MODULE_SOURCES:.c
|
|||||||
VM_OBJECTS := $(addprefix $(BUILD_DIR)/vm/, $(notdir $(VM_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))
|
TEST_OBJECTS := $(patsubst test/api/%.c, $(BUILD_DIR)/test/%.o, $(TEST_SOURCES))
|
||||||
|
|
||||||
LIBUV_DIR := build/libuv
|
LIBUV_DIR := deps/libuv
|
||||||
LIBUV := $(LIBUV_DIR)/out/Release/libuv.a
|
LIBUV := build/libuv$(LIBUV_ARCH).a
|
||||||
|
|
||||||
# Flags needed to compile source files for the CLI, including the modules and
|
# Flags needed to compile source files for the CLI, including the modules and
|
||||||
# API tests.
|
# API tests.
|
||||||
@ -131,51 +133,61 @@ test: $(BUILD_DIR)/test/$(WREN)
|
|||||||
|
|
||||||
# Command-line interpreter.
|
# Command-line interpreter.
|
||||||
bin/$(WREN): $(CLI_OBJECTS) $(MODULE_OBJECTS) $(VM_OBJECTS) $(LIBUV)
|
bin/$(WREN): $(CLI_OBJECTS) $(MODULE_OBJECTS) $(VM_OBJECTS) $(LIBUV)
|
||||||
@printf "%10s %-30s %s\n" $(CC) $@ "$(C_OPTIONS)"
|
@ printf "%10s %-30s %s\n" $(CC) $@ "$(C_OPTIONS)"
|
||||||
@mkdir -p bin
|
@ mkdir -p bin
|
||||||
@$(CC) $(CFLAGS) $^ -o $@ -lm $(LIBUV_LIBS)
|
@ $(CC) $(CFLAGS) $^ -o $@ -lm $(LIBUV_LIBS)
|
||||||
|
|
||||||
# Static library.
|
# Static library.
|
||||||
lib/lib$(WREN).a: $(VM_OBJECTS)
|
lib/lib$(WREN).a: $(VM_OBJECTS)
|
||||||
@printf "%10s %-30s %s\n" $(AR) $@ "rcu"
|
@ printf "%10s %-30s %s\n" $(AR) $@ "rcu"
|
||||||
@mkdir -p lib
|
@ mkdir -p lib
|
||||||
@$(AR) rcu $@ $^
|
@ $(AR) rcu $@ $^
|
||||||
|
|
||||||
# Shared library.
|
# Shared library.
|
||||||
lib/lib$(WREN).$(SHARED_EXT): $(VM_OBJECTS)
|
lib/lib$(WREN).$(SHARED_EXT): $(VM_OBJECTS)
|
||||||
@printf "%10s %-30s %s\n" $(CC) $@ "$(C_OPTIONS) $(SHARED_LIB_FLAGS)"
|
@ printf "%10s %-30s %s\n" $(CC) $@ "$(C_OPTIONS) $(SHARED_LIB_FLAGS)"
|
||||||
@mkdir -p lib
|
@ mkdir -p lib
|
||||||
@$(CC) $(CFLAGS) -shared $(SHARED_LIB_FLAGS) -o $@ $^
|
@ $(CC) $(CFLAGS) -shared $(SHARED_LIB_FLAGS) -o $@ $^
|
||||||
|
|
||||||
# Test executable.
|
# Test executable.
|
||||||
$(BUILD_DIR)/test/$(WREN): $(TEST_OBJECTS) $(MODULE_OBJECTS) $(VM_OBJECTS) \
|
$(BUILD_DIR)/test/$(WREN): $(TEST_OBJECTS) $(MODULE_OBJECTS) $(VM_OBJECTS) \
|
||||||
$(BUILD_DIR)/cli/io.o $(BUILD_DIR)/cli/vm.o $(LIBUV)
|
$(BUILD_DIR)/cli/io.o $(BUILD_DIR)/cli/vm.o $(LIBUV)
|
||||||
@printf "%10s %-30s %s\n" $(CC) $@ "$(C_OPTIONS)"
|
@ printf "%10s %-30s %s\n" $(CC) $@ "$(C_OPTIONS)"
|
||||||
@mkdir -p $(BUILD_DIR)/test
|
@ mkdir -p $(BUILD_DIR)/test
|
||||||
@$(CC) $(CFLAGS) $^ -o $@ -lm $(LIBUV_LIBS)
|
@ $(CC) $(CFLAGS) $^ -o $@ -lm $(LIBUV_LIBS)
|
||||||
|
|
||||||
# CLI object files.
|
# CLI object files.
|
||||||
$(BUILD_DIR)/cli/%.o: src/cli/%.c $(CLI_HEADERS) $(MODULE_HEADERS) $(VM_HEADERS)
|
$(BUILD_DIR)/cli/%.o: src/cli/%.c $(CLI_HEADERS) $(MODULE_HEADERS) \
|
||||||
@printf "%10s %-30s %s\n" $(CC) $< "$(C_OPTIONS)"
|
$(VM_HEADERS) $(LIBUV)
|
||||||
@mkdir -p $(BUILD_DIR)/cli
|
@ printf "%10s %-30s %s\n" $(CC) $< "$(C_OPTIONS)"
|
||||||
@$(CC) -c $(CFLAGS) $(CLI_FLAGS) -o $@ $(FILE_FLAG) $<
|
@ mkdir -p $(BUILD_DIR)/cli
|
||||||
|
@ $(CC) -c $(CFLAGS) $(CLI_FLAGS) -o $@ $(FILE_FLAG) $<
|
||||||
|
|
||||||
# Module object files.
|
# Module object files.
|
||||||
$(BUILD_DIR)/module/%.o: src/module/%.c $(CLI_HEADERS) $(MODULE_HEADERS) $(VM_HEADERS)
|
$(BUILD_DIR)/module/%.o: src/module/%.c $(CLI_HEADERS) $(MODULE_HEADERS) \
|
||||||
@printf "%10s %-30s %s\n" $(CC) $< "$(C_OPTIONS)"
|
$(VM_HEADERS) $(LIBUV)
|
||||||
@mkdir -p $(BUILD_DIR)/module
|
@ printf "%10s %-30s %s\n" $(CC) $< "$(C_OPTIONS)"
|
||||||
@$(CC) -c $(CFLAGS) $(CLI_FLAGS) -o $@ $(FILE_FLAG) $<
|
@ mkdir -p $(BUILD_DIR)/module
|
||||||
|
@ $(CC) -c $(CFLAGS) $(CLI_FLAGS) -o $@ $(FILE_FLAG) $<
|
||||||
|
|
||||||
# VM object files.
|
# VM object files.
|
||||||
$(BUILD_DIR)/vm/%.o: src/vm/%.c $(VM_HEADERS)
|
$(BUILD_DIR)/vm/%.o: src/vm/%.c $(VM_HEADERS)
|
||||||
@printf "%10s %-30s %s\n" $(CC) $< "$(C_OPTIONS)"
|
@ printf "%10s %-30s %s\n" $(CC) $< "$(C_OPTIONS)"
|
||||||
@mkdir -p $(BUILD_DIR)/vm
|
@ mkdir -p $(BUILD_DIR)/vm
|
||||||
@$(CC) -c $(CFLAGS) -Isrc/include -o $@ $(FILE_FLAG) $<
|
@ $(CC) -c $(CFLAGS) -Isrc/include -o $@ $(FILE_FLAG) $<
|
||||||
|
|
||||||
# Test object files.
|
# Test object files.
|
||||||
$(BUILD_DIR)/test/%.o: test/api/%.c $(MODULE_HEADERS) $(VM_HEADERS)
|
$(BUILD_DIR)/test/%.o: test/api/%.c $(MODULE_HEADERS) $(VM_HEADERS) $(LIBUV)
|
||||||
@printf "%10s %-30s %s\n" $(CC) $< "$(C_OPTIONS)"
|
@ printf "%10s %-30s %s\n" $(CC) $< "$(C_OPTIONS)"
|
||||||
@mkdir -p $(dir $@)
|
@ mkdir -p $(dir $@)
|
||||||
@$(CC) -c $(CFLAGS) $(CLI_FLAGS) -o $@ $(FILE_FLAG) $<
|
@ $(CC) -c $(CFLAGS) $(CLI_FLAGS) -o $@ $(FILE_FLAG) $<
|
||||||
|
|
||||||
|
# Download libuv.
|
||||||
|
$(LIBUV_DIR)/build/gyp/gyp: script/libuv.py
|
||||||
|
@ ./script/libuv.py download
|
||||||
|
|
||||||
|
# Build libuv to a static library.
|
||||||
|
$(LIBUV): $(LIBUV_DIR)/build/gyp/gyp script/libuv.py
|
||||||
|
@ ./script/libuv.py build $(LIBUV_ARCH)
|
||||||
|
|
||||||
.PHONY: all cli test vm
|
.PHONY: all cli test vm
|
||||||
|
|||||||
@ -708,4 +708,3 @@ for (i in 0...20) {
|
|||||||
|
|
||||||
IO.print(total)
|
IO.print(total)
|
||||||
IO.print("elapsed: ", IO.clock - start)
|
IO.print("elapsed: ", IO.clock - start)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user