2022-10-27 10:45:25 +00:00
|
|
|
#!/usr/bin/make -f
|
|
|
|
|
|
|
|
VERSION ?= "$(shell git describe --tags --match "v*" --dirty --always --abbrev=8 2>/dev/null || cat VERSION 2>/dev/null || echo "develop")"
|
2024-07-08 08:28:19 +00:00
|
|
|
FROST_LOCODE = ./frostfs-locode-db
|
2022-10-27 10:45:25 +00:00
|
|
|
|
2023-04-21 14:20:01 +00:00
|
|
|
.PHONY: all clean version help update debpackage
|
2022-10-27 10:45:25 +00:00
|
|
|
|
|
|
|
DIRS = in tmp
|
|
|
|
|
2023-04-21 14:20:01 +00:00
|
|
|
# IGNORE
|
2022-10-27 10:45:25 +00:00
|
|
|
space := $(subst ,, )
|
|
|
|
|
2022-10-27 13:50:54 +00:00
|
|
|
# .deb package versioning
|
|
|
|
OS_RELEASE = $(shell lsb_release -cs)
|
|
|
|
PKG_VERSION ?= $(shell echo $(VERSION) | sed "s/^v//" | \
|
2022-10-27 19:54:31 +00:00
|
|
|
sed -E "s/(.*)-(g[a-fA-F0-9]{6,8})(.*)/\1\3~\2/" | \
|
|
|
|
sed "s/-/~/")-${OS_RELEASE}
|
2022-10-27 13:50:54 +00:00
|
|
|
|
2023-04-21 14:20:01 +00:00
|
|
|
# Generate locode_db BoltDB file
|
2024-07-08 08:28:19 +00:00
|
|
|
all: $(DIRS) $(FROST_LOCODE) locode_db
|
|
|
|
|
|
|
|
$(FROST_LOCODE):
|
|
|
|
go build .
|
2022-10-27 10:45:25 +00:00
|
|
|
|
|
|
|
$(DIRS):
|
2022-10-27 19:54:31 +00:00
|
|
|
@echo "⇒ Ensure dir: $@"
|
|
|
|
@mkdir -p $@
|
2022-10-27 10:45:25 +00:00
|
|
|
|
2023-04-21 08:42:42 +00:00
|
|
|
in/airports.dat: $(DIRS)
|
2023-04-21 14:20:01 +00:00
|
|
|
zcat data/airports.dat.gz > in/airports.dat
|
2022-10-27 10:45:25 +00:00
|
|
|
|
2023-04-21 08:42:42 +00:00
|
|
|
in/countries.dat: $(DIRS)
|
2023-04-21 14:20:01 +00:00
|
|
|
zcat data/countries.dat.gz > in/countries.dat
|
2022-10-27 10:45:25 +00:00
|
|
|
|
|
|
|
in/continents.geojson: $(DIRS)
|
2023-04-21 14:20:01 +00:00
|
|
|
zcat data/continents.geojson.gz > in/continents.geojson
|
2022-10-27 10:45:25 +00:00
|
|
|
|
2023-04-21 14:20:01 +00:00
|
|
|
in/unlocode-SubdivisionCodes.csv: $(DIRS)
|
|
|
|
zcat data/unlocode-SubdivisionCodes.csv.gz > in/unlocode-SubdivisionCodes.csv
|
2022-10-27 10:45:25 +00:00
|
|
|
|
2023-04-21 14:20:01 +00:00
|
|
|
in/unlocode-CodeList.csv: $(DIRS)
|
|
|
|
zcat data/unlocode-CodeList.csv.gz > in/unlocode-CodeList.csv
|
|
|
|
|
|
|
|
# Generate locode_db BoltDB file
|
2024-07-08 08:28:19 +00:00
|
|
|
locode_db: in/unlocode-CodeList.csv in/unlocode-SubdivisionCodes.csv in/continents.geojson in/airports.dat in/countries.dat $(FROST_LOCODE)
|
|
|
|
$(FROST_LOCODE) generate \
|
2022-10-27 10:45:25 +00:00
|
|
|
--airports in/airports.dat \
|
|
|
|
--continents in/continents.geojson \
|
|
|
|
--countries in/countries.dat \
|
2023-04-21 14:20:01 +00:00
|
|
|
--in in/unlocode-CodeList.csv \
|
|
|
|
--subdiv in/unlocode-SubdivisionCodes.csv \
|
2022-10-27 10:45:25 +00:00
|
|
|
--out locode_db
|
2022-10-27 19:54:31 +00:00
|
|
|
chmod 644 locode_db
|
2022-10-27 10:45:25 +00:00
|
|
|
|
2023-04-21 14:20:01 +00:00
|
|
|
# IGNORE
|
|
|
|
# Openflights doesn't have tags or releases, so update would always take latest master version.
|
|
|
|
# See https://github.com/jpatokal/openflights
|
|
|
|
data/airports.dat.gz: $(DIRS)
|
|
|
|
wget -c https://raw.githubusercontent.com/jpatokal/openflights/master/data/airports.dat -O tmp/airports.dat && \
|
|
|
|
gzip -c tmp/airports.dat > data/airports.dat.gz
|
|
|
|
|
|
|
|
data/countries.dat.gz: $(DIRS)
|
|
|
|
wget -c https://raw.githubusercontent.com/jpatokal/openflights/master/data/countries.dat -O tmp/countries.dat && \
|
|
|
|
gzip -c tmp/countries.dat > data/countries.dat.gz
|
|
|
|
|
|
|
|
# IGNORE
|
|
|
|
# See https://unece.org/trade/cefact/UNLOCODE-Download
|
|
|
|
tmp/locode.csv.zip :$(DIRS)
|
2024-07-03 13:39:00 +00:00
|
|
|
DOWNLOADURL=$$(wget -O - https://unece.org/trade/cefact/UNLOCODE-Download \
|
|
|
|
| grep -oP '(?<=href=")\S+loc\d+csv\.zip'); \
|
|
|
|
echo "$$DOWNLOADURL" | grep -oP '(?<=loc)\d+' > tmp/locode-version.txt; \
|
|
|
|
wget -c "$$DOWNLOADURL" -O tmp/locode.csv.zip
|
2023-04-21 14:20:01 +00:00
|
|
|
|
|
|
|
data/unlocode-SubdivisionCodes.csv.gz: tmp/locode.csv.zip
|
|
|
|
unzip -p tmp/locode.csv.zip "*SubdivisionCodes.csv" | gzip > data/unlocode-SubdivisionCodes.csv.gz
|
|
|
|
|
|
|
|
data/unlocode-CodeList.csv.gz: tmp/locode.csv.zip
|
|
|
|
unzip -p tmp/locode.csv.zip "*CodeListPart*" | gzip > data/unlocode-CodeList.csv.gz
|
|
|
|
|
|
|
|
# Download and repack external data-sources
|
|
|
|
update: data/unlocode-CodeList.csv.gz data/unlocode-SubdivisionCodes.csv.gz data/countries.dat.gz data/airports.dat.gz
|
|
|
|
|
2022-10-27 10:45:25 +00:00
|
|
|
# Print version
|
|
|
|
version:
|
|
|
|
@echo $(VERSION)
|
|
|
|
|
|
|
|
# Show this help prompt
|
|
|
|
help:
|
|
|
|
@echo ' Usage:'
|
|
|
|
@echo ''
|
|
|
|
@echo ' make <target>'
|
|
|
|
@echo ''
|
|
|
|
@echo ' Targets:'
|
|
|
|
@echo ''
|
|
|
|
@awk '/^#/{ comment = substr($$0,3) } comment && /^[a-zA-Z][a-zA-Z0-9_-]+ ?:/{ print " ", $$1, comment }' $(MAKEFILE_LIST) | column -t -s ':' | grep -v 'IGNORE' | sort -u
|
|
|
|
|
2024-07-08 08:28:19 +00:00
|
|
|
# Run tests
|
|
|
|
test: locode_db
|
|
|
|
test -n "$$($(FROST_LOCODE) info --db locode_db --locode "US NYC" 2>&1 | grep "New York")"
|
|
|
|
test -n "$$($(FROST_LOCODE) info --db locode_db --locode "RU LED" 2>&1 | grep "Leningrad")"
|
|
|
|
test -n "$$($(FROST_LOCODE) info --db locode_db --locode "RU KUF" 2>&1 | grep "Samara")"
|
|
|
|
test -n "$$($(FROST_LOCODE) info --db locode_db --locode "VN DAN" 2>&1 | grep "Binh Hoa")"
|
|
|
|
test -n "$$($(FROST_LOCODE) info --db locode_db --locode "FR PAR" 2>&1 | grep "Paris")"
|
2023-04-21 14:20:01 +00:00
|
|
|
|
|
|
|
# Clean data directory before update
|
|
|
|
clean_data:
|
|
|
|
rm -f data/unlocode-CodeList.csv.gz
|
|
|
|
rm -f data/unlocode-SubdivisionCodes.csv.gz
|
|
|
|
rm -f data/countries.dat.gz
|
|
|
|
rm -f data/airports.dat.gz
|
|
|
|
|
2022-10-27 10:45:25 +00:00
|
|
|
# Clean up
|
|
|
|
clean:
|
|
|
|
rm -f in/*
|
|
|
|
rm -f tmp/*
|
|
|
|
rm -f locode_db
|
2024-07-08 08:28:19 +00:00
|
|
|
rm -f $(FROST_LOCODE)
|
2022-10-27 13:50:54 +00:00
|
|
|
|
|
|
|
# Package for Debian
|
|
|
|
debpackage:
|
2022-12-22 13:28:24 +00:00
|
|
|
dch --package frostfs-locode-db \
|
2022-10-27 19:54:31 +00:00
|
|
|
--controlmaint \
|
|
|
|
--newversion $(PKG_VERSION) \
|
|
|
|
--force-bad-version \
|
|
|
|
--distribution $(OS_RELEASE) \
|
|
|
|
"Please see CHANGELOG.md for code changes for $(VERSION)"
|
2022-10-27 13:50:54 +00:00
|
|
|
dpkg-buildpackage --no-sign -b
|
|
|
|
|
2023-04-21 14:20:01 +00:00
|
|
|
# Clean up debian packaging leftovers
|
2022-10-27 13:50:54 +00:00
|
|
|
debclean:
|
2022-10-27 19:54:31 +00:00
|
|
|
dh clean
|