stud

study spacejunk
Log | Files | Refs | LICENSE

blob 42e70f54 (11704B) - Raw


      1 OSM ?= lithuania-latest.osm.pbf
      2 RIVERFILTER = Visinčia|Šalčia|Nemunas
      3 SLIDES = slides-2021-03-29.pdf
      4 
      5 GDB10LT ?= $(wildcard GDB10LT-static-*.zip)
      6 
      7 # Max figure size (in meters) is when it's width is TEXTWIDTH_CM on scale 1:25k
      8 SCALEDWIDTH = $(shell awk '/^TEXTWIDTH_CM/{print 25000/100*$$3}' layer2img.py)
      9 
     10 ##############################################################################
     11 # These variables have to come before first use due to how macros are expanded
     12 ##############################################################################
     13 
     14 NON_ARCHIVABLES = notes.txt referatui.txt slides-2021-03-29.txt
     15 ARCHIVABLES = $(filter-out $(NON_ARCHIVABLES),$(shell git ls-files .))
     16 
     17 LISTINGS = aggregate-rivers.sql wm.sql extract-and-generate
     18 
     19 FIGURES = \
     20 		  test-figures \
     21 		  fig8-definition-of-a-bend \
     22 		  fig8-elimination-gen1 \
     23 		  fig8-elimination-gen2 \
     24 		  fig8-elimination-gen3 \
     25 		  fig5-gentle-inflection-before \
     26 		  fig5-gentle-inflection-after \
     27 		  inflection-1-gentle-inflection-before \
     28 		  inflection-1-gentle-inflection-after \
     29 		  fig6-selfcrossing \
     30 		  selfcrossing-1 \
     31 		  isolated-1-exaggerated
     32 
     33 RIVERS = \
     34 		 salvis-25k \
     35 		 salvis-50k \
     36 		 salvis-250k \
     37 		 salvis-douglas-64-50k \
     38 		 salvis-visvalingam-64-50k \
     39 		 salvis-douglas-64-chaikin-50k \
     40 		 salvis-visvalingam-64-chaikin-50k \
     41 		 salvis-overlaid-douglas-64-chaikin-50k \
     42 		 salvis-overlaid-visvalingam-64-chaikin-50k
     43 
     44 #################################
     45 # The thesis, publishable version
     46 #################################
     47 
     48 mj-msc-full.pdf: mj-msc.pdf version.inc.tex $(ARCHIVABLES) ## Thesis for publishing
     49 	cp $< .tmp-$@
     50 	for f in $^; do \
     51 		if [ "$$f" = "$<" ]; then continue; fi; \
     52 		pdfattach .tmp-$@ $$f .tmp2-$@; \
     53 		mv .tmp2-$@ .tmp-$@; \
     54 	done
     55 	mv .tmp-$@ $@
     56 
     57 ###############################
     58 # Auxiliary targets for humans
     59 ###############################
     60 
     61 .PHONY: test
     62 test: .faux_test ## Unit tests (fast)
     63 
     64 .PHONY: visuals
     65 visuals: .faux_visuals  # Generate visuals for paper (fast)
     66 
     67 .PHONY: test-rivers
     68 test-rivers: .faux_test-rivers ## Rivers tests (slow)
     69 
     70 .PHONY: slides
     71 slides: $(SLIDES)
     72 
     73 ###########################
     74 # The report, quick version
     75 ###########################
     76 
     77 mj-msc.pdf: mj-msc.tex version.inc.tex vars.inc.tex bib.bib \
     78 	$(LISTINGS) $(addsuffix .pdf,$(FIGURES)) $(addsuffix .pdf,$(RIVERS))
     79 	latexmk -shell-escape -pdf $<
     80 
     81 ############################
     82 # Report's test dependencies
     83 ############################
     84 
     85 define FIG_template
     86 $(1).pdf: layer2img.py Makefile $(2)
     87 	python3 ./layer2img.py --outfile=$(1).pdf \
     88 		$$(if $$($(1)_WIDTHDIV),--widthdiv=$$($(1)_WIDTHDIV)) \
     89 		$$(if $$($(1)_QUADRANT),--quadrant=$$($(1)_QUADRANT)) \
     90 		$$(foreach i,1 2 3, \
     91 			$$(if $$($(1)_$$(i)COLOR),--group$$(i)-color="$$($(1)_$$(i)COLOR)") \
     92 			$$(if $$($(1)_$$(i)SELECT),--group$$(i)-select="$$($(1)_$$(i)SELECT)") \
     93 			$$(if $$($(1)_$$(i)LINESTYLE),--group$$(i)-linestyle="$$($(1)_$$(i)LINESTYLE)") \
     94 	)
     95 endef
     96 $(foreach fig,$(FIGURES),$(eval $(call FIG_template,$(fig),.faux_visuals)))
     97 $(foreach fig,$(RIVERS), $(eval $(call FIG_template,$(fig),.faux_visuals)))
     98 
     99 test-figures_1SELECT = wm_figures
    100 
    101 fig8-definition-of-a-bend_1SELECT = wm_debug where name='fig8' AND stage='afigures' AND gen=1
    102 fig8-definition-of-a-bend_2SELECT = wm_debug where name='fig8' AND stage='bbends-polygon' AND gen=1
    103 fig8-definition-of-a-bend_3SELECT = wm_debug where name='fig8' AND stage='bbends-polygon' AND gen=1
    104 fig8-definition-of-a-bend_3LINESTYLE = dotted
    105 
    106 fig8-elimination-gen1_1SELECT = wm_debug where name='fig8' AND stage='afigures' AND gen=1
    107 fig8-elimination-gen1_2SELECT = wm_debug where name='fig8' AND stage='bbends-polygon' AND gen=1
    108 fig8-elimination-gen1_3SELECT = wm_debug where name='fig8' AND stage='bbends-polygon' AND gen=1
    109 fig8-elimination-gen1_3LINESTYLE = dotted
    110 
    111 fig8-elimination-gen2_1SELECT = wm_debug where name='fig8' AND stage='afigures' AND gen=2
    112 fig8-elimination-gen2_2SELECT = wm_debug where name='fig8' AND stage='bbends-polygon' AND gen=2
    113 fig8-elimination-gen2_3SELECT = wm_debug where name='fig8' AND stage='bbends-polygon' AND gen=2
    114 fig8-elimination-gen2_3LINESTYLE = dotted
    115 fig8-elimination-gen3_1SELECT = wm_debug where name='fig8' AND stage='bbends' AND gen=3
    116 fig8-elimination-gen3_2SELECT = wm_debug where name='fig8' AND stage='bbends-polygon' AND gen=3
    117 fig8-elimination-gen3_3SELECT = wm_debug where name='fig8' AND stage='bbends-polygon' AND gen=3
    118 fig8-elimination-gen3_3LINESTYLE = dotted
    119 
    120 fig5-gentle-inflection-before_WITHDIV = 2
    121 fig5-gentle-inflection-before_1SELECT = wm_debug where name='fig5' AND stage='afigures' AND gen=1
    122 fig5-gentle-inflection-before_2SELECT = wm_debug where name='fig5' AND stage='bbends-polygon' AND gen=1
    123 fig5-gentle-inflection-before_3SELECT = wm_debug where name='fig5' AND stage='bbends-polygon' AND gen=1
    124 fig5-gentle-inflection-before_3LINESTYLE = dotted
    125 fig5-gentle-inflection-after_WITHDIV = 2
    126 fig5-gentle-inflection-after_1SELECT = wm_debug where name='fig5' AND stage='cinflections' AND gen=1
    127 fig5-gentle-inflection-after_2SELECT = wm_debug where name='fig5' AND stage='cinflections-polygon' AND gen=1
    128 fig5-gentle-inflection-after_3SELECT = wm_debug where name='fig5' AND stage='cinflections-polygon' AND gen=1
    129 fig5-gentle-inflection-after_3LINESTYLE = dotted
    130 
    131 inflection-1-gentle-inflection-before_WIDTHDIV = 2
    132 inflection-1-gentle-inflection-before_1SELECT = wm_debug where name='inflection-1' AND stage='afigures' AND gen=1
    133 inflection-1-gentle-inflection-before_2SELECT = wm_debug where name='inflection-1' AND stage='bbends-polygon' AND gen=1
    134 inflection-1-gentle-inflection-before_3SELECT = wm_debug where name='inflection-1' AND stage='bbends-polygon' AND gen=1
    135 inflection-1-gentle-inflection-before_3LINESTYLE = dotted
    136 inflection-1-gentle-inflection-after_WIDTHDIV = 2
    137 inflection-1-gentle-inflection-after_1SELECT = wm_debug where name='inflection-1' AND stage='cinflections' AND gen=1
    138 inflection-1-gentle-inflection-after_2SELECT = wm_debug where name='inflection-1' AND stage='cinflections-polygon' AND gen=1
    139 inflection-1-gentle-inflection-after_3SELECT = wm_debug where name='inflection-1' AND stage='cinflections-polygon' AND gen=1
    140 inflection-1-gentle-inflection-after_3LINESTYLE = dotted
    141 
    142 fig6-selfcrossing_WIDTHDIV = 2
    143 fig6-selfcrossing_1SELECT = wm_debug where name='fig6' AND stage='afigures' AND gen=1
    144 fig6-selfcrossing_1LINESTYLE = dotted
    145 fig6-selfcrossing_2SELECT = wm_debug where name='fig6' AND stage='dcrossings' AND gen=1
    146 fig6-selfcrossing_3SELECT = wm_visuals where name='fig6-baseline'
    147 fig6-selfcrossing_3COLOR = orange
    148 
    149 selfcrossing-1_WIDTHDIV = 2
    150 selfcrossing-1_1SELECT = wm_debug where name='selfcrossing-1' AND stage='afigures' AND gen=1
    151 selfcrossing-1_1LINESTYLE = dotted
    152 selfcrossing-1_2SELECT = wm_debug where name='selfcrossing-1' AND stage='dcrossings' AND gen=1
    153 selfcrossing-1_3SELECT = wm_visuals where name='selfcrossing-1-baseline'
    154 selfcrossing-1_3COLOR = orange
    155 
    156 isolated-1-exaggerated_WIDTHDIV = 2
    157 isolated-1-exaggerated_1SELECT = wm_debug where name='isolated-1' AND stage='afigures' AND gen=1
    158 isolated-1-exaggerated_1LINESTYLE = dotted
    159 isolated-1-exaggerated_2SELECT = wm_debug where name='isolated-1' AND stage='afigures' AND gen=2
    160 
    161 salvis-25k_1SELECT = wm_visuals where name='salvis'
    162 salvis-25k_WIDTHDIV = 1
    163 
    164 salvis-50k_1SELECT = wm_visuals where name='salvis'
    165 salvis-50k_WIDTHDIV = 2
    166 
    167 salvis-250k_1SELECT = wm_visuals where name='salvis'
    168 salvis-250k_WIDTHDIV = 10
    169 
    170 #salvis-douglas-64-50k_1SELECT = wm_visuals where name='salvis'
    171 salvis-douglas-64-50k_2SELECT = wm_visuals where name='salvis-douglas-64'
    172 salvis-douglas-64-50k_WIDTHDIV = 2
    173 
    174 salvis-visvalingam-64-50k_2SELECT = wm_visuals where name='salvis-visvalingam-64'
    175 salvis-visvalingam-64-50k_WIDTHDIV = 2
    176 
    177 salvis-douglas-64-chaikin-50k_2SELECT = wm_visuals where name='salvis-douglas-64-chaikin'
    178 salvis-douglas-64-chaikin-50k_WIDTHDIV = 2
    179 
    180 salvis-visvalingam-64-chaikin-50k_2SELECT = wm_visuals where name='salvis-visvalingam-64-chaikin'
    181 salvis-visvalingam-64-chaikin-50k_WIDTHDIV = 2
    182 
    183 salvis-overlaid-douglas-64-chaikin-50k_1SELECT = wm_visuals where name='salvis'
    184 salvis-overlaid-douglas-64-chaikin-50k_2SELECT = wm_visuals where name='salvis-douglas-64-chaikin'
    185 salvis-overlaid-douglas-64-chaikin-50k_1COLOR = orange
    186 salvis-overlaid-douglas-64-chaikin-50k_WIDTHDIV = 2
    187 salvis-overlaid-douglas-64-chaikin-50k_QUADRANT = 1
    188 
    189 salvis-overlaid-visvalingam-64-chaikin-50k_1SELECT = wm_visuals where name='salvis'
    190 salvis-overlaid-visvalingam-64-chaikin-50k_2SELECT = wm_visuals where name='salvis-visvalingam-64-chaikin'
    191 salvis-overlaid-visvalingam-64-chaikin-50k_1COLOR = orange
    192 salvis-overlaid-visvalingam-64-chaikin-50k_WIDTHDIV = 2
    193 salvis-overlaid-visvalingam-64-chaikin-50k_QUADRANT = 1
    194 
    195 
    196 .faux_db: db init.sql rivers.sql
    197 	bash db start
    198 	bash db -f init.sql -f rivers.sql
    199 	touch $@
    200 
    201 .faux_test: test.sql wm.sql .faux_db
    202 	bash db -f $<
    203 	touch $@
    204 
    205 .faux_visuals: visuals.sql .faux_test
    206 	bash db -v scaledwidth=$(SCALEDWIDTH) -f $<
    207 	touch $@
    208 
    209 .faux_test-rivers: test-rivers.sql wm.sql Makefile .faux_db
    210 	bash db -f $<
    211 	touch $@
    212 
    213 ################################
    214 # Report's non-test dependencies
    215 ################################
    216 
    217 REF = $(shell git describe --abbrev=12 --always --dirty)
    218 version.inc.tex: Makefile $(shell git rev-parse --git-dir 2>/dev/null)
    219 	TZ=UTC date '+\gdef\VCDescribe{%F (revision $(REF))}%' > $@
    220 
    221 vars.inc.tex: vars.awk wm.sql Makefile
    222 	awk -f $< wm.sql
    223 
    224 ###############
    225 # Misc commands
    226 ###############
    227 
    228 slides-2021-03-29.pdf: slides-2021-03-29.txt
    229 	pandoc -t beamer -i $< -o $@
    230 
    231 dump-debug_wm.sql.xz:
    232 	docker exec -ti wm-mj pg_dump -Uosm osm -t wm_devug | xz -v > $@
    233 
    234 release.zip: mj-msc.tex mj-msc.bbl version.inc.tex vars.inc.tex \
    235 	$(addsuffix .pdf,$(FIGURES)) $(addsuffix .pdf,$(RIVERS)) \
    236 	$(shell git ls-files .)
    237 	-rm $@
    238 	mkdir -p .tmp; touch .tmp/editorial-version
    239 	zip $@ $^
    240 	zip $@ -j .tmp/editorial-version
    241 
    242 mj-msc.bbl: mj-msc.tex bib.bib
    243 	biber mj-msc
    244 
    245 mj-msc-gray.pdf: mj-msc.pdf
    246 	gs \
    247 		-sOutputFile=$@ \
    248 		-sDEVICE=pdfwrite \
    249 		-sColorConversionStrategy=Gray \
    250 		-dProcessColorModel=/DeviceGray \
    251 		-dCompatibilityLevel=1.4 \
    252 		-dNOPAUSE \
    253 		-dBATCH \
    254 		$<
    255 
    256 .PHONY: clean
    257 clean: ## Clean the current working directory
    258 	-bash db stop
    259 	-rm -r .faux_test .faux_aggregate-rivers .faux_test-rivers .faux_visuals \
    260 		.faux_db version.inc.tex vars.inc.tex version.aux version.fdb_latexmk \
    261 		_minted-mj-msc \
    262 		$(shell git ls-files -o mj-msc*) \
    263 		$(addsuffix .pdf,$(FIGURES)) \
    264 		$(addsuffix .pdf,$(RIVERS)) \
    265 		$(SLIDES)
    266 
    267 .PHONY: clean-tables
    268 clean-tables: ## Remove tables created during unit or rivers tests
    269 	bash db -c '\dt wm_*' | awk '/_/{print "drop table "$$3";"}' | bash db -f -
    270 	-rm .faux_db
    271 
    272 .PHONY: help
    273 help: ## Print this help message
    274 	@awk -F':.*?## ' '/^[a-z0-9.-]*: *.*## */{printf "%-18s %s\n",$$1,$$2}' $(MAKEFILE_LIST)
    275 
    276 .PHONY: wc
    277 wc: mj-msc.pdf ## Character and page count
    278 	@pdftotext $< - | \
    279 		awk '/\yReferences\y/{exit}; {print}' | \
    280 		tr -d '[:space:]' | wc -c | \
    281 		awk '{printf("Chars: %d, pages: %.1f\n", $$1, $$1/1500)}'
    282 
    283 $(OSM):
    284 	wget http://download.geofabrik.de/europe/$@
    285 
    286 .PHONY: refresh-rivers
    287 refresh-rivers: aggregate-rivers.sql .faux_db ## Refresh rivers.sql from GDB10LT
    288 	@if [ ! -f "$(GDB10LT)" ]; then \
    289 		echo "ERROR: GDB10LT-static-*.zip not found. Do GDB10LT=<...>"; \
    290 		exit 1; \
    291 	fi
    292 	mkdir -p .tmp/shp; unzip -d .tmp/shp "$(GDB10LT)" 'HIDRO_L.*'
    293 	shp2pgsql -s 3857 -d ".tmp/shp/HIDRO_L.shp" | \
    294 		awk '!/^INSERT/{print}; /^INSERT/&&/$(RIVERFILTER)/{print;next}' | \
    295 		bash ./db
    296 	bash db -f $<
    297 	(\
    298 		echo '-- Generated at $(shell TZ=UTC date +"%FT%TZ") on $(shell whoami)@$(shell hostname -f)'; \
    299 		echo '-- Rivers: $(RIVERFILTER)'; \
    300 		docker exec wm-mj pg_dump --clean -Uosm osm -t wm_rivers | tr -d '\r' \
    301 	) > rivers.sql.tmp
    302 	mv rivers.sql.tmp rivers.sql
    303 	rm -fr .tmp/shp