Skip to content

Commit 03d1b27

Browse files
committed
add rules for building dmg
1 parent 1aa13e8 commit 03d1b27

File tree

4 files changed

+140
-41
lines changed

4 files changed

+140
-41
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ compile_commands.json
1212
/test/share
1313
default.profraw
1414
/test/include
15+
/pkg
16+
/fakeroot

Makefile

+43-41
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,12 @@
1-
LIBVER ?=$(shell vtool -show-build $(shell brew --prefix)/lib/libgetargv.dylib | awk '/minos/{print $$2}')
2-
export MACOSX_DEPLOYMENT_TARGET=$(LIBVER)
3-
VERSION=0.1
4-
COMPAT_VERSION := $(shell echo $(VERSION) | cut -f1 -d.).0
5-
6-
CODESIGN_PREFIX := cam.narzt.
7-
KEYCHAIN := ~/Library/Keychains/login.keychain-db
8-
CERT_IDENTITY := $(shell security find-identity -v -p codesigning | sed -Ee 's/.*"([^"]+)".*/\1/g' | grep -Fve ' valid identit' -e ' CA')
9-
10-
SRC_DIR = src
11-
OBJ_DIR = obj
12-
LIB_DIR = lib
13-
14-
PREFIX := /usr/local
15-
CXX=clang++
16-
CPPFLAGS += -MMD -MP
17-
18-
COMPILER_VERSION := $(shell $(CXX) --version | grep version | grep -o -m 1 "[0-9]\+\.[0-9]\+\.*[0-9]*" | head -n 1)
19-
COMPILER_VERSION_NUMBER := $(shell echo $(COMPILER_VERSION) | sed -e 's/\.\([0-9][0-9]\)/\1/g' -e 's/\.\([0-9]\)/0\1/g' -e 's/^[0-9]\{3,4\}$$/&00/')
20-
CLANG_13_OR_MORE := $(shell expr $(COMPILER_VERSION_NUMBER) \>= 130106)
21-
ifneq ($(CLANG_13_OR_MORE),0)
22-
# supported: c++11, c++14, c++17, c++20
23-
# future: c++2b
24-
CXXFLAGS := --std=c++20 -O3 -Iinclude
25-
else
26-
CXXFLAGS := --std=c++17 -O3 -Iinclude
27-
endif
28-
29-
EXTRA_CXXFLAGS := -pedantic-errors -Weverything -Wno-c++98-compat -Wno-pre-c++20-compat-pedantic -Wno-poison-system-directories
30-
LDFLAGS += -Llib -fvisibility=default -fPIC
31-
LDLIBS += -lgetargv
32-
33-
LIB_SHORT_NAME = getargv++
34-
DYLIB_FILENAME = lib$(LIB_SHORT_NAME).$(VERSION).dylib
35-
DYLIB = lib/$(DYLIB_FILENAME)
36-
SOURCES = $(wildcard $(SRC_DIR)/*.cpp)
37-
OBJECTS = $(SOURCES:$(SRC_DIR)/%.cpp=$(OBJ_DIR)/%.o)
1+
include Makefile-variables
382

39-
.PHONY := db clean dylib install_dylib lint
3+
.PHONY := db clean dylib install install_dylib lint dmg
404
.DEFAULT_GOAL := dylib
415

426
dylib: $(DYLIB)
437

8+
install: install_dylib
9+
4410
install_dylib: $(DYLIB)
4511
install -d $(PREFIX)/$(LIB_DIR)
4612
install $(DYLIB) $(PREFIX)/$(DYLIB)
@@ -62,10 +28,10 @@ $(DYLIB): $(OBJECTS) | $(LIB_DIR)
6228
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp | $(OBJ_DIR)
6329
$(CXX) $(EXTRA_CXXFLAGS) $(CXXFLAGS) $(CPPFLAGS) -c -fPIC $< -o $@
6430

65-
$(OBJ_DIR) $(LIB_DIR):
31+
$(OBJ_DIR) $(LIB_DIR) $(FAKE_ROOT) $(PKG_DIR):
6632
mkdir -p $@
6733

68-
docs:
34+
docs: doxygen.conf $(SOURCES) $(HEADERS)
6935
doxygen -q doxygen.conf
7036

7137
db: compile_commands.json
@@ -74,10 +40,46 @@ compile_commands.json: Makefile
7440
$(shell brew --prefix bear)/bin/bear -- make -B $(OBJECTS)
7541

7642
clean:
77-
@$(RM) -rf $(OBJ_DIR) $(LIB_DIR) docs
43+
@$(RM) -rf $(OBJ_DIR) $(LIB_DIR) docs $(FAKE_ROOT) $(PKG_DIR)
7844

7945
lint: compile_commands.json
8046
for file in $(SOURCES); do /usr/bin/xcrun -r clangd --enable-config --clang-tidy --log=error --check=$$file; done
8147
$(shell brew --prefix llvm)/bin/scan-build -enable-checker security -enable-checker unix -enable-checker valist $(MAKE) -B dylib
8248

49+
dmg: $(DMG)
50+
51+
$(DMG): $(PRODUCT)
52+
hdiutil create -fs "$(DMG_FS)" -volname "$(DMG_VOLUME_NAME)" -srcfolder "$(PKG_DIR)" -ov -format "$(DMG_FORMAT)" "$@"
53+
54+
$(DISTRIBUTION): $(SRC_DIR)/dist.xml
55+
< $< > $@ sed \
56+
-e 's/OS_VERSION/$(MACOS_VER_NUM)/g' \
57+
-e 's/ARCH/$(ARCH)/g' \
58+
-e 's/VERSION/$(VERSION)/g' \
59+
-e 's/LIB_PKG_NAME/$(LIB_PKG:$(PKG_DIR)/%=%)/g' \
60+
-e 's/LIB_ID/$(LIB_BUNDLE_IDENTIFIER)/g' \
61+
-e 's/LIB_NAME/$(LIB_NAME)/g'
62+
63+
$(PRODUCT): $(LIB_PKG) $(DISTRIBUTION)
64+
productbuild \
65+
--identifier $(PRODUCT_BUNDLE_IDENTIFIER) \
66+
--version $(VERSION) \
67+
--package-path $(PKG_DIR) \
68+
--resources ./ \
69+
--distribution $(DISTRIBUTION) \
70+
$(SIGN_PACKAGE_FLAG) \
71+
$@
72+
@$(RM) $^
73+
74+
$(LIB_PKG): $(FAKE_ROOT) | $(PKG_DIR)
75+
@$(RM) -rf $(FAKE_ROOT)/*
76+
$(MAKE) PREFIX=$(FAKE_ROOT) install_dylib
77+
pkgbuild --root $(FAKE_ROOT) \
78+
--identifier "$(LIB_BUNDLE_IDENTIFIER)" \
79+
--version "$(VERSION)" \
80+
$(PKG_VERSION_FLAG) \
81+
--install-location "$(PREFIX)" \
82+
$(SIGN_PACKAGE_FLAG) \
83+
$@
84+
8385
-include $(OBJECTS:.o=.d)

Makefile-variables

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
MACOS_VER_NUM ?=$(shell vtool -show-build $(shell brew --prefix)/lib/libgetargv.dylib | awk '/minos/{print $$2}')
2+
MACOS_VER_MAJOR := $(shell echo $(MACOS_VER_NUM) | cut -f1 -d.)
3+
MACOS_VER_MINOR := $(shell echo $(MACOS_VER_NUM) | cut -f2 -d.)
4+
MACOS_LT_10_11 := $(shell [ $(MACOS_VER_MAJOR) -eq 10 -a $(MACOS_VER_MINOR) -lt 11 ] && echo true)
5+
MACOS_LT_10_13 := $(shell [ $(MACOS_VER_MAJOR) -eq 10 -a $(MACOS_VER_MINOR) -lt 13 ] && echo true)
6+
MACOS_LT_11 := $(shell [ $(MACOS_VER_MAJOR) -eq 10 -a $(MACOS_VER_MINOR) -lt 15 ] || [ $(MACOS_VER_MAJOR) -lt 11 ] && echo true)
7+
export MACOSX_DEPLOYMENT_TARGET := $(MACOS_VER_MAJOR).$(MACOS_VER_MINOR)
8+
VERSION=0.1
9+
COMPAT_VERSION := $(shell echo $(VERSION) | cut -f1 -d.).0
10+
ARCH := $(shell uname -m)
11+
CODESIGN_PREFIX := cam.narzt.
12+
KEYCHAIN := ~/Library/Keychains/login.keychain-db
13+
CERT_IDENTITY := $(shell security find-identity -v -p codesigning | sed -Ee 's/.*"([^"]+)".*/\1/g' | grep -Fve ' valid identit' -e ' CA')
14+
15+
SRC_DIR = src
16+
INCLUDE_DIR = include
17+
OBJ_DIR = obj
18+
LIB_DIR = lib
19+
PKG_DIR = pkg
20+
FAKE_ROOT = fakeroot
21+
PREFIX ?= /usr/local
22+
CXX = clang++
23+
CPPFLAGS += -MMD -MP
24+
25+
COMPILER_VERSION := $(shell $(CXX) --version | grep version | grep -o -m 1 "[0-9]\+\.[0-9]\+\.*[0-9]*" | head -n 1)
26+
COMPILER_VERSION_NUMBER := $(shell echo $(COMPILER_VERSION) | sed -e 's/\.\([0-9][0-9]\)/\1/g' -e 's/\.\([0-9]\)/0\1/g' -e 's/^[0-9]\{3,4\}$$/&00/')
27+
CLANG_13_OR_MORE := $(shell expr $(COMPILER_VERSION_NUMBER) \>= 130106)
28+
ifneq ($(CLANG_13_OR_MORE),0)
29+
# supported: c++11, c++14, c++17, c++20
30+
# future: c++2b
31+
CXXFLAGS := --std=c++20 -O3 -Iinclude
32+
else
33+
CXXFLAGS := --std=c++17 -O3 -Iinclude
34+
endif
35+
36+
EXTRA_CXXFLAGS := -pedantic-errors -Weverything -Wno-c++98-compat -Wno-pre-c++20-compat-pedantic -Wno-poison-system-directories
37+
LDFLAGS += -Llib -fvisibility=default -fPIC
38+
LDLIBS += -lgetargv
39+
40+
LIB_SHORT_NAME = getargv++
41+
LIB_NAME = lib$(LIB_SHORT_NAME)
42+
DYLIB_FILENAME = $(LIB_NAME).$(VERSION).dylib
43+
DYLIB = lib/$(DYLIB_FILENAME)
44+
SOURCES = $(wildcard $(SRC_DIR)/*.cpp)
45+
HEADERS = $(wildcard $(INCLUDE_DIR)/*.hpp)
46+
OBJECTS = $(SOURCES:$(SRC_DIR)/%.cpp=$(OBJ_DIR)/%.o)
47+
48+
DMG_VOLUME_NAME := $(LIB_NAME) Installer
49+
DMG := $(PKG_DIR)/$(LIB_NAME).dmg
50+
PRODUCT_BUNDLE_PACKAGE_TYPE := APPL
51+
LIB_BUNDLE_IDENTIFIER := $(CODESIGN_PREFIX)$(LIB_NAME)
52+
PRODUCT_BUNDLE_IDENTIFIER := $(LIB_BUNDLE_IDENTIFIER)
53+
PRODUCT := $(PKG_DIR)/$(LIB_NAME)-$(VERSION)-macOS-$(MACOS_VER_NUM)-$(ARCH).pkg
54+
LIB_PKG := $(PKG_DIR)/$(LIB_NAME)-$(VERSION)-macOS-$(MACOS_VER_NUM)-$(ARCH)-package.pkg
55+
DISTRIBUTION := $(OBJ_DIR)/dist.xml
56+
57+
ifeq ($(MACOS_LT_10_11),true)
58+
DMG_FORMAT := UDZO
59+
else ifeq ($(MACOS_LT_11),true)
60+
DMG_FORMAT := ULFO
61+
else
62+
DMG_FORMAT := ULMO
63+
endif
64+
65+
ifeq ($(MACOS_LT_10_13),true)
66+
DMG_FS := HFS+
67+
else
68+
DMG_FS := APFS
69+
endif
70+
71+
ifeq ($(MACOS_LT_12),true)
72+
PKG_VERSION_FLAG :=
73+
else
74+
PKG_VERSION_FLAG := --min-os-version $(MACOSX_DEPLOYMENT_TARGET)
75+
endif

src/dist.xml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<installer-gui-script minSpecVersion="2">
3+
<volume-check>
4+
<allowed-os-versions>
5+
<os-version min="OS_VERSION" />
6+
</allowed-os-versions>
7+
</volume-check>
8+
9+
<license file="LICENSE" mime-type="text/plain" />
10+
11+
<options customize="allow" require-scripts="false" hostArchitectures="ARCH" />
12+
13+
<choices-outline>
14+
<line choice="LIB_ID" />
15+
</choices-outline>
16+
<choice title="LIB_NAME library" id="LIB_ID" customLocation="/usr/local" customLocationAllowAlternateVolumes="true">
17+
<pkg-ref id="LIB_ID" />
18+
</choice>
19+
<pkg-ref id="LIB_ID" version="VERSION" onConclusion="none">LIB_PKG_NAME</pkg-ref>
20+
</installer-gui-script>

0 commit comments

Comments
 (0)