1MAPSDIR           ?= base/maps
2UFO2MAP            = ./ufo2map$(EXE_EXT)
3MAPSRCS           := $(shell find $(MAPSDIR) -name '*.map' \! -name 'tutorial*' \! -name '*autosave*' \! -name 'test*' | xargs du | sort -bnr | sed -e 's/^[0-9]*//' | tr -d "\t")
4BSPS              := $(MAPSRCS:.map=.bsp)
5NICE              ?= 19
6UFO2MAPFLAGS      ?= -v 4 -nice $(NICE) -quant 4 -soft
7FAST_UFO2MAPFLAGS ?= -v 2 -quant 6 -nice $(NICE)
8ENTS_UFO2MAPFLAGS ?= -v 2 -nice $(NICE) -onlyents
9PYTHONBIN         := $(shell $(PROGRAM_PYTHON) -m urllib2 2>/dev/null && echo $(PROGRAM_PYTHON))
10ifeq ($(PYTHONBIN),)
11        PYTHONBIN         := $(shell python2.6 -m urllib2 2>/dev/null && echo python2.6)
12endif
13ifeq ($(PYTHONBIN),)
14        PYTHONBIN         := $(shell python2.7 -m urllib2 2>/dev/null && echo python2.7)
15endif
16ifeq ($(PYTHONBIN),)
17        PYTHONBIN         := $(shell python2 -m urllib2 2>/dev/null && echo python2)
18endif
19ifeq ($(PYTHONBIN),)
20        PYTHONBIN         := python
21endif
22
23maps: ufo2map $(BSPS)
24
25maps-fast:
26	$(MAKE) maps UFO2MAPFLAGS="$(FAST_UFO2MAPFLAGS)"
27
28maps-ents:
29	$(MAKE) maps UFO2MAPFLAGS="$(ENTS_UFO2MAPFLAGS)"
30
31# TODO only sync if there were updates on the map files
32maps-sync:
33	$(PYTHONBIN) contrib/map-get/update.py
34
35force-maps-sync:
36	$(PYTHONBIN) contrib/map-get/update.py --reply=yes
37
38clean-maps:
39	@echo "Deleting maps..."
40	@find $(MAPSDIR) -name '*.bsp' -delete
41	@echo "done"
42
43.DELETE_ON_ERROR:
44
45$(BSPS): %.bsp: %.map
46	$(UFO2MAP) $(UFO2MAPFLAGS) $(<:base/%=%)
47