Skip to content

Commit

Permalink
Option to create xsnap-worker.a statically linkable library
Browse files Browse the repository at this point in the history
  • Loading branch information
kriskowal committed Oct 7, 2024
1 parent 105bc68 commit 171f0ef
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion xsnap/makefiles/mac/xsnap-worker.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
%.o : %.c

GOAL ?= debug
# Providing LIB=1 CC=clang generates a statically linkable library
# build/lib/mac/$(GOAL)/xsnap-worker.a
# that exports xnsapMain instead of main.
LIB ?=
NAME = xsnap-worker
ifneq ($(VERBOSE),1)
MAKEFLAGS += --silent
Expand All @@ -19,6 +23,7 @@ TLS_DIR = $(CURDIR)/../../sources
XS_DIR = $(MODDABLE)/xs

BIN_DIR = $(BUILD_DIR)/bin/mac/$(GOAL)
LIB_DIR = $(BUILD_DIR)/lib/mac/$(GOAL)
INC_DIR = $(XS_DIR)/includes
PLT_DIR = $(XS_DIR)/platforms
SRC_DIR = $(XS_DIR)/sources
Expand Down Expand Up @@ -64,6 +69,9 @@ endif
ifeq ($(XSNAP_RANDOM_INIT),1)
C_OPTIONS += -DmxSnapshotRandomInit
endif
ifneq ("x$(LIB)","x")
C_OPTIONS += -Dmain=xsnapMain
endif

LIBRARIES = -framework CoreServices

Expand Down Expand Up @@ -133,18 +141,33 @@ VPATH += $(MODDABLE)/modules/data/text/decoder
VPATH += $(MODDABLE)/modules/data/text/encoder
VPATH += $(MODDABLE)/modules/data/base64

build: $(TMP_DIR) $(BIN_DIR) $(BIN_DIR)/$(NAME)
ifneq ("x$(LIB)","x")
build: build-lib
else
build: build-bin
endif

build-bin: $(TMP_DIR) $(BIN_DIR) $(BIN_DIR)/$(NAME)

build-lib: $(TMP_DIR) $(LIB_DIR) $(LIB_DIR)/$(NAME).a

$(TMP_DIR):
mkdir -p $(TMP_DIR)

$(BIN_DIR):
mkdir -p $(BIN_DIR)

$(LIB_DIR):
mkdir -p $(LIB_DIR)

$(BIN_DIR)/$(NAME): $(OBJECTS)
@echo "#" $(NAME) $(GOAL) ": cc" $(@F)
$(CC) $(LINK_OPTIONS) $(OBJECTS) $(LIBRARIES) -o $@

$(LIB_DIR)/$(NAME).a: $(OBJECTS)
@echo "#" $(NAME) $(GOAL) ": ar" $(@F)
$(AR) q $(LIB_DIR)/$(NAME).a $(OBJECTS)

$(OBJECTS): $(TLS_DIR)/xsnap.h
$(OBJECTS): $(TLS_DIR)/xsnapPlatform.h
$(OBJECTS): $(PLT_DIR)/xsPlatform.h
Expand All @@ -161,5 +184,7 @@ $(TMP_DIR)/%.o: %.c
clean:
rm -rf $(BUILD_DIR)/bin/mac/debug/$(NAME)
rm -rf $(BUILD_DIR)/bin/mac/release/$(NAME)
rm -rf $(BUILD_DIR)/lib/mac/debug/$(NAME)
rm -rf $(BUILD_DIR)/lib/mac/release/$(NAME)
rm -rf $(BUILD_DIR)/tmp/mac/debug/$(NAME)
rm -rf $(BUILD_DIR)/tmp/mac/release/$(NAME)

0 comments on commit 171f0ef

Please sign in to comment.