summaryrefslogtreecommitdiffstats
path: root/packaging/macos/220-inkscape_package.sh
blob: 02400dceced412c68872aa52d761556184799302 (plain)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/usr/bin/env bash
#
# SPDX-FileCopyrightText: 2021 René de Hesselle <dehesselle@web.de>
#
# SPDX-License-Identifier: GPL-2.0-or-later

### description ################################################################

# Create the application bundle and make everything relocatable.

### shellcheck #################################################################

# Nothing here.

### dependencies ###############################################################

source "$(dirname "${BASH_SOURCE[0]}")"/jhb/etc/jhb.conf.sh

source "$(dirname "${BASH_SOURCE[0]}")"/src/ink.sh
source "$(dirname "${BASH_SOURCE[0]}")"/src/svg2icns.sh

bash_d_include error
bash_d_include lib

### variables ##################################################################

SELF_DIR=$(dirname "$(greadlink -f "$0")")

### functions ##################################################################

# Nothing here.

### main #######################################################################

error_trace_enable

#----------------------------------------------------- create application bundle

( # run gtk-mac-bundler

  cp "$SELF_DIR"/src/inkscape.bundle "$INK_BLD_DIR"
  cp "$SELF_DIR"/res/inkscape.plist "$INK_BLD_DIR"

  cd "$INK_BLD_DIR" || exit 1
  export ARTIFACT_DIR=$ARTIFACT_DIR   # referenced in inkscape.bundle
  jhb run gtk-mac-bundler inkscape.bundle
)

# Rename to get from lowercase "i" to capitalized "I" as the app bundle name
# depends on the main binary (and that was lowercase in 0.9x).
mv "$INK_APP_DIR" "$INK_APP_DIR".tmp   # requires case-insensitive filesysystem
mv "$INK_APP_DIR".tmp "$INK_APP_DIR"

#----------------------------------------------------- adjust library link paths

# Add rpath according to our app bundle structure.
lib_clear_rpath "$INK_APP_EXE_DIR"/inkscape
lib_add_rpath @executable_path/../Resources/lib "$INK_APP_EXE_DIR"/inkscape
lib_add_rpath @executable_path/../Resources/lib/inkscape \
  "$INK_APP_EXE_DIR"/inkscape

# Libraries in INK_APP_LIB_DIR can reference each other directly.
lib_change_siblings "$INK_APP_LIB_DIR"

# Point GTK modules towards INK_APP_LIB_DIR using @loader_path.
lib_change_paths @loader_path/../../.. "$INK_APP_LIB_DIR" \
  "$INK_APP_LIB_DIR"/gtk-3.0/3.0.0/immodules/*.so \
  "$INK_APP_LIB_DIR"/gtk-3.0/3.0.0/printbackends/*.so

# Point enchant's applespell plugin towards INK_APP_LIB_DIR using @loader_path.
lib_change_paths @loader_path/.. "$INK_APP_LIB_DIR" \
  "$INK_APP_LIB_DIR"/enchant-2/enchant_applespell.so

# Point Ghostscript towards INK_APP_LIB_DIR using @executable_path.
lib_change_paths \
  @executable_path/../lib \
  "$INK_APP_LIB_DIR" \
  "$INK_APP_BIN_DIR"/gs

#------------------------------------------------------ use rpath in cache files

sed -i '' \
  's|@executable_path/../Resources/lib|@rpath|g' \
  "$INK_APP_LIB_DIR"/gtk-3.0/3.0.0/immodules.cache
sed -i '' \
  's|@executable_path/../Resources/lib|@rpath|g' \
  "$INK_APP_LIB_DIR"/gdk-pixbuf-2.0/2.10.0/loaders.cache

#------------------------------------------------------------- modify Info.plist

# update Inkscape version information
/usr/libexec/PlistBuddy \
  -c "Set CFBundleShortVersionString '$(ink_get_version)'" \
  "$INK_APP_PLIST"
/usr/libexec/PlistBuddy \
  -c "Set CFBundleVersion '$INK_BUILD'" \
  "$INK_APP_PLIST"

# update minimum system version according to deployment target
/usr/libexec/PlistBuddy \
  -c "Set LSMinimumSystemVersion $SYS_SDK_VER" \
  "$INK_APP_PLIST"

# add some metadata to make CI identifiable
if $CI_GITLAB; then
  for var in PROJECT_NAME PROJECT_URL COMMIT_BRANCH COMMIT_SHA COMMIT_SHORT_SHA\
             JOB_ID JOB_URL JOB_NAME PIPELINE_ID PIPELINE_URL; do
    # use awk to create camel case strings (e.g. PROJECT_NAME to ProjectName)
    /usr/libexec/PlistBuddy -c "Add CI$(\
      echo $var | awk -F _ '{
        for (i=1; i<=NF; i++)
        printf "%s", toupper(substr($i,1,1)) tolower(substr($i,2))
      }'
    ) string $(eval echo \$CI_$var)" "$INK_APP_PLIST"
  done
fi

#----------------------------------------------------- generate application icon

svg2icns \
  "$INK_DIR"/share/branding/inkscape-mac.svg \
  "$INK_APP_RES_DIR"/inkscape.icns

#----------------------------------------------------------- add file type icons

cp "$INK_DIR"/packaging/macos/res/*.icns "$INK_APP_RES_DIR"

#------------------------------------------------------- add Python and packages

# Install externally built Python framework.
ink_install_python

# Add rpath to find libraries.
lib_add_rpath @executable_path/../../../../../Resources/lib \
  "$INK_APP_FRA_DIR"/Python.framework/Versions/Current/bin/\
python"$INK_PYTHON_VER"
lib_add_rpath @executable_path/../../../../../../../../Resources/lib \
  "$INK_APP_FRA_DIR"/Python.framework/Versions/Current/Resources/\
Python.app/Contents/MacOS/Python

# Install wheels.
ink_pipinstall INK_PYTHON_PKG_APPDIRS         # extension manager
ink_pipinstall INK_PYTHON_PKG_BEAUTIFULSOUP4  # extension manager
ink_pipinstall INK_PYTHON_PKG_CACHECONTROL    # extension manager
ink_pipinstall INK_PYTHON_PKG_CSSSELECT
ink_pipinstall INK_PYTHON_PKG_LXML
ink_pipinstall INK_PYTHON_PKG_NUMPY
ink_pipinstall INK_PYTHON_PKG_PILLOW          # export raster extension
ink_pipinstall INK_PYTHON_PKG_PYGOBJECT
ink_pipinstall INK_PYTHON_PKG_PYSERIAL
ink_pipinstall INK_PYTHON_PKG_SCOUR

#----------------------------------------------------- remove Python cache files

rm -rf "$INK_APP_RES_DIR"/share/glib-2.0/codegen/__pycache__

#-------------------------------------------------- add fontconfig configuration

# Mimic the behavior of having all files under 'share' and linking the
# active ones to 'etc'.
cd "$INK_APP_ETC_DIR"/fonts/conf.d || exit 1

for file in ./*.conf; do
  ln -sf ../../../share/fontconfig/conf.avail/"$(basename "$file")" .
done

# Our customized version loses all the non-macOS paths and sets a cache
# directory below '$HOME/Library/Application Support/Inkscape'.
cp "$SELF_DIR"/res/fonts.conf "$INK_APP_ETC_DIR"/fonts

#-------------------------------- use rpath for GObject introspection repository

for gir in "$INK_APP_RES_DIR"/share/gir-1.0/*.gir; do
  sed "s|@executable_path/..|@rpath|g" "$gir" > "$TMP_DIR/$(basename "$gir")"
done

mv "$TMP_DIR"/*.gir "$INK_APP_RES_DIR"/share/gir-1.0

# compile *.gir into *.typelib files
for gir in "$INK_APP_RES_DIR"/share/gir-1.0/*.gir; do
  jhb run g-ir-compiler \
    -o "$INK_APP_LIB_DIR/girepository-1.0/$(basename -s .gir "$gir")".typelib \
    "$gir"
done