Updated to support the dylib build type for Mac and implement a compatible approach for ONESHELL that works with both make 3.81 and 4.2.1.

Updated to support the dylib build type for Mac and implement a compatible approach for ONESHELL that works with both make 3.81 and 4.2.1.
This commit is contained in:
Hong Chen 2025-02-19 14:40:53 -06:00
parent 22c3ddd313
commit 15a61e160a
4 changed files with 36 additions and 30 deletions

View File

@ -46,7 +46,7 @@ GetOptions
$full_build = !$no_source_build ;
$val = $ARGV[$argnum + 1] ;
if( !(($build_type eq "o") or ($build_type eq "a") or ($build_type eq "so")) )
if( !(($build_type eq "o") or ($build_type eq "a") or ($build_type eq "so") or ($build_type eq "dylib")) )
{
print "Invalid build type {$build_type}, valid build types are {o, a, so}\n" ;
exit 1 ;
@ -94,7 +94,7 @@ elsif ( $build_type eq a )
{
$ENV{'TRICKIFY_BUILD_TYPE'} = STATIC ;
}
elsif ( $build_type eq so )
elsif ( $build_type eq so || $build_type eq dylib )
{
$ENV{'TRICKIFY_BUILD_TYPE'} = SHARED ;
}

View File

@ -130,7 +130,8 @@ UNAME := $(shell uname)
ifeq ($(UNAME), Linux)
SHARED_OPTIONS := -fPIC
else ifeq ($(UNAME), Darwin)
SHARED_OPTIONS := -fPIC -lgcov
SHARED_OPTIONS := -fPIC
LD_OPTIONS := -Wl,-install_name,$(abspath $(TRICKIFY_OBJECT_NAME))
else
SHARED_OPTIONS :=
endif
@ -138,31 +139,29 @@ endif
.PHONY: all
all: $(TRICKIFY_OBJECT_NAME) $(TRICKIFY_PYTHON_DIR)
.ONESHELL:
$(TRICKIFY_OBJECT_NAME): $(SWIG_OBJECTS) $(IO_OBJECTS) | $(dir $(TRICKIFY_OBJECT_NAME))
echo TRICKIFICATION STEP A
@while read -r line ; do \
export FILES="$$FILES $$line" ; \
done < $(PY_LINK_LIST)
echo TRICKIFICATION STEP B
@while read -r line ; do \
export FILES="$$FILES $$line" ; \
done < $(IO_LINK_LIST)
echo TRICKIFICATION STEP C
@if [ "$(FULL_TRICKIFY_BUILD)" = "1" ] ; then \
while read -r line ; do \
export FILES="$$FILES $$line" ; \
done < $(OBJ_LINK_LIST) ; \
fi
echo TRICKIFICATION STEP D
@if [ "$(TRICKIFY_BUILD_TYPE)" = "PLO" ] ; then \
$(LD) $(LD_PARTIAL) -o $@ $$FILES ; \
elif [ "$(TRICKIFY_BUILD_TYPE)" = "SHARED" ] ; then \
$(TRICK_CXX) $(SHARED_LIB_OPT) $(SHARED_OPTIONS) -o $@ $$FILES ; \
elif [ "$(TRICKIFY_BUILD_TYPE)" = "STATIC" ] ; then \
ar rcs $@ $ $$FILES ; \
fi
echo TRICKIFICATION STEP E
@echo TRICKIFICATION
@sh -c '\
FILES=""; \
while IFS= read -r line; do \
FILES="$$FILES $$line"; \
done < $(PY_LINK_LIST); \
while IFS= read -r line; do \
FILES="$$FILES $$line"; \
done < $(IO_LINK_LIST); \
if [ "$(FULL_TRICKIFY_BUILD)" = "1" ]; then \
while IFS= read -r line; do \
FILES="$$FILES $$line"; \
done < $(OBJ_LINK_LIST); \
fi; \
if [ "$(TRICKIFY_BUILD_TYPE)" = "PLO" ]; then \
$(LD) $(LD_PARTIAL) -o $@ $$FILES; \
elif [ "$(TRICKIFY_BUILD_TYPE)" = "SHARED" ]; then \
$(TRICK_CXX) $(SHARED_LIB_OPT) $(SHARED_OPTIONS) $(LD_OPTIONS) -o $@ $$FILES; \
elif [ "$(TRICKIFY_BUILD_TYPE)" = "STATIC" ]; then \
ar rcs $@ $$FILES; \
fi; \
'
$(dir $(TRICKIFY_OBJECT_NAME)) $(BUILD_DIR) $(dir $(TRICKIFY_PYTHON_DIR)) .trick:
@mkdir -p $@

View File

@ -4,7 +4,7 @@ include $(LOCAL_DIR)/myproject_vars.mk
all:
@echo MAKE LOCAL_DIR $(LOCAL_DIR)
@$(TRICK_HOME)/bin/trick-ify -d "$(LOCAL_DIR)/../include_bar $(LOCAL_DIR)/../include_foo" -b so -n trickified_myproject -v --source_make_args -fPIC
@$(TRICK_HOME)/bin/trick-ify -d "$(LOCAL_DIR)/../include_bar $(LOCAL_DIR)/../include_foo" -b $(BUILD_TYPE) -n trickified_myproject -v --source_make_args -fPIC
clean:
@rm -rf build python trick $(TRICKIFY_OBJECT_NAME)

View File

@ -11,7 +11,14 @@ MYPROJECT_INCLUDE := -I$(MYPROJECT_HOME)/include_bar -I$(MYPROJECT_HOME)/include
TRICK_CFLAGS += $(MYPROJECT_INCLUDE) $(MYPROJECT_SOURCE)
TRICK_CXXFLAGS += $(MYPROJECT_INCLUDE) $(MYPROJECT_SOURCE)
export TRICKIFY_OBJECT_NAME := trickified_myproject.so
BUILD_TYPE := so
UNAME := $(shell uname)
ifeq ($(UNAME),Darwin)
BUILD_TYPE := dylib
endif
export TRICKIFY_OBJECT_NAME := trickified_myproject.$(BUILD_TYPE)
MYPROJECT_TRICK := $(MYPROJECT_HOME)/trickified/$(TRICKIFY_OBJECT_NAME)
# Tell Trick the headers and source at this location are part of a
@ -25,4 +32,4 @@ TRICK_PYTHON_PATH += :$(MYPROJECT_HOME)/trickified/python
TRICK_SWIG_FLAGS += -I$(MYPROJECT_HOME)/trickified
# Link in the Trickified object
TRICK_LDFLAGS += $(MYPROJECT_TRICK)
TRICK_LDFLAGS += $(MYPROJECT_TRICK) -Wl,-rpath,$(MYPROJECT_HOME)/trickified