From 1afca4888b2ee8e49c2e4d0bef478d0728d5ed41 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Thu, 13 Aug 2020 11:21:22 +0800 Subject: add make target to build .so file. --- README.md | 14 +++++++++++--- makefile | 24 ++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ab2f857..4275320 100644 --- a/README.md +++ b/README.md @@ -26,13 +26,21 @@ So MoonPlus is a new code base for pushing the language to go forward and being * **Lua Module** - Install [luarocks](https://luarocks.org), a package manager for Lua modules. Then install it as a Lua module. +  Build `moonp.so` file with + +```sh +> make shared LUAI=/usr/local/include/lua LUAL=/usr/local/lib/lua +``` + +  Then get the binary file from path `bin/shared/moonp.so`. + +  Or you can install [luarocks](https://luarocks.org), a package manager for Lua modules. Then install it as a Lua module with ```sh > luarocks install moonplus ``` -  Require the module in Lua: +  Then require the module in Lua: ```Lua require("moonp")("main") -- require `main.moon` @@ -54,7 +62,7 @@ f! * **Binary Tool** - Clone this repo, then build and install executable with: +  Clone this repo, then build and install executable with: ```sh > make install diff --git a/makefile b/makefile index 0c29230..70d6c97 100644 --- a/makefile +++ b/makefile @@ -79,12 +79,15 @@ release: export CXXFLAGS := $(CXXFLAGS) $(COMPILE_FLAGS) $(RCOMPILE_FLAGS) release: export LDFLAGS := $(LDFLAGS) $(LINK_FLAGS) $(RLINK_FLAGS) debug: export CXXFLAGS := $(CXXFLAGS) $(COMPILE_FLAGS) $(DCOMPILE_FLAGS) debug: export LDFLAGS := $(LDFLAGS) $(LINK_FLAGS) $(DLINK_FLAGS) +shared: export CXXFLAGS := $(CXXFLAGS) $(COMPILE_FLAGS) $(RCOMPILE_FLAGS) # Build and output paths release: export BUILD_PATH := build/release release: export BIN_PATH := bin/release debug: export BUILD_PATH := build/debug debug: export BIN_PATH := bin/debug +shared: export BUILD_PATH := build/shared +shared: export BIN_PATH := bin/shared install: export BIN_PATH := bin/release # Find all source files in the source directory, sorted by most @@ -154,7 +157,7 @@ endif .PHONY: release release: dirs ifeq ($(USE_VERSION), true) - @echo "Beginning release build v$(VERSION_STRING)" + @echo "Beginning release build $(VERSION_STRING)" else @echo "Beginning release build" endif @@ -168,7 +171,7 @@ endif .PHONY: debug debug: dirs ifeq ($(USE_VERSION), true) - @echo "Beginning debug build v$(VERSION_STRING)" + @echo "Beginning debug build $(VERSION_STRING)" else @echo "Beginning debug build" endif @@ -178,6 +181,23 @@ endif @echo -n "Total build time: " @$(END_TIME) +$(BUILD_PATH)/moonp.so: src/MoonP/ast.cpp src/MoonP/moon_compiler.cpp src/MoonP/moon_parser.cpp src/MoonP/moonplus.cpp src/MoonP/parser.cpp + $(CMD_PREFIX)$(CXX) $(CXXFLAGS) -I $(SRC_PATH) -I $(LUAI) -L $(LUAL) -llua -o $@ -fPIC -shared $? + +# Standard, non-optimized release build +.PHONY: shared +shared: dirs +ifeq ($(USE_VERSION), true) + @echo "Beginning release build $(VERSION_STRING)" +else + @echo "Beginning release build" +endif + @$(START_TIME) + @$(MAKE) $(BUILD_PATH)/moonp.so --no-print-directory + @echo -n "Total build time: " + @$(END_TIME) + @mv $(BUILD_PATH)/moonp.so $(BIN_PATH)/moonp.so + # Create the directories used in the build .PHONY: dirs dirs: -- cgit v1.2.3-55-g6feb