forked from jonaseberle/autoortho-scenery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.tiles
185 lines (154 loc) · 5.53 KB
/
Makefile.tiles
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
# Requires Github CLI (gh) command to facilitate authenticated requests to the API
#
# Quick start:
# make -f Makefile.tiles clean
# make -f Makefile.tiles test_tile_list_chunks
# make -f Makefile.tiles -j $(nproc --ignore=2)
# @todo: make release in kubilus/autoortho-scenery, see ./bin/prepareAssetsElevationData
ELEV_RELEASE_JSON_ENDPOINT?=repos/jonaseberle/autoortho-scenery/releases/tags/elevation-v0.0.1
SPLITSIZE?=125
SHELL=/bin/bash
ZL?=16
TILENAME?=test
TILES:=$(addprefix z_$(TILENAME)_, $(shell ls $(TILENAME)_tile_list.* 2>/dev/null | awk -F. '{ print $$2 }') )
TILE_ZIPS=$(addsuffix .zip, $(TILES))
ZIPS=$(TILE_ZIPS)
# paranthesis to use in shell commands
# make chokes on () in shell commands
OP:=(
CP:=)
# Get the tiles listed in each list file
.SECONDEXPANSION:
TILE_FILES = $(addsuffix .dsf, $(addprefix Ortho4XP/Tiles/*/*/*/, $(basename $(shell cat $(TILENAME)_tile_list.$* 2>/dev/null ) ) ) )
all: $(ZIPS)
# creates directories
%/:
@mkdir -p $@
#
# Work on tile lists
#
z_$(TILENAME)_%: $(TILENAME)_tile_list.% $${TILE_FILES}
@echo "[$@]"
z_$(TILENAME)_%.zip.info: z_$(TILENAME)_%.zip
@echo "[$@]"
@echo "-----------------------------------"
@echo "Post processing info:"
@comm --total -3 <( unzip -l $(basename $@) *.dsf | awk -F/ '/.*\.dsf/ { print $$4 }' | sort ) <( cat $(TILENAME)_tile_list.$* | sort )
@echo "-----------------------------------"
@export EXPECTED=$$(cat $(TILENAME)_tile_list.$* | wc -l); \
export ACTUAL=$$(unzip -l $(basename $@) *.dsf | grep dsf | wc -l); \
echo "Expected tile len: $$EXPECTED"; \
echo "Actual tile len: $$ACTUAL"; \
[ $$EXPECTED -eq $$ACTUAL ]
#
# Ortho4XP setup
#
ortho4xp.diff:
@echo "[$@]"
cd Ortho4XP && git diff > ../ortho4xp.diff
Ortho4XP:
@echo "[$@]"
git clone --depth=1 https://github.com/oscarpilote/Ortho4XP.git
cd $@ && patch -p1 -u < ../ortho4xp.diff
cp extract_overlay.py $@/.
cp Ortho4XP.cfg $@/.
mkdir $@/tmp
@echo "Setting up symlinks in order to not care about Ortho4XP's expected directory structure in ./Elevation_data..."
mkdir -p $@/Elevation_data && cd $@/Elevation_data \
&& bash -c 'for lat in {-9..9}; do for lon in {-18..18}; do ln -snfr ./ "./$$(printf "%+d0%+03d0" "$$lat" "$$lon")"; done; done'
#
# Custom tile elevation
#
# generates the targets var/run/neighboursOfTile_%.elevation with surrounding tiles' elevations
# as prerequisites (takes a little while, 360*180 rules):
var/run/Makefile.elevationRules: | $$(@D)/
@echo "[$@]"
@bin/genMakefileElevationRules > $@
include var/run/Makefile.elevationRules
var/run/tile_%.elevation: var/cache/elevation/elevation_%.zip Ortho4XP | $$(@D)/
@# Unzips if file not empty, but fails on unzip error.
@# Ignores the .zip if empty
@if [ -s "var/cache/elevation/elevation_$*.zip" ]; then \
printf "[$@] unzipping custom elevation: %s\n" \
"$$(unzip -o -d Ortho4XP/Elevation_data/ var/cache/elevation/elevation_$*.zip | tr "\n" " | ")"; \
else \
echo "[$@] no custom elevation for this tile"; \
fi
@touch $@
var/run/elevationRelease.json: | $$(@D)/
@echo "[$@]"
@json=$$(gh api $(ELEV_RELEASE_JSON_ENDPOINT) --paginate) \
&& echo "$$json" > $@ \
&& printf "[$@] got %s\n" "$$(jq -r '.assets[].name' $@ | tr --delete "elevation_" | tr --delete ".zip" | tr "\n" ",")"
var/cache/elevation/elevation_%.zip: var/run/elevationRelease.json | $$(@D)/
@# Fails if we expect a file but download failed.
@# Creates an empty .zip file if there is no custom elevation.
@url=$$(jq -r '.assets[] | select$(OP).name == "elevation_$*.zip"$(CP) .browser_download_url' \
var/run/elevationRelease.json); \
if [ -n "$$url" ]; then \
echo "[$@] downloading custom elevation"; \
wget --continue --quiet -O $@ "$$url" && touch $@; \
else \
echo "[$@] no custom elevation for this tile"; \
touch $@; \
fi
#
# Split tile list
#
#$(TILENAME)_tile_list.%: $(TILENAME)_tile_list_chunks
$(TILENAME)_tile_list_chunks: $(TILENAME)_tile_list
@echo "[$@]"
split $< -d -l $(SPLITSIZE) $<.
#
# Tile pack setup
#
Ortho4XP/Tiles/*/*/*/%.dsf: Ortho4XP var/run/neighboursOfTile_%.elevation
@echo [$@]
@echo "Make tile $*"
@echo "Setup per tile config, if possible"
@mkdir -p Ortho4XP/Tiles/zOrtho4XP_$*
@cp Ortho4XP_$*.cfg Ortho4XP/Tiles/zOrtho4XP_$*/. 2>/dev/null || true
@echo "Make tile $(@)"
# this silences deprecation warnings in Ortho4XP for more concise output
@set -e;\
export COORDS=$$(echo $(@) | sed -e 's/.*\/\([-+][0-9]\+\)\([-+][0-9]\+\).dsf/\1 \2/g');\
echo $$COORDS; \
cd Ortho4XP \
&& python3 Ortho4XP_v130.py $$COORDS BI $(ZL) 2>&1 | grep -v 'is deprecated' \
|| ( \
echo "ERROR DETECTED! Retry tile $@ with noroads config."; \
cp $(CURDIR)/Ortho4XP_noroads.cfg $(CURDIR)/Ortho4XP/Tiles/zOrtho4XP_$*/Ortho4XP_$*.cfg \
&& python3 Ortho4XP_v130.py $$COORDS BI $(ZL) 2>&1 | grep -v 'is deprecated' \
);
var/run/z_aosingle_%: Ortho4XP/Tiles/*/*/*/%.dsf
@echo "[$@]"
@cp -r Ortho4XP/Tiles/zOrtho4XP_$*/ var/run/z_aosingle_$*
z_aosingle_%.zip: var/run/z_aosingle_%
@echo "[$@]"
@cd var/run/ && zip -r ../../$@ z_aosingle_$*/
.SECONDARY: $(TILE_FILES)
# Static pattern rule for the zip files
$(ZIPS): z_%.zip: z_%
@echo "[$@]"
@mkdir -p $<
@cp -r Ortho4XP/Tiles/zOrtho4XP_*/'Earth nav data' $</.
@cp -r Ortho4XP/Tiles/zOrtho4XP_*/terrain $</.
@cp -r Ortho4XP/Tiles/zOrtho4XP_*/textures $</.
@zip -r $@ $<
%.sha256: %
@echo "[$@]"
sha256sum $< > $@
clean:
@echo "[$@]"
-rm -rf Ortho4XP/Tiles/*
-rm -rf var/run
-rm -f $(ZIPS)
-rm -rf z_$(TILENAME)*
-rm -rf z_aosingle_*
-rm -f $(TILENAME)_tile_list.*
distclean: clean
@echo "[$@]"
-rm -rf Ortho4XP
-rm -rf var
-rm -f z_*
-rm -f *_tile_list.*