From 2a0311fbf1506d140a04979bebe8b9b5a7ddd73e Mon Sep 17 00:00:00 2001
From: Aaron Pham <contact@aarnphm.xyz>
Date: Mon, 19 Aug 2024 15:41:18 -0400
Subject: [PATCH] chore(build): add options to build from source on linux (#98)

Signed-off-by: Aaron Pham <contact@aarnphm.xyz>
---
 Makefile | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/Makefile b/Makefile
index b7e384d..d69d512 100644
--- a/Makefile
+++ b/Makefile
@@ -13,6 +13,7 @@ endif
 
 LUA_VERSIONS := luajit lua51
 BUILD_DIR := build
+BUILD_FROM_SOURCE := false
 
 all: luajit
 
@@ -30,16 +31,23 @@ define download_release
 	curl -L https://github.com/gptlang/lua-tiktoken/releases/latest/download/tiktoken_core-$1-$2.$(EXT) -o $(BUILD_DIR)/tiktoken_core.$(EXT)
 endef
 
-ifneq ($(filter arm64 aarch64,$(ARCH)),)
+ifeq ($(BUILD_FROM_SOURCE), true)
     $(BUILD_DIR)/tiktoken_core.$(EXT): $(BUILD_DIR)
 	$(call build_from_source,luajit)
     $(BUILD_DIR)/tiktoken_core-lua51.$(EXT): $(BUILD_DIR)
 	$(call build_from_source,lua51)
 else
-    $(BUILD_DIR)/tiktoken_core.$(EXT): $(BUILD_DIR)
-	$(call download_release,$(OS),luajit)
-    $(BUILD_DIR)/tiktoken_core-lua51.$(EXT): $(BUILD_DIR)
-	$(call download_release,$(OS),lua51)
+    ifneq ($(filter arm64 aarch64,$(ARCH)),)
+        $(BUILD_DIR)/tiktoken_core.$(EXT): $(BUILD_DIR)
+		$(call build_from_source,luajit)
+        $(BUILD_DIR)/tiktoken_core-lua51.$(EXT): $(BUILD_DIR)
+		$(call build_from_source,lua51)
+    else
+        $(BUILD_DIR)/tiktoken_core.$(EXT): $(BUILD_DIR)
+		$(call download_release,$(OS),luajit)
+        $(BUILD_DIR)/tiktoken_core-lua51.$(EXT): $(BUILD_DIR)
+		$(call download_release,$(OS),lua51)
+    endif
 endif
 
 $(BUILD_DIR):