-
Notifications
You must be signed in to change notification settings - Fork 162
/
Makefile.osx-helper
76 lines (62 loc) · 2.53 KB
/
Makefile.osx-helper
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
dontcopy = /System/Library/% /usr/lib/% /usr/X11/lib/% /usr/X11R6/lib/% @executable_path/%
getdylibs = $(filter-out $(dontcopy),$(shell $(OTOOL) -L $(1) | grep version | cut -f 1 -d ' '))
dest = $(macosx_bundle_path)/MacOS/$(notdir $(1))
# Let's create a list of all libraries used at runtime, starting with the
# application.
FILES :=
NEWFILES := $(USDX_BIN)
define processload
D := $(1)
ifeq ($$(patsubst @rpath%,,$$(D)),)
D := $$(firstword $$(foreach rpath,$$(RUNPATH),$$(wildcard $$(patsubst @rpath%,$$(rpath)%,$$(D))) ))
ifeq ($$(D),)
$$(error dylib $(1) not found in rpath $$(RUNPATH))
endif
else
ifeq ($$(patsubst @loader_path/%,,$$(D)),)
D := $$(patsubst @loader_path/%,$(2)%,$$(D))
endif
endif
$$(eval RUNPATH_$$(D) := $$$$(RUNPATH))
NEXTNEWFILES := $(NEXTNEWFILES) $$(filter-out $(FILES) $(NEXTNEWFILES),$$(D))
endef
define runpathlist
RUNPATH := $$(RUNPATH_$(1)) $$(patsubst @loader_path/%,$$(dir $(1))%,$$(filter-out $$(RUNPATH_$(1)),$$(shell $$(OTOOL) -l $(1) | grep -A 2 '\<cmd LC_RPATH\>' | sed -n 's/.* path \(.*\) .offset .*/\1/p')))
$$(foreach dylib,$$(call getdylibs,$(1)),$$(eval $$(call processload,$$(dylib),$$(dir $(1)))))
endef
define recurse
FILES := $$(FILES) $$(NEWFILES)
NEXTNEWFILES :=
$$(foreach dylib,$$(NEWFILES),$$(eval $$(call runpathlist,$$(dylib))))
NEWFILES := $$(strip $$(NEXTNEWFILES))
ifneq ($$(NEWFILES),)
$$(eval $$(recurse))
endif
endef
$(eval $(recurse))
# Libavutil is referenced as /usr/local/opt/[email protected]/lib/libavutil.54.dylib by
# ultrastardx and as /usr/local/Cellar/[email protected]/2.8.11/lib/libavutil.54.dylib
# by libavcodec. We don't want make to call the installdylib rule for both in
# parallel. Handle this by creating a variable libavutil.54.dylib that is
# assigned the full path. The last one wins.
define removedupes
$(1) := $(2)
endef
$(foreach dylib,$(FILES),$(eval $(call removedupes,$(notdir $(dylib)),$(dylib))))
FILES := $(sort $(foreach dylib,$(FILES),$($(notdir $(dylib)))))
# The first rule in this file and thus the default target:
all: $(foreach dylib,$(FILES),$(call dest,$(dylib)))
define changeimport
@echo change the install name for $(2)
@$(INSTALL_NAME_TOOL) -change $(2) @executable_path/$(notdir $(2)) $(1)
endef
define installdylib
$(call dest,$(1)): $(1)
@echo work on $(1)
@$(INSTALL) -m 755 $(1) $(call dest,$(1))
ifneq ($(1),$(USDX_BIN))
@$(INSTALL_NAME_TOOL) -id @executable_path/$(notdir $(1)) $(call dest,$(1))
endif
$$(foreach dylib,$$(call getdylibs,$(1)),$$(call changeimport,$(call dest,$(1)),$$(dylib)))
endef
$(foreach dylib,$(FILES),$(eval $(call installdylib,$(dylib))))