makefile 8.13 KB
Newer Older
1
LANGUAGE ?= tr
2
AVADANLIKDIR := $(shell cd "$(shell dirname $(lastword $(MAKEFILE_LIST)))/" && pwd)
3

4 5
# Duplicate of CaSILE but need PROJECT variable early
PROJECTDIR := $(shell cd "$(shell dirname $(firstword $(MAKEFILE_LIST)))/" && pwd)
6 7
GITNAME := $(notdir $(shell git worktree list | head -n1 | awk '{print $$1}'))
PROJECT ?= $(GITNAME)
8
PUBLISHERDIR ?= $(AVADANLIKDIR)
9

10 11
OUTPUTDIR ?= ${HOME}/Nextcloud/viachristus/$(PROJECT)
INPUTDIR  ?= $(OUTPUTDIR)
12

13
ORIGLAYOUTS := $(LAYOUTS)
14

15
LAYOUTS ?= a5trim-kartonkapakli
16
FORMATS ?= pdfs epub
17
LAYOUTS_app = uygulama
18
FORMATS_app = pdfs app
19
LAYOUTS_ekran = ekran
20
FORMATS_ekran = pdfs
21
LAYOUTS_web = $(ORIGLAYOUTS) a4-cikti a4-spiral
22
FORMATS_web = pdfs epub mobi web play
23
LAYOUTS_isbn-basvuru = $(ORIGLAYOUTS)
24
FORMATS_isbn-basvuru = pdfs
25
LAYOUTS_1.basim = $(ORIGLAYOUTS)
26
FORMATS_1.basim = pdfs play
27 28 29 30 31 32 33 34
LAYOUTS_2.basim = $(LAYOUTS_1.basim)
FORMATS_2.basim = $(FORMATS_1.basim)
LAYOUTS_3.basim = $(LAYOUTS_2.basim)
FORMATS_3.basim = $(FORMATS_2.basim)
LAYOUTS_4.basim = $(LAYOUTS_3.basim)
FORMATS_4.basim = $(FORMATS_3.basim)
LAYOUTS_5.basim = $(LAYOUTS_4.basim)
FORMATS_5.basim = $(FORMATS_4.basim)
35

36
DEBUGTAGS = casile viachristus
37

38
M4MACROS += $(AVADANLIKDIR)/viachristus.m4
39
METADATA += $(AVADANLIKDIR)/viachristus.yml
40
LUAINCLUDES += .avadanlik.lua
41
LUALIBS += $(AVADANLIKDIR)/viachristus.lua
42 43
SILEPATH += $(AVADANLIKDIR)

44
# Use VC's gitlab config for CI builds
45 46
CITEMPLATE ?= $(AVADANLIKDIR)/gitlab-ci.yml
CICONFIG ?= .gitlab-ci.yml
47

48
# Work around GNU make defaulting to running the first rule defined
49
default: pdfs
50

51 52 53 54
ifeq ($(DEBUG),true)
SILE = /home/caleb/projects/sile/sile
$(call prepend,SILEPATH,/home/caleb/projects/sile/ )
endif
55

Caleb Maclennan's avatar
Caleb Maclennan committed
56
# CI runners need help getting the branch name because of funky checkouts
57
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
58
ifeq ($(BRANCH),HEAD)
59 60 61
ifeq ($(shell git rev-parse master),$(shell git rev-parse HEAD))
BRANCH = master
else
62 63
BRANCH = $(CI_BUILD_REF_NAME)
endif
64
endif
Caleb Maclennan's avatar
Caleb Maclennan committed
65

66
# If this commit is tagged or an a special branch, run special rules for it
67
ALLTAGS := $(strip $(shell git tag --points-at HEAD | xargs echo) $(and $(findstring /,$(BRANCH)),$(BRANCH)))
Caleb Maclennan's avatar
Caleb Maclennan committed
68
ifneq ($(ALLTAGS),)
69

70
DIFF = false
71

72 73
# Use first segment of tags as target names (sort is to deduplicate)
TARGETS = $(sort $(subst /,,$(dir $(ALLTAGS))))
74 75

# Use last segment of tag names as formats
Caleb Maclennan's avatar
Caleb Maclennan committed
76 77
FORMATS = $(sort $(notdir $(ALLTAGS)))
TAGNAME = $(firstword $(sort $(notdir $(ALLTAGS))))
78

79
# Else not directly on any tags
80 81
else

82 83 84
# If not on a tagged release, don't stick with pinned toolkit versions
init: update_toolkits

Caleb Maclennan's avatar
Caleb Maclennan committed
85
# If we are not on the master branch, guess the parent and output to a directory
86
ifneq ($(BRANCH),master)
87
PARENT ?= $(shell git merge-base master $(BRANCH))
88 89
endif

Caleb Maclennan's avatar
Caleb Maclennan committed
90 91 92 93 94 95
# If the environment has information about a parent, override the calculated one
_BRANCH = PARENT_$(subst +,_,$(subst -,_,$(BRANCH)))
ifneq ($($(_BRANCH)),)
PARENT = $($(_BRANCH))
endif

96
# End non-tagged
97 98
endif

99
# Assume OUTPATH is always used in a foreach loop with TARGET variable set
100
ifeq ($(BRANCH),master)
101
OUTPATH = $(TARGET)$(and $(TAGNAME),/$(TAGNAME))
102
else
103
OUTPATH = $(BRANCH)
104 105
endif

Caleb Maclennan's avatar
Caleb Maclennan committed
106
# If there is a layout associated with a tag, only build that layout
107 108
ifdef LAYOUTS_$(TAGNAME)
LAYOUTS := $(LAYOUTS_$(TAGNAME))
109 110
endif

111
# If there is a format associated with a tag, only build that format
112 113
ifdef FORMATS_$(TAGNAME)
FORMATS := $(FORMATS_$(TAGNAME))
114 115
endif

116 117
LIVESYNC = false

118 119
# Setup target dependencies to mimic stages of a CI pipeline
ifeq ($(MAKECMDGOALS),ci)
120
LIVESYNC = true
121
sync_pre: init
122 123
endif

124 125 126 127
ifneq ($(CI),)
LIVESYNC = true
endif

128 129 130 131 132 133 134
debug: debug_avadanlik

.PHONY: debug_avadanlik

debug_avadanlik:
	@echo AVADANLIKDIR: $(AVADANLIKDIR)
	@echo BRANCH: $(BRANCH)
135 136 137
	@echo INPUTDIR: $(INPUTDIR)
	@echo OUTPATH: $(OUTPATH)
	@echo OUTPUTDIR: $(OUTPUTDIR)
138
	@echo TAGNAME: $(TAGNAME)
139

140 141 142 143 144 145
check_dependencies: check_dependencies_avadanlik

.PHONY: check_dependencies_avadanlik
check_dependencies_avadanlik:
	hash rsync

146 147 148
.avadanlik.lua:
	cat <<- EOF > $@
		CASILE.publisher = "viachristus"
Caleb Maclennan's avatar
Caleb Maclennan committed
149
		CASILE.avadanlikdir = "$(AVADANLIKDIR)"
150 151
	EOF

152 153 154 155 156 157
.PHONY: update_all_tags
update_all_tags: $(UPDATATAGTARGETS)

UPDATATAGTARGETS = update_uygulama_tags update_ekran_tags update_web_tags
.PHONY: $(UPDATATAGTARGETS)
$(UPDATATAGTARGETS): update_%_tags:
158
	git tag |
159
		grep '/$*$$' |
160 161 162 163 164
		while read tag; do
			git tag -d $$tag
			git tag $$tag
		done

165 166
init: init_avadanlik

Caleb Maclennan's avatar
Caleb Maclennan committed
167
.PHONY: init_avadanlik
168
init_avadanlik: time_warp_avadanlik $(AVADANLIKDIR)/yarn.lock $(OUTPUTDIR)
169

170
$(AVADANLIKDIR)/yarn.lock: $(AVADANLIKDIR)/package.json
Caleb Maclennan's avatar
Caleb Maclennan committed
171 172 173 174
	cd $(AVADANLIKDIR) && yarn install

update_toolkits: update_avadanlik

175
.PHONY: update_avadanlik
176
update_avadanlik: init_avadanlik
177
	git submodule update --init --remote -- $(AVADANLIKDIR)
178
	$(call time_warp,$(AVADANLIKDIR))
Caleb Maclennan's avatar
Caleb Maclennan committed
179
	cd $(AVADANLIKDIR) && yarn upgrade
180

181 182 183 184 185 186
time_warp: time_warp_avadanlik

.PHONY: time_warp_avadanlik
time_warp_avadanlik:
	$(call time_warp,$(AVADANLIKDIR))

187 188 189
$(OUTPUTDIR):
	mkdir -p $@

Caleb Maclennan's avatar
Caleb Maclennan committed
190 191
# Create per book jobs in the CI config
define ci_setup ?=
192
	yq -M -s -y -e --arg sources "$(strip $(SOURCES))" \
193
		'. + ($$sources | [splits(" ") as $$target | [["pdfs", "renderings", "promotionals"][] as $$action | { ($$target+"."+$$action) : { "extends": ("."+$$action), "only": [ "master", ("/^"+$$target+"\\/.*/")], "except": (if ($$action != "pdfs") then ["/.*\\/isbn-basvuru$$/", "/.*\\/\\d+\\.-basim$$/"] else null end),  "artifacts": { "paths": [($$target+"*")]  } }}][]]) | add'
Caleb Maclennan's avatar
Caleb Maclennan committed
194 195
endef

196
.PHONY: sync_pre
197
sync_pre: | $(require_inputdir)
198
	$(foreach TARGET,$(TARGETS),mkdir -p $(INPUTDIR)/$(OUTPATH);
199 200 201 202 203
		find $(INPUTDIR)/$(OUTPATH)/ -maxdepth 1 -type f \( \
				-name "$(TARGET)*" \
				$(and $(call printisbn,$(TARGET)),-or -name "$(call printisbn,$(TARGET))*") \
				$(and $(call ebookisbn,$(TARGET)),-or -name "$(call ebookisbn,$(TARGET))*") \
			\) -execdir rsync -utv {} $(PROJECTDIR)/ \;;)
204 205 206 207
	$(if $(strip $(filter-out $(TARGETS),$(PROJECT))),
		find $(INPUTDIR)/ -maxdepth 1 -type f \
			-name "$(PROJECT)*" \
			-execdir rsync -utv {} $(PROJECTDIR)/ \;)
208

209 210
.PHONY: sync_post
sync_post: | $(require_pubdir) $(require_outputdir)
211 212 213 214 215 216
	$(foreach TARGET,$(TARGETS),mkdir -p $(OUTPUTDIR)/$(OUTPATH);
		find $(PUBDIR)/ -maxdepth 1 -type f \( \
				-name "$(TARGET)*" \
				$(and $(call printisbn,$(TARGET)),-or -name "$(call printisbn,$(TARGET))*") \
				$(and $(call ebookisbn,$(TARGET)),-or -name "$(call ebookisbn,$(TARGET))*") \
			\) -execdir rsync -ct {} $(OUTPUTDIR)/$(OUTPATH)/ \;;)
217 218 219 220
	$(if $(strip $(filter-out $(TARGETS),$(PROJECT))),
		find $(PUBDIR)/ -maxdepth 1 -type f  \
			-name "$(PROJECT)*" \
			-execdir rsync -ct {} $(OUTPUTDIR)/ \;)
221

222 223
define addtopub ?=
	$(DRAFT) && rm -f $(PUBDIR)/$@ || ln -f $@ $(PUBDIR)/$@
224
	$(and $(filter true,$(LIVESYNC)),$(OUTPUTDIR),$(foreach TARGET,$(call parse_bookid,$@),$(DRAFT) || install -Dt $(OUTPUTDIR)/$(or $(strip $(filter-out $(PROJECT),$(TARGET))),$(OUTPATH)) $@))
225 226
endef

227 228
.PHONY: yayinlar.viachristus.com
yayinlar.viachristus.com:
229 230 231 232 233 234
	curl \
		-X POST \
		-F token=${DEPLOY_TOKEN} \
		-F ref=master \
		https://gitlab.alerque.com/api/v4/projects/112/trigger/pipeline

235
urlinfo = https://yayinlar.viachristus.com/$(call parse_bookid,$1)
236

237 238 239
# Override sources for auto-generated resources
publisher_logo-grey.svg: PUBLISHERLOGO = $(PUBLISHERDIR)/logo-grey.svg
publisher_emblum-grey.svg: PUBLISHEREMBLUM = $(PUBLISHERDIR)/emblum-grey.svg
240

241
define magick_sembol_filter ?=
242 243 244
	-alpha on \
	-channel RGB \
	+level-colors '#ff0000','#550000'
245 246
endef

247 248 249 250 251
define magick_logo_filter ?=
	-channel RGB -negate \
	-level 20%,60%!
endef

252
NAMELANGS = en tr und part xx
253
NAMESFILES = $(foreach LANG,$(NAMELANGS),$(CASILEDIR)/names.$(LANG).txt)
254

255
proper_names.txt: $(SOURCES) $(NAMESFILES) | $(CASILEDIR)/bin/extract_names.pl
256
	$(call skip_if_tracked,$@)
257
	find -maxdepth 2 -name '*.md' -execdir cat {} \; | $(CASILEDIR)/bin/extract_names.pl |\
258
		sort -u |\
259
		grep -vxf <(cat $(NAMESFILES)) > $@
260

261
sort_names: proper_names.txt | $(CASILEDIR)/bin/sort_names.zsh $(NAMESFILES)
262 263
	sort_names.zsh < $^

264
tag_names: $(SOURCES) | $(CASILEDIR)/bin/tag_names.zsh $(NAMESFILES)
265 266
	git diff-index --quiet --cached HEAD || exit 1 # die if anything already staged
	git diff-files --quiet -- $^ || exit 1 # die if input files have uncommitted changes
267
	tag_names.zsh la avadanlik/names.la.txt $^
268 269
	tag_names.zsh en avadanlik/names.en.txt $^

270
avadanlik/names.%.txt:
271
	test -f $@ || touch $@
272
	sort -u $@ | sponge $@