-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
217 lines (160 loc) · 5.47 KB
/
Makefile
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#!/usr/bin/env make
# Copyright (C) 2018--2019 Philip Belemezov.
# All Rights Reserved.
#
# This file is part of Subtitles.
#
# Subtitles is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Subtitles is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Subtitles. If not, see <https://www.gnu.org/licenses/>.
SHELL := /bin/bash
DISTDIR := dist
PIPENV := pipenv
# PyInstaller cannot be installed using pip 19.1.
# See https://github.com/pypa/pip/issues/6163
PIP_REQUIRED_VERSION := '18.1'
VERSION := $(shell cat doc/VERSION)
GIT_COMMIT := $(shell git log --pretty=format:'%h' -n 1)
CREATE_DMG := node_modules/create-dmg/cli.js
NAME := Subtitles
NAME_VERSION = $(NAME)-$(VERSION)
DMG_FILE = $(DISTDIR)/$(NAME_VERSION).dmg
DMG_SRCDIR = $(DISTDIR)/dmg_dir
# DMG_TEMP := $(shell mktemp)
APP_BUNDLE = $(DISTDIR)/Subtitles.app
EXE := $(DISTDIR)/Subtitles/Subtitles.exe
ZIP_FILE := $(DISTDIR)/$(NAME_VERSION).zip
ZIP_FILE_WINDOWS := $(DISTDIR)/$(NAME_VERSION)-Windows.zip
ZIP_FILE_LINUX := $(DISTDIR)/$(NAME_VERSION)-Linux.zip
APPDIR := $(DISTDIR)/$(NAME_VERSION).AppDir
APPIMAGE := $(DISTDIR)/$(NAME_VERSION).AppImage
BUILD_TIMESTAMP := $(DISTDIR)/build.timestamp
DESKTOP_FILE_IN := resources/linux/$(NAME).desktop
DESKTOP_FILE_OUT := $(APPDIR)/$(NAME).desktop
APPRUN_IN := resources/linux/AppRun.sh
APPRUN_OUT := $(APPDIR)/AppRun
PLATFORM := $(shell uname -s)
ifneq (,$(findstring MINGW, $(PLATFORM)))
PLATFORM := Windows
else
ifneq (,$(findstring MSYS_NT, $(PLATFORM)))
PLATFORM := Windows
endif
endif
ifeq ($(PLATFORM),Linux)
ifeq ($(APPIMAGETOOL),)
APPIMAGETOOL := appimagetool
endif
ifeq (,$(shell which $(APPIMAGETOOL)))
$(error "You must have appimagetool in your PATH or set the APPIMAGETOOL environment variable")
endif
endif
ifeq ($(PLATFORM),Windows)
PYTHON := python3
PIP := pip3
PIP_INSTALL := "$(PIP) install"
else
ifeq ($(PLATFORM),Linux)
PYTHON := python
PIP := pip
PIP_INSTALL := "$(PIP) install"
else
ifeq ($(PLATFORM),Darwin)
PYTHON := python
PIP := pip
PIP_INSTALL := "$(PIP) install"
else
ERROR = $(error "Unsupported platform '$(PLATFORM)'")
endif
endif
endif
all: depends build package
diag:
@echo "Platform: $(PLATFORM)"
@echo "Python: $(PYTHON), version: $(shell $(PYTHON) --version)"
@echo "pip: $(PIP), version: $(shell $(PIP) --version)"
@echo "PIP_INSTALL=$(PIP_INSTALL)"
build: $(BUILD_TIMESTAMP)
$(BUILD_TIMESTAMP):
if [ -n "${TRAVIS_COMMIT}" ]; then \
GIT_COMMIT="${TRAVIS_COMMIT}"; \
else \
GIT_COMMIT="$(shell git log --pretty=format:'%h' -n 1)"; \
fi; \
if [ -n "$(GIT_COMMIT)" ]; then \
echo "$(GIT_COMMIT)" > doc/VERSION.commit; \
fi
echo "$(shell uname -n -r -m)" > doc/VERSION.build_host
if [ -n "${TRAVIS_BUILD_NUMBER}" ]; then \
echo "${TRAVIS_BUILD_NUMBER}" > doc/VERSION.build_number; \
fi
$(PIPENV) run pyinstaller -y Subtitles.pyinstaller.spec
touch $(BUILD_TIMESTAMP)
package: package-$(PLATFORM)
package-Darwin: $(DMG_FILE)
$(DMG_FILE): $(BUILD_TIMESTAMP)
@if $(CREATE_DMG) --overwrite "$(APP_BUNDLE)" "$(DISTDIR)" \
| grep 'No usable identity found'; then \
if [ ! -f "$(DISTDIR)/$(NAME) $(VERSION).dmg" ]; then \
@echo "Code signing failed (normal), but DMG not created."; \
exit 1; \
fi ; \
@echo "Warning: Unable to code sign DMG"; \
fi
mv "$(DISTDIR)/$(NAME) $(VERSION).dmg" "$(DISTDIR)/$(NAME_VERSION).dmg"
package-Windows: $(ZIP_FILE_WINDOWS)
$(ZIP_FILE_WINDOWS): $(ZIP_FILE)
mv "$(ZIP_FILE)" "$(ZIP_FILE_WINDOWS)"
$(ZIP_FILE): $(BUILD_TIMESTAMP)
# $(RM) $(ZIP_FILE)
cd $(DISTDIR) && zip -dd -9 -o -r $(NAME_VERSION).zip $(NAME) >/dev/null
@echo "ZIP File $(ZIP_FILE) created."
package-Linux: $(ZIP_FILE_LINUX) $(APPIMAGE)
$(ZIP_FILE_LINUX): $(ZIP_FILE)
mv "$(ZIP_FILE)" "$(ZIP_FILE_LINUX)"
$(APPIMAGE): $(APPDIR)-dir $(APPDIR)
$(APPIMAGETOOL) $(APPDIR) $(APPIMAGE)
$(APPDIR)-dir:
$(RM) -r $(APPDIR)
# mkdir -p $(APPDIR)/usr/bin/
mkdir -p $(APPDIR)/usr/lib/Subtitles/
$(APPDIR): $(BUILD_TIMESTAMP) $(DESKTOP_FILE_OUT) $(APPRUN_OUT)
cp -r $(DISTDIR)/Subtitles/* $(APPDIR)/usr/lib/Subtitles
chmod +x $(APPDIR)/usr/lib/Subtitles/Subtitles
cp $(APPDIR)/usr/lib/Subtitles/Subtitles.png $(APPDIR)/
$(APPRUN_OUT): $(APPRUN_IN)
cp -r $(APPRUN_IN) $(APPRUN_OUT)
chmod +x $(APPRUN_OUT)
$(DESKTOP_FILE_OUT): $(DESKTOP_FILE_IN)
cp $(DESKTOP_FILE_IN) $(DESKTOP_FILE_OUT)
depends: depends-$(PLATFORM) pip-version Pipfile.lock
depends-force:
touch Pipfile
$(MAKE) depends
pip-version:
$(eval PIP_CUR_MAJOR_VERSION := $(shell $(PIPENV) run pip --version | cut -d' ' -f2 | cut -d. -f1))
$(eval PIP_REQ_MAJOR_VERSION := $(shell echo $(PIP_REQUIRED_VERSION) | cut -d. -f1))
@if [ "$(PIP_CUR_MAJOR_VERSION)" == "$(PIP_REQ_MAJOR_VERSION)" ]; then \
echo "pip $(PIP_CUR_MAJOR_VERSION) installed, no down- or upgrade needed" ; \
else \
echo "pip must be changed to $(PIP_REQUIRED_VERSION)" ; \
$(PIPENV) run python -m pip install pip==$(PIP_REQUIRED_VERSION); \
fi
Pipfile.lock: Pipfile
$(PIPENV) sync
depends-Windows:
depends-Linux:
depends-Darwin:
clean:
$(RM) -r build dist
.PHONY: err diag clean build depends depends-$(PLATFORM) pip-version
err: ; $(ERROR)