Skip to content
This repository was archived by the owner on Mar 12, 2022. It is now read-only.

Commit 25aecf2

Browse files
committed
commit Universal builds
1 parent 60798b3 commit 25aecf2

7 files changed

+176
-124
lines changed

Diff for: Makefile

+97-46
Original file line numberDiff line numberDiff line change
@@ -13,65 +13,121 @@ HS_APPLICATION ?= /Applications
1313
# (usually ~/.hammerspoon)
1414
MARKDOWNMAKER = utils/docmaker.lua
1515

16-
OBJCFILE = ${wildcard *.m}
17-
LUAFILE = ${wildcard *.lua}
18-
HEADERS = ${wildcard *.h}
19-
20-
# swap if all objective-c files should be compiled into one target -- this is necessary if you organize your code in
21-
# multiple files but need them to access functions/objects defined in different files -- each dynamic library is loaded
22-
# individually by Hammerspoon so they can't see the exports of each other directly.
23-
SOFILE := $(OBJCFILE:.m=.so)
24-
# SOFILE := internal.so
16+
OBJCFILES = ${wildcard *.m}
17+
LUAFILES = ${wildcard *.lua}
18+
HEADERS = ${wildcard *.h}
19+
20+
# for compiling each source file into a separate library
21+
# (see also obj_x86_64/%.s and obj_arm64/%.s below)
22+
SOFILES := $(OBJCFILES:.m=.so)
23+
24+
# for compiling all source files into one library
25+
# (see also obj_x86_64/%.s and obj_arm64/%.s below)
26+
# SOFILES := internal.so
27+
28+
SOFILES_x86_64 := $(addprefix obj_x86_64/,$(SOFILES))
29+
SOFILES_arm64 := $(addprefix obj_arm64/,$(SOFILES))
30+
SOFILES_univeral := $(addprefix obj_universal/,$(SOFILES))
31+
2532
DEBUG_CFLAGS ?= -g
2633

2734
# special vars for uninstall
2835
space :=
2936
space +=
3037
comma := ,
31-
ALLFILES := $(LUAFILE)
32-
ALLFILES += $(SOFILE)
33-
34-
.SUFFIXES: .m .so
38+
ALLFILES := $(LUAFILES)
39+
ALLFILES += $(SOFILES)
3540

36-
#CC=cc
41+
# CC=clang
3742
CC=@clang
38-
WARNINGS ?= -Weverything -Wno-objc-missing-property-synthesis -Wno-implicit-atomic-properties -Wno-direct-ivar-access -Wno-cstring-format-directive -Wno-padded -Wno-covered-switch-default -Wno-missing-prototypes -Werror-implicit-function-declaration -Wno-documentation-unknown-command
39-
EXTRA_CFLAGS ?= -F$(HS_APPLICATION)/Hammerspoon.app/Contents/Frameworks -mmacosx-version-min=10.12
43+
WARNINGS ?= -Weverything -Wno-objc-missing-property-synthesis -Wno-implicit-atomic-properties -Wno-direct-ivar-access -Wno-cstring-format-directive -Wno-padded -Wno-covered-switch-default -Wno-missing-prototypes -Werror-implicit-function-declaration -Wno-documentation-unknown-command -Wno-poison-system-directories
44+
EXTRA_CFLAGS ?= -F$(HS_APPLICATION)/Hammerspoon.app/Contents/Frameworks -mmacosx-version-min=10.13
4045

4146
CFLAGS += $(DEBUG_CFLAGS) -fmodules -fobjc-arc -DHS_EXTERNAL_MODULE $(WARNINGS) $(EXTRA_CFLAGS)
4247
LDFLAGS += -dynamiclib -undefined dynamic_lookup $(EXTRA_LDFLAGS)
4348

44-
all: verify $(SOFILE)
49+
all: verify $(shell uname -m)
4550

46-
release: clean all
47-
HS_APPLICATION=$(HS_APPLICATION) PREFIX=tmp make install ; cd tmp ; tar -cf ../$(MODULE)-v$(VERSION).tar hs ; cd .. ; gzip $(MODULE)-v$(VERSION).tar
51+
x86_64: $(SOFILES_x86_64)
4852

49-
releaseWithDocs: clean all docs
50-
HS_APPLICATION=$(HS_APPLICATION) PREFIX=tmp make install ; cd tmp ; tar -cf ../$(MODULE)-v$(VERSION).tar hs ; cd .. ; gzip $(MODULE)-v$(VERSION).tar
53+
arm64: $(SOFILES_arm64)
54+
55+
universal: verify x86_64 arm64 $(SOFILES_univeral)
56+
57+
# for compiling each source file into a separate library
58+
# (see also SOFILES above)
59+
60+
obj_x86_64/%.so: %.m $(HEADERS)
61+
$(CC) $< $(CFLAGS) $(LDFLAGS) -target x86_64-apple-macos10.13 -o $@
62+
63+
obj_arm64/%.so: %.m $(HEADERS)
64+
$(CC) $< $(CFLAGS) $(LDFLAGS) -target arm64-apple-macos11 -o $@
65+
66+
# for compiling all source files into one library
67+
# (see also SOFILES above)
68+
69+
# obj_x86_64/%.so: $(OBJCFILES) $(HEADERS)
70+
# $(CC) $(OBJCFILES) $(CFLAGS) $(LDFLAGS) -target x86_64-apple-macos10.13 -o $@
71+
#
72+
# obj_arm64/%.so: $(OBJCFILES) $(HEADERS)
73+
# $(CC) $(OBJCFILES) $(CFLAGS) $(LDFLAGS) -target arm64-apple-macos11 -o $@
74+
75+
# creating the universal dSYM bundle is a total hack because I haven't found a better
76+
# way yet... suggestions welcome
77+
obj_universal/%.so: $(SOFILES_x86_64) $(SOFILES_arm64)
78+
lipo -create -output $@ $(subst universal/,x86_64/,$@) $(subst universal/,arm64/,$@)
79+
mkdir -p $@.dSYM/Contents/Resources/DWARF/
80+
cp $(subst universal/,x86_64/,$@).dSYM/Contents/Info.plist $@.dSYM/Contents
81+
lipo -create -output $@.dSYM/Contents/Resources/DWARF/$(subst obj_universal/,,$@) $(subst universal/,x86_64/,$@).dSYM/Contents/Resources/DWARF/$(subst obj_universal/,,$@) $(subst universal/,arm64/,$@).dSYM/Contents/Resources/DWARF/$(subst obj_universal/,,$@)
82+
83+
$(SOFILES_x86_64): | obj_x86_64
84+
85+
$(SOFILES_arm64): | obj_arm64
86+
87+
$(SOFILES_univeral): | obj_universal
88+
89+
obj_x86_64:
90+
mkdir obj_x86_64
5191

52-
# swap if all objective-c files should be compiled into one target
53-
.m.so: $(HEADERS) $(OBJCFILE)
54-
$(CC) $< $(CFLAGS) $(LDFLAGS) -o $@
92+
obj_arm64:
93+
mkdir obj_arm64
5594

56-
# internal.so: $(HEADERS) $(OBJCFILE)
57-
# $(CC) $(OBJCFILE) $(CFLAGS) $(LDFLAGS) -o $@
95+
obj_universal:
96+
mkdir obj_universal
5897

59-
install: verify install-objc install-lua
98+
verify: $(LUAFILES)
99+
@if $$(hash lua >& /dev/null); then (luac -p $(LUAFILES) && echo "Lua Compile Verification Passed"); else echo "Skipping Lua Compile Verification"; fi
100+
101+
install: install-$(shell uname -m)
102+
103+
install-lua: $(LUAFILES)
104+
mkdir -p $(PREFIX)/$(MODPATH)/$(MODULE)
105+
install -m 0644 $(LUAFILES) $(PREFIX)/$(MODPATH)/$(MODULE)
60106
test -f docs.json && install -m 0644 docs.json $(PREFIX)/$(MODPATH)/$(MODULE) || echo "No docs.json file to install"
61107

62-
verify: $(LUAFILE)
63-
@if $$(hash lua >& /dev/null); then (luac -p $(LUAFILE) && echo "Lua Compile Verification Passed"); else echo "Skipping Lua Compile Verification"; fi
108+
install-x86_64: verify install-lua $(SOFILES_x86_64)
109+
mkdir -p $(PREFIX)/$(MODPATH)/$(MODULE)
110+
install -m 0644 $(SOFILES_x86_64) $(PREFIX)/$(MODPATH)/$(MODULE)
111+
cp -vpR $(SOFILES_x86_64:.so=.so.dSYM) $(PREFIX)/$(MODPATH)/$(MODULE)
64112

65-
install-objc: $(SOFILE)
113+
install-arm64: verify install-lua $(SOFILES_arm64)
66114
mkdir -p $(PREFIX)/$(MODPATH)/$(MODULE)
67-
install -m 0644 $(SOFILE) $(PREFIX)/$(MODPATH)/$(MODULE)
68-
# swap if all objective-c files should be compiled into one target
69-
cp -vpR $(OBJCFILE:.m=.so.dSYM) $(PREFIX)/$(MODPATH)/$(MODULE)
70-
# cp -vpR $(SOFILE:.so=.so.dSYM) $(PREFIX)/$(MODPATH)/$(MODULE)
115+
install -m 0644 $(SOFILES_arm64) $(PREFIX)/$(MODPATH)/$(MODULE)
116+
cp -vpR $(SOFILES_arm64:.so=.so.dSYM) $(PREFIX)/$(MODPATH)/$(MODULE)
71117

72-
install-lua: $(LUAFILE)
118+
install-universal: verify install-lua $(SOFILES_univeral)
73119
mkdir -p $(PREFIX)/$(MODPATH)/$(MODULE)
74-
install -m 0644 $(LUAFILE) $(PREFIX)/$(MODPATH)/$(MODULE)
120+
install -m 0644 $(SOFILES_univeral) $(PREFIX)/$(MODPATH)/$(MODULE)
121+
cp -vpR $(SOFILES_univeral:.so=.so.dSYM) $(PREFIX)/$(MODPATH)/$(MODULE)
122+
123+
uninstall:
124+
rm -v -f $(PREFIX)/$(MODPATH)/$(MODULE)/{$(subst $(space),$(comma),$(ALLFILES))}
125+
(pushd $(PREFIX)/$(MODPATH)/$(MODULE)/ ; rm -v -fr $(SOFILES:.so=.so.dSYM) ; popd)
126+
rm -v -f $(PREFIX)/$(MODPATH)/$(MODULE)/docs.json
127+
rmdir -p $(PREFIX)/$(MODPATH)/$(MODULE) ; exit 0
128+
129+
clean:
130+
rm -rf obj_x86_64 obj_arm64 obj_universal tmp docs.json
75131

76132
docs:
77133
hs -c "require(\"hs.doc\").builder.genJSON(\"$(dir $(mkfile_path))\")" > docs.json
@@ -82,15 +138,10 @@ markdown:
82138
markdownWithTOC:
83139
hs -c "dofile(\"$(MARKDOWNMAKER)\").genMarkdown([[$(dir $(mkfile_path))]], true)" > README.tmp.md
84140

85-
clean:
86-
rm -rf $(SOFILE) *.dSYM tmp docs.json
141+
release: clean all
142+
HS_APPLICATION=$(HS_APPLICATION) PREFIX=tmp make install-universal ; cd tmp ; tar -cf ../$(MODULE)-v$(VERSION).tar hs ; cd .. ; gzip $(MODULE)-v$(VERSION).tar
87143

88-
uninstall:
89-
rm -v -f $(PREFIX)/$(MODPATH)/$(MODULE)/{$(subst $(space),$(comma),$(ALLFILES))}
90-
# swap if all objective-c files should be compiled into one target
91-
(pushd $(PREFIX)/$(MODPATH)/$(MODULE)/ ; rm -v -fr $(OBJCFILE:.m=.so.dSYM) ; popd)
92-
# (pushd $(PREFIX)/$(MODPATH)/$(MODULE)/ ; rm -v -fr $(SOFILE:.so=.so.dSYM) ; popd)
93-
rm -v -f $(PREFIX)/$(MODPATH)/$(MODULE)/docs.json
94-
rmdir -p $(PREFIX)/$(MODPATH)/$(MODULE) ; exit 0
144+
releaseWithDocs: clean all docs
145+
HS_APPLICATION=$(HS_APPLICATION) PREFIX=tmp make install-universal ; cd tmp ; tar -cf ../$(MODULE)-v$(VERSION).tar hs ; cd .. ; gzip $(MODULE)-v$(VERSION).tar
95146

96-
.PHONY: all clean uninstall verify install install-objc install-lua docs markdown markdownWithTOC
147+
.PHONY: all clean verify install install-lua install-x86_64 install-arm64 install-universal docs markdown markdownWithTOC release releaseWithDocs

Diff for: README.md

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ I make no promises that these will work for you or work at all with any, past, c
99

1010
### Installation
1111

12+
*See https://github.com/asmagill/hammerspoon_asm/blob/master/README.md for details about building this module as a Universal library*
13+
1214
Compiled versions of this module can be found in the releases. You can download the release and install it by expanding it in your `~/.hammerspoon/` directory (or any other directory in your `package.path` and `package.cpath` search paths):
1315

1416
~~~sh

0 commit comments

Comments
 (0)