BUILD     = build
INSTALL_BIN = /opt/homebrew/bin
INSTALL_LIB = /opt/homebrew/lib
INSTALL_INC = /opt/homebrew/include
CELL_SHOP   = $(HOME)/.cell

all: $(BUILD)/build.ninja
	meson compile -C $(BUILD)
	cp $(BUILD)/libcell_runtime.dylib .
	cp $(BUILD)/cell .

$(BUILD)/build.ninja:
	meson setup $(BUILD) -Dbuildtype=debugoptimized

install: all $(CELL_SHOP)
	cp cell $(INSTALL_BIN)/cell
	cp libcell_runtime.dylib $(INSTALL_LIB)/
	cp source/cell.h source/quickjs.h source/wota.h $(INSTALL_INC)/
	rm -rf $(CELL_SHOP)/packages/core
	ln -s $(CURDIR) $(CELL_SHOP)/packages/core
	@echo "Installed cell to $(INSTALL_BIN) and $(INSTALL_LIB)"

$(CELL_SHOP):
	mkdir -p $(CELL_SHOP)/packages $(CELL_SHOP)/cache $(CELL_SHOP)/build

clean:
	rm -rf $(BUILD)
	rm -f cell libcell_runtime.dylib

.PHONY: all install clean
