Skip to content

Commit

Permalink
Updated to support the dylib build type for Mac and implement a compa…
Browse files Browse the repository at this point in the history
…tible 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.
  • Loading branch information
hchen99 committed Feb 19, 2025
1 parent 22c3ddd commit 15a61e1
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 30 deletions.
4 changes: 2 additions & 2 deletions bin/trick-ify
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;
Expand Down Expand Up @@ -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 ;
}
Expand Down
49 changes: 24 additions & 25 deletions share/trick/makefiles/trickify.mk
Original file line number Diff line number Diff line change
Expand Up @@ -130,39 +130,38 @@ 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

.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 $@
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit 15a61e1

Please sign in to comment.