aboutsummaryrefslogtreecommitdiffhomepage
path: root/makefile
blob: 0bde8ce45418be1932b4d8e4b2238bde1c5ceb23 (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
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
#include .envrc-local
PROG_VER_GIT :=$(shell echo `git describe --long --tags | sed -e "s/^[ a-z_-]\+\([0-9.]\+\)/\1/;s/\([^-]*-g\)/r\1/;s/-/./g"`)
#PROG_VER_DECLARED :=$(shell echo `cat ./views/version.txt | grep --color=never "enum" | sed 's/.\+(\([0-9]\+\),[ \t]\+\([0-9]\+\),[ \t]\+\([0-9]\+\)[ \t]*).\+/\1.\2.\3/g'`)
DUB=dub
DUB_FLAGS=-v --force --compiler=
PRG_NAME=doc-reform
PRG_NICKAME=spine
PRG_NAME_DIR=$(shell echo `echo $(PRG_NAME) | sed -e "s/-/_/g"`)
PRG_SRC=$(PRG_NAME).d
PRG_SRCDIR=./src
PRG_BIN=$(PRG_NAME)
PRG_BINDIR=./bin
PRG_DOCDIR=./docs
EMACSLISP=/usr/share/emacs/site-lisp
ORG_VER_AVAILABLE=$(shell echo `ls -d ~/.emacs.d/elpa/org-???????? | cut -d '-' -f2`)
EMACSLISP_ORG=~/.emacs.d/elpa/org-$($(shell echo $(ORG_VER_AVAILABLE)))
ORG_CONTRIB_VER_AVAILABLE=$(shell echo `ls -d ~/.emacs.d/elpa/org-plus-contrib-???????? | cut -d '-' -f2`)
EMACSLISP_ORG_CONTRIB=~/.emacs.d/elpa/org-plus-contrib-$($(shell echo $(ORG_CONTRIB_VER_AVAILABLE)))
ORGFILELIST=$(shell echo `ls -1 org/*.org`)
ORGFILES=""
ORGDIR :=$(shell echo `pwd`)
SiSU_MARKUP_SAMPLES_FIND_PODS= \
find data/pod -maxdepth 2 -name pod.manifest | cut -f 1-3 -d / | sort

SiSU_MARKUP_SAMPLES_PODS_FOUND= \
$(SiSU_MARKUP_SAMPLES_FIND_PODS) | xargs

# SiSU_MARKUP_SAMPLES_DIR_FILES_FOUND = \
# find data/sisudir/media/text -name *.ss[tm] | sort | xargs
#
Date                    := `date "+%Y%m%d"`
#SpineBIN                := $(SpineBIN)                # './result/bin'
#SpineOUT                := $(SpineOUT)                # '/srv/www/spine'
#SpinePOD                := $(SpinePOD)                # 'markup/pod'
#SpineSearchActionLocal  := $(SpineSearchActionLocal)  # 'http://localhost/spine_search'
#SpineSearchActionRemote := $(SpineSearchActionRemote) # 'https://sisudoc.org/spine_search'
#SpineCGIform            := $(SpineCGIform)            # 'spine_search'
#SpineSQLdb              := $(SpineSQLdb)              # 'spine.search.db'
#SpineCGIbin             := $(SpineCGIbin)             # '/var/www/cgi/cgi-bin'
#SpineDBpath             := "$(SpineDBpath)"           # '/var/www/sqlite'
hwd                     := `pwd`
gwd                     := `pwd` + "/src/ext_depends"
deps                    := "`ls -gx './src/ext_depends'`"
dirs_loc                := "`ls -gx '.'`"
#dirs                    := "`ls -gx $${gwd}`"

default: flake-check

flake-check:
	nix flake update; \
	nix flake check; \
	echo -e 'nix flake show ❯❯\n'; \
	nix flake show; \
	echo -e '\n❯❯ nix flake update && nix flake check --show-trace && nix flake show && nix develop ".#devShell" -c zsh\n'; \
	echo -e '❯❯ nix develop\n❯❯ nix develop -c zsh\n'; \
	echo -e '❯❯ nix build ".#spine-ldc" --print-build-logs |& nom\n❯❯ nix build ".#spine-dmd" --print-build-logs |& nom\n'; \
	echo -e '❯❯ make -s\n❯❯ make -s nix-build-ldc\n❯❯ make -s nix-build-dmd\n'; \
	echo -e '❯❯ make -s ldc\n❯❯ make -s dmd\n'; \
	echo -e '❯❯ $(DUB) --compiler=ldc2 --build=ldc2\n❯❯ $(DUB) --compiler=dmd --build=dmd\n';

nix-devshell:
	echo -ne '\n❯❯ nix flake update && nix flake check --show-trace && nix flake show && nix develop ".#devShell"\n\n❯❯ nix build ".#default" --print-build-logs\n❯❯ nix build ".#spine-dmd" --print-build-logs\n❯❯ nix build ".#spine-ldc" --print-build-logs\n❯❯ nix build ".#spine-gdc" --print-build-logs\n\n'; \
	nix flake update && nix flake check --show-trace && nix flake show && nix develop ".#devShell"

# nix build
build: nix-build-default

nix-build-default:
	nix build ".#default" --print-build-logs

nix-build-dmd:
	nix build ".#spine-dmd" --print-build-logs

nix-build-ldc:
	nix build ".#spine-ldc" --print-build-logs

nix-build-gdc:
	nix build ".#spine-gdc" --print-build-logs

commands:
	rg --color=always -B1 "^[a-zA-Z_-]+:" makefile | page

cmds:
	rg --color=always -B1 "^[a-zA-Z_-]+:" makefile | page

# tangle org files
org-tangle:
	cd ./org; \
	org-tangle *.org; \
	cd -

# output local
out-local:
	$(SpineBIN)/spine -v \
	--epub --html \
	--latex --latex-init --html-link-pdf \
	--cgi-sqlite-search-filename=$(SpineCGIform) --cgi-url-action=$(SpineSearchActionLocal) \
	--sqlite-update --sqlite-db-filename=$(SpineSQLdb) --html-link-search \
	--curate --html-link-curate \
	--output=$(SpineOUT) $(SpinePOD)/*

# output remote
out-remote:
	$(SpineBIN)/spine -v \
	--epub --html \
	--latex --latex-init --html-link-pdf \
	--cgi-sqlite-search-filename=$(SpineCGIform) --cgi-url-action=$(SpineSearchActionRemote) \
	--sqlite-update --sqlite-db-filename="$(SpineSQLdb)" --html-link-search \
	--curate --html-link-curate \
	--output=$(SpineOUT) $(SpinePOD)/*

# output local plus markup source, pods
out-local-plus-pods:
	$(SpineBIN)/spine -v \
	--pods --html-link-markup \
	--epub --html \
	--latex --latex-init --html-link-pdf \
	--cgi-sqlite-search-filename=$(SpineCGIform) --cgi-url-action=$(SpineSearchActionLocal) \
	--sqlite-update --sqlite-db-filename=$(SpineSQLdb) --html-link-search \
	--curate --html-link-curate \
	--output=$(SpineOUT) $(SpinePOD)/*

# output remote plus markup source, pods
out-remote-plus-pods:
	$(SpineBIN)/spine -v \
	--pods --html-link-markup \
	--epub --html \
	--latex --latex-init --html-link-pdf \
	--cgi-sqlite-search-filename=$(SpineCGIform) --cgi-url-action=$(SpineSearchActionRemote) \
	--sqlite-update --sqlite-db-filename="$(SpineSQLdb)" --html-link-search \
	--curate --html-link-curate \
	--output=$(SpineOUT) $(SpinePOD)/*

# epub output
out-epub:
	$(SpineBIN)/spine -v \
	--epub --output=$(SpineOUT) $(SpinePOD)/*

# html output with local search links
out-html:
	$(SpineBIN)/spine -v --generated-by \
	--curate \
	--html --html-link-search --html-link-curate --cgi-url-action=$(SpineSearchActionLocal) \
	--output=$(SpineOUT) $(SpinePOD)/*

# latex output
out-latex:
	$(SpineBIN)/spine -v \
	--latex \
	--output=$(SpineOUT) $(SpinePOD)/*

# odf output
out-odf:
	$(SpineBIN)/spine -v \
	--odf \
	--output=$(SpineOUT) $(SpinePOD)/*

# sqlite output
out-sqlite:
	$(SpineBIN)/spine -v \
	--sqlite-update --sqlite-db-filename=$(SpineSQLdb) \
	--output=$(SpineOUT) $(SpinePOD)/*

# generate markup sample output with local search links
output-samples-local:
	$(SpineBIN)/spine -v \
	--latex --latex-init \
	--epub \
	--html --html-link-search --html-link-pdf --html-link-curate --html-link-markup \
	--cgi-sqlite-search-filename=$(SpineCGIform) --cgi-url-action=$(SpineSearchActionLocal) \
	--curate \
	--sqlite-update --sqlite-db-filename="$(SpineSQLdb)" \
	--output=$(SpineOUT) $(SpinePOD)/*

# generate markup sample output with remote search links
output-samples-remote:
	$(SpineBIN)/spine -v \
	--generated-by \
	--latex --latex-init \
	--epub \
	--html --html-link-search --html-link-pdf --html-link-curate \
	--cgi-sqlite-search-filename=$(SpineCGIform) --cgi-url-action=$(SpineSearchActionRemote) \
	--curate \
	--sqlite-update --sqlite-db-filename=$(SpineSQLdb) \
	--output=$(SpineOUT) $(SpinePOD)/*

# generate markup sample output with local search links
output-samples: output-samples-local

# nix build (remote) run
generate-output-remote: nix-build output-samples-remote

# nix build (local) run
generate-output-local: nix-build output-samples-local

# preview org files vim
files-vi:
	fd --max-depth 6 --type file -g "*" | sort \
	| fzf \
	  --preview='bat --color "always" {}' \
	  --preview-window=right:66% \
	  --bind="enter:execute(nvim {})"; \

# preview org files emacs
files-e:
	fd --max-depth 6 --type file -g "*" | sort \
	| fzf \
	  --preview='bat --color "always" {}' \
	  --preview-window=right:66% \
	  --bind="enter:execute(emacsclient -nw -a -f {})"; \

# preview org files vim
org-v:
	cd ./org; \
	fd --max-depth 5 --type file -g "*.org" | sort \
	| fzf \
	  --preview='bat --color "always" {}' \
	  --preview-window=right:66% \
	  --bind="enter:execute(nvim {})"; \
	cd -

# preview org files emacs
org-e:
	cd ./org; \
	fd --max-depth 5 --type file -g "*.org" | sort \
	| fzf \
	  --preview='bat --color "always" {}' \
	  --preview-window=right:66% \
	  --bind="enter:execute(emacsclient -nw -a -f {})"; \
	cd -

# show markup pod source selections
markup:
	ls -1 --color=always $(SpinePOD)
	ls -1 -d --color=always $(SpinePOD)/*/

# show markup pod source tree
markup-pod-tree:
	exa -alT --git -I'.git|.dub|*_' --color=always -L5 $(SpinePOD) | less -R

# show markup pod source tree
tree-src-search-cgi:
	exa -alT --git -I'*_' --color=always -L5 $(SpineSearchCGI)/src $(SpineSearchCGI)/views | less -R

# show markup files
markup-files:
	cd $(SpinePOD); \
	find . -type f -iname "*sst"; \
	cd -; \
	echo $(SpinePOD)
# find $(SpinePOD)/. -type f -iname "*sst"

# preview markup files vim
markup-files-vi:
	cd $(SpinePOD); \
	fd --max-depth 5 --type file -g "*.ss?" | sort \
	| fzf \
	  --preview='bat --color "always" {}' \
	  --preview-window=right:66% \
	  --bind="enter:execute(vim {})"; \
	cd -

# preview markup files emacs
markup-files-e:
	cd $(SpinePOD); \
	fd --max-depth 5 --type file -g "*.ss?" | sort \
	| fzf \
	  --preview='bat --color "always" {}' \
	  --preview-window=right:66% \
	  --bind="enter:execute(emacsclient -nw -a -f {})"; \
	cd -

# markup samples list
markup-sample: markup-pod-sample

# markup samples list
markup-pod-sample:
	find data/pod -name pod.manifest | cut -f 1-3 -d / | sort

# markup samples pod manifests and sst files
markup-samples: markup-pod-samples markup-file-samples

# markup samples pod manifests
markup-pod-samples:
	echo $(SpinePOD); \
	find $(SpinePOD) -name pod.manifest | sort

#find $(SpinePOD) -name pod.manifest | sed -E 's:.+?(([/][^/]+){2})$:\1:'

# markup samples sst files
markup-file-samples:
	echo $(SpinePOD); \
	find $(SpinePOD) -name *.ss[tm] | sort

# archive spine output (www)
spineWWWarchive:
	cd /srv/www ; \
	rm spine_output.$(Date).tar.bz2 ; \
	sudo tar --exclude='./spine/latex' --exclude='./spine/pod' --exclude='./spine/*_' -cjf spine_output.$(Date).tar.bz2 ./spine ; \
	cd -

# rsync archived spine output to Linode
spineWWWrsyncLinode:
	rsync -v /srv/www/spine_output.$(Date).tar.bz2 linode:./stage/. ; \
	rsync -v /var/www/sqlite/spine.search.db linode:./stage/. ; \
	echo "tar -xf ../spine_output.$(Date).tar.bz2"

# get project external dependencies
depends_get:
	dub upgrade; \
	cd $${gwd} && \
	echo "$${dirs_loc}" && \
	for dir in $${dirs_loc}; do \
	  if [[ -d $${dir} ]]; then \
	    echo $${gwd}/$${dir} && \
	    if [[ "imageformats" == $${dir} ]]; then \
	      echo $${gwd}/$${dir} && \
	      rm -rvf $${gwd}/$${dir} && \
	      git clone --depth=1 https://github.com/tjhann/$${dir} && \
	      cd $${dir} && \
	      echo $$PWD && \
	      echo "$${dir} `git rev-parse HEAD | cut -c 1-8`"   > ../$${dir}.meta && \
	      echo "https://github.com/tjhann/$${dir}"           >> ../$${dir}.meta && \
	      echo "Boost Software License 1.0 (BSL-1.0)"       >> ../$${dir}.meta && \
	      cd $${gwd} && \
	      rm -rf $${gwd}/$${dir}/.git; \
	    elif [[ "d2sqlite3" == $${dir}  || "D-YAML" == $${dir} || "tinyendian" == $${dir} ]]; then \
	      echo $${gwd}/$${dir} && \
	      rm -rvf $${gwd}/$${dir} && \
	      git clone --depth=1 https://github.com/dlang-community/$${dir} && \
	      cd $${gwd}/$${dir} && \
	      echo "$${dir} `git rev-parse HEAD | cut -c 1-8`"   > ../$${dir}.meta && \
	      echo "https://github.com/dlang-community/$${dir}"  >> ../$${dir}.meta && \
	      echo "Boost Software License 1.0 (BSL-1.0)"       >> ../$${dir}.meta && \
	      cd $${gwd} && \
	      rm -rf $${gwd}/$${dir}/.git; \
	    fi; \
	  fi; \
	done; \
	cd $${hwd}

# get and set project external dependencies
depends_set: depends_get
	dub describe | sed 's~$(shell echo `pwd | sed 's_/_\\/_g'`)~.~g'  > dub_describe.json

changelog_:
	git log --pretty=format:'---%+s %+as %ae%+h%d%+b' --no-merges | sed "/^\\s*$$/d" | sed "s/^---$$//" | sed "s/^\(\*\)\+/-/" | sed "s/ \+$$//" > CHANGELOG_

# git changelog for project
changelog:
	git log --pretty=format:'---%+s %+as %ae%+h%d%+b' --no-merges | sed "/^\\s*$$/d" | sed "s/^---$$//" | sed "s/^\(\*\)\+/-/" | sed "s/ \+$$//" | sed "s/ \+$//" > CHANGELOG_

# remove test tarball dir
nixGitHEADtarballClean:
	if [ -d "./tarballGitHEAD" ]; then \
	  rm -rv ./tarballGitHEAD; \
	fi;

# clean create check & build test tarball
nixGitHEADtarball: nixGitHEADtarballClean nixGitHEADtarballTar nixGitHEADtarballCheck nixGitHEADtarballBuild

get_depends:
	hwd=$$(echo `pwd`) && \
	gwd="$${hwd}/src/ext_depends" && \
	dirs=$$(echo `ls -gx $${gwd}`) && \
	license_bsl="Boost Software License 1.0 (BSL-1.0)" && \
	echo $${hwd} && \
	echo $${gwd} && \
	echo $${deps} && \
	dub upgrade; \
	cd $${gwd} && \
	for dir in $${deps}; do \
	  if [ -d $${dir} ]; then \
	    echo $${dir} && \
	    if [ "imageformats" == $${dir} ]; then \
	      echo $${dir} && \
	      rm -rf $${dir} && \
	      git clone --depth=1 https://github.com/tjhann/$${dir} && \
	      cd $${dir} && \
	      echo $$PWD && \
	      echo "$${dir} `git rev-parse HEAD | cut -c 1-8`"   > ../$${dir}.meta && \
	      echo "https://github.com/tjhann/$${dir}"          >> ../$${dir}.meta && \
	      echo "$${license_bsl}"                            >> ../$${dir}.meta && \
	      cd $${gwd} && \
	      rm -rf $${dir}/.git; \
	    elif [[ "d2sqlite3" == $${dir}  || "D-YAML" == $${dir} || "tinyendian" == $${dir} ]]; then \
	      echo $${dir} && \
	      rm -rf $${dir} && \
	      git clone --depth=1 https://github.com/dlang-community/$${dir} && \
	      cd $${dir} && \
	      echo "$${dir} `git rev-parse HEAD | cut -c 1-8`"   > ../$${dir}.meta && \
	      echo "https://github.com/dlang-community/$${dir}" >> ../$${dir}.meta && \
	      echo "$${license_bsl}"                            >> ../$${dir}.meta && \
	      cd $${gwd} && \
	      rm -rf $${dir}/.git; \
	    fi; \
	  fi; \
	done; \
	cd $${hwd}

set_depends: get_depends
	dub describe | sed 's~$(shell echo `pwd | sed 's_/_\\/_g'`)~.~g'  > dub_describe.json

rm_flakelock:
	git reset HEAD flake.lock && \
	touch flake.lock \
	git rm -f flake.lock

flake_update:
	git add .; \
	nix flake lock && \
	git reset HEAD flake.lock; \
	cp flake.lock flake.lock_

flake_update_move_lock: flake_update
	touch flake.lock \
	git rm -f flake.lock

set_latest: set_depends flake_update rm_flakelock

dub_upgrade:
	$(DUB) upgrade

dc: ldc

compile: ldc

all: dmd ldc gdc

all_ver: dmd_ver ldc_ver gdc_ver

meson_clean_build_dir:
	rm -r build; mkdir build

meson_redo: meson_clean_build_dir meson_build

meson_project_build_clean: clean skel tangle dub_upgrade meson_build

meson: meson_clean_build_dir dub_upgrade meson_build

all_clean: clean tangle dmd ldc gdc

all_ver_clean: clean tangle dmd_ver ldc_ver gdc_ver

dmd: dub_upgrade
	$(DUB) --compiler=dmd --build=dmd --build=release-nobounds
	notify-send -t 0 'D dmd compiled test release executable ready' 'spine-dmd'

dmd_clean_ver: clean tangle dmd_ver

dmd_rel: expunge skel tangle
	$(DUB) --compiler=dmd --build=spine-release

dmd_rel_tangle: tangle
	$(DUB) --compiler=dmd --build=spine-dmd

dmd_rel_expunge_tangle: expunge skel tangle dmd_rel_tangle

gdc: dub_upgrade
	$(DUB) --compiler=gdc --build=gdc
	notify-send -t 0 'D gdc compiled test release executable ready' 'spine-gdc'

gdc_clean_ver: clean tangle gdc_ver

gdc_rel: expunge skel tangle
	$(DUB) --compiler=gdc --config=spine-release

gdc_rel_tangle: tangle
	$(DUB) --compiler=gdc --config=spine-gdc

gdc_rel_expunge_tangle: expunge skel tangle gdc_rel_tangle

ldc: dub_upgrade
	$(DUB) --compiler=ldc2 --build=ldc2 --build=release
	notify-send -t 0 'D ldc compiled test release executable ready' 'spine-ldc'

# assumes git tags with program version
ldc_ver: dub_upgrade
	$(DUB) --compiler=ldc2 --config=ldc-version
	mv bin/spine-ldc-ver bin-archive/spine-$(PROG_VER_DECLARED)-tag-$(PROG_VER_GIT)-ldc
	notify-send -t 0 'D ldc2 compiled test release executable ready' 'spine-$(PROG_VER_DECLARED)-tag-$(PROG_VER_GIT)-ldc'

ldc_clean_ver: clean tangle ldc_ver

ldc_rel: expunge skel tangle
	$(DUB) --compiler=ldc2 --config=spine-release

ldc_rel_tangle: tangle
	$(DUB) --compiler=ldc2 --config=spine-ldc

ldc_rel_expunge_tangle: expunge skel tangle ldc_rel_tangle

reinit: clean skel tangle

skel:
	mkdir -p $(PRG_BINDIR); \
	mkdir -p $(PRG_BINDIR)-archive; \
	mkdir -p build; \
	mkdir -p views; \
	mkdir -p data; \
	mkdir -p sundry/misc/util/d/cgi/search/cgi-bin/src; \
	mkdir -p sundry/misc/util/d/tools/markup_conversion; \
	mkdir -p sundry/misc/editor-syntax-etc/emacs; \
	mkdir -p sundry/misc/editor-syntax-etc/vim/syntax; \
	mkdir -p sundry/misc/editor-syntax-etc/vim/colors; \
	mkdir -p sundry/misc/editor-syntax-etc/vim/ftplugin; \
	mkdir -p sundry/misc/editor-syntax-etc/vim/rc; \
	mkdir -p sundry/misc/editor-syntax-etc/vim/templates; \
	mkdir -p $(PRG_SRCDIR)/$(PRG_NAME_DIR)/conf; \
	mkdir -p $(PRG_SRCDIR)/$(PRG_NAME_DIR)/io_in; \
	mkdir -p $(PRG_SRCDIR)/$(PRG_NAME_DIR)/io_out; \
	mkdir -p $(PRG_SRCDIR)/$(PRG_NAME_DIR)/meta; \
	mkdir -p $(PRG_SRCDIR)/$(PRG_NAME_DIR)/share; \
	mkdir -p $(PRG_SRCDIR)/$(PRG_NAME_DIR); \
	mkdir -p $(PRG_BINDIR);

init: skel

clean:
	rm -rf build; \
	rm -rf $(PRG_SRCDIR); \
	rm -rf $(PRG_DOCDIR);

clean_bin:
	rm $(PRG_BINDIR)/*

clean_src:
	rm -rf $(PRG_SRCDIR);

clean_docs:
	rm -rf $(PRG_DOCDIR)

expunge:
	rm -f dub.selections.json; \
	rm -rf build; \
	rm -rf $(PRG_SRCDIR); \
	rm -rf $(PRG_BINDIR); \
	rm -rf $(PRG_DOCDIR);

distclean: expunge

distclean_and_init: expunge
	mkdir -p views; \
	mkdir -p sundry/misc/util/d/cgi/search/cgi-bin/src; \
	mkdir -p sundry/misc/util/d/tools/markup_conversion; \
	mkdir -p sundry/misc/editor-syntax-etc/emacs; \
	mkdir -p sundry/misc/editor-syntax-etc/vim/syntax; \
	mkdir -p sundry/misc/editor-syntax-etc/vim/colors; \
	mkdir -p sundry/misc/editor-syntax-etc/vim/ftplugin; \
	mkdir -p sundry/misc/editor-syntax-etc/vim/rc; \
	mkdir -p sundry/misc/editor-syntax-etc/vim/templates; \
	mkdir -p $(PRG_SRCDIR)/$(PRG_NAME_DIR); \
	mkdir -p $(PRG_BINDIR);

ver:
	echo spine-$(PROG_VER_DECLARED)-tag-$(PROG_VER_GIT)

clean_tangle_build: clean tangle build

tangle_build: tangle build

makefile_new:
	make -k tangle_maker

restart: clean tangle

find_pods:
	$(SiSU_MARKUP_SAMPLES_FIND_PODS)

testrun_find:
	spine -v --source --html --epub --sqlite-discrete \
	--sqlite-create --sqlite-update \
	--output-dir=tmp/program_output_pod \
	data/pod/sisu-manual

testrun_find_pod_source:
	$(SiSU_MARKUP_SAMPLES_PODS_FOUND) \
	spine -v --source \
	--output-dir=tmp/program_output_pod

testrun_find_pod_pod:
	$(SiSU_MARKUP_SAMPLES_PODS_FOUND) \
	spine -v --pod \
	--output-dir=tmp/program_output_pod

testrun_find_pod_html:
	$(SiSU_MARKUP_SAMPLES_PODS_FOUND) \
	spine -v --html \
	--output-dir=tmp/program_output_pod

testrun_find_pod_epub:
	$(SiSU_MARKUP_SAMPLES_PODS_FOUND) \
	spine -v --epub \
	--output-dir=tmp/program_output_pod

testrun_find_pod_all:
	$(SiSU_MARKUP_SAMPLES_PODS_FOUND) \
	spine -v --source --html --epub --sqlite-discrete \
	--sqlite-create --sqlite-update \
	--output-dir=tmp/program_output_pod

testrun_paths:
	spine -v --source --html --epub --sqlite-discrete \
	--sqlite-create --sqlite-update \
	--output-dir=tmp/program_output_pod \
	data/pod/sisu-manual

testrun_paths_pod_source:
	spine -v --source \
	--output-dir=tmp/program_output_pod \
	./markup/pod/*

testrun_paths_pod_pod:
	spine -v --pod \
	--output-dir=tmp/program_output_pod \
	./markup/pod/*

testrun_paths_pod_html:
	spine -v --html \
	--output-dir=tmp/program_output_pod \
	./markup/pod/*

testrun_paths_pod_epub:
	spine -v --epub \
	--output-dir=tmp/program_output_pod \
	./markup/pod/*

testrun_paths_pod_all:
	spine -v --source --html --epub --sqlite-discrete \
	--sqlite-create --sqlite-update \
	--output-dir=tmp/program_output_pod \
	./markup/pod/*

testrun_find_dir_source:
	$(SiSU_MARKUP_SAMPLES_DIR_FILES_FOUND) \
	spine -v --source \
	--output-dir=tmp/program_output_dir

testrun_find_dir_pod:
	$(SiSU_MARKUP_SAMPLES_DIR_FILES_FOUND) \
	spine -v --pod \
	--output-dir=tmp/program_output_dir

testrun_find_dir_html:
	$(SiSU_MARKUP_SAMPLES_DIR_FILES_FOUND) \
	spine -v --html \
	--output-dir=tmp/program_output_dir

testrun_find_dir_epub:
	$(SiSU_MARKUP_SAMPLES_DIR_FILES_FOUND) \
	spine -v --epub \
	--output-dir=tmp/program_output_dir

testrun_find_dir_all:
	$(SiSU_MARKUP_SAMPLES_DIR_FILES_FOUND) \
	spine -v --source --html --epub --sqlite-discrete \
	--sqlite-create --sqlite-update \
	--output-dir=tmp/program_output_dir

testrun_filelist_dir_source:
	spine -v --source \
	--output-dir=tmp/program_output_dir \
	$(SiSU_MARKUP_SAMPLES_DIR)

testrun_filelist_dir_pod:
	spine -v --pod \
	--output-dir=tmp/program_output_dir \
	$(SiSU_MARKUP_SAMPLES_DIR)

testrun_filelist_dir_html:
	spine -v --html \
	--output-dir=tmp/program_output_dir \
	$(SiSU_MARKUP_SAMPLES_DIR)

testrun_filelist_dir_epub:
	spine -v --epub \
	--output-dir=tmp/program_output_dir \
	$(SiSU_MARKUP_SAMPLES_DIR)

testrun_filelist_dir_all:
	spine -v --source --html --epub --sqlite-discrete \
	--sqlite-create --sqlite-update \
	--output-dir=tmp/program_output_dir \
	$(SiSU_MARKUP_SAMPLES_DIR)

tangle: skel
	for f in $(ORGFILELIST); do \
		ORGFILES="$$ORGFILES \"$$f\""; \
	done; \
	emacs --batch -Q -q \
	--eval "(progn \
		(add-to-list 'load-path \
			(expand-file-name \"$(EMACSLISP)\")) \
		(add-to-list 'load-path \
			(expand-file-name \"$(EMACSLISP_ORG)\" t)) \
		(add-to-list 'load-path \
			(expand-file-name \"$(EMACSLISP_ORG_CONTRIB)\" t)) \
		(require 'org)(require 'ob)(require 'ob-tangle) \
		(mapc (lambda (file) \
			(find-file (expand-file-name file \"$(ORGDIR)\")) \
				(setq-local org-src-preserve-indentation t) \
			(org-babel-tangle) \
			(kill-buffer)) '($$ORGFILES)))" 2>&1

tangle_maker:
	for f in $(ORGFILELIST); do \
		ORGFILES="\"org/dr_build_scaffold.org\""; \
	done; \
	emacs --batch -Q -q \
	--eval "(progn \
		(add-to-list 'load-path \
			(expand-file-name \"$(EMACSLISP)\")) \
		(add-to-list 'load-path \
			(expand-file-name \"$(EMACSLISP_ORG)\" t)) \
		(add-to-list 'load-path \
			(expand-file-name \"$(EMACSLISP_ORG_CONTRIB)\" t)) \
		(require 'org)(require 'ob)(require 'ob-tangle) \
		(mapc (lambda (file) \
			(find-file (expand-file-name file \".\")) \
				(setq-local org-src-preserve-indentation t) \
			(org-babel-tangle) \
			(kill-buffer)) '($$ORGFILES)))" 2>&1

# nix-shell
nix-shell:
	nix-shell -I .envrc

nix-shell-pure:
	nix-shell -I .envrc --pure

# nix-shell (with local tools, presumably latest dlang compiler & build tools (ldc & dub))
nix-shell-updated:
	nix-shell -I nixpkgs=/srv/nix/nixpkgs --pure

# shell.nix (with shebang)
shell:
	shell.nix

# nix-build spine
nix-build:
	nix-build default.nix && ./result/bin/spine -v

# nix-build spine (with local tools, presumably latest dlang compiler & build tools (ldc & dub))
nix-build-use-tools-new:
	nix-build -I .envrc

# tangle-build
tangle-build: org-tangle nix-build

# build-run
build-run: nix-build output-samples

# tangle-build-run
tangle-build-run: org-tangle nix-build output-samples

# nix-build spine search
nix-build-search:
	cd ./sundry/spine_search_cgi; \
	nix-build \
	cd -

_flake-lock-reset:
	git reset HEAD flake.lock

_flake-show-name:
	nix search --json 2>/dev/null |jq;

_flake-show-package:
	nix flake show;

_flake-show-derivation:
	nix show-derivation |jq;

nix-develop:
	nix develop -f default.nix -I nixpkgs=/srv/nix/nixpkgs

# nix flake show
flake-show: _flake-show-package _flake-show-name _flake-show-derivation

# nix-build flake spine
flake-build: _flake-show-name
	nix build --print-build-logs

# nix-build flake spine
flake-reset-build: _flake-lock-reset _flake-show-name
	nix build --print-build-logs

# nix-build spine (with local tools, presumably latest dlang compiler & build tools (ldc & dub))
flake-build-use-tools-new:
	nix build --print-build-logs -I nixpkgs=/srv/nix/nixpkgs

# tangle-build-flake
flake-tangle-build: org-tangle flake-build

# build-flake-run
flake-build-run: flake-build output-samples

# tangle-build-run
flake-tangle-build-run: org-tangle flake-build output-samples

# nix-build spine search
flake-build-search:
	cd ./sundry/spine_search_cgi; \
	nix build --print-build-logs \
	cd -

gitsnapshot: distclean tangle
	git commit -a

# markup_dir_samples:
#   find data/sisudir/media/text -name *.ss[tm] | sort

version_tag:
	echo "DRV=0.16.0; git tag -f doc-reform-markup-samples_v$$\{DRV} -m\"doc-reform markup-samples spine-$$\{DRV}\" HEAD"; \
	echo "git tag -f doc-reform-markup-samples_v0.16.0 -m\"doc-reform markup-samples spine-0.16.0\" HEAD";

.PHONY : all build release \
	distclean init \
	tangle gitsnapshot