
rounds := $(shell ls -d ../2*-*)

source = $(shell find $(rounds) -name \*.py)
parquet := $(source:.py=.parquet)

COUNTRY := $(shell basename "$$(cd .. && pwd)")
LSMS_DATA_ROOT ?= $(if $(LSMS_DATA_DIR),$(LSMS_DATA_DIR),$(if $(XDG_DATA_HOME),$(XDG_DATA_HOME),$(HOME)/.local/share)/lsms_library)
VAR_DIR ?= $(LSMS_DATA_ROOT)/$(COUNTRY)/var

# food_prices / food_quantities / food_expenditures are derived at API time by
# _FOOD_DERIVED from food_acquired -- NOT materialized to var/ (the per-country
# food_prices_quantities_and_expenditures.py was retired, GH #218 Phase 3).
var = $(VAR_DIR)/food_acquired.parquet

all: $(parquet) $(var)

food_acquired = $(shell find $(rounds) -name food_acquired.py)
food_acquired_parquet := $(food_acquired:.py=.parquet)

../%/_/food_acquired.parquet: $(food_acquired)
	(cd $(@D) && python food_acquired.py)

$(VAR_DIR)/food_acquired.parquet: food_acquired.py $(food_acquired_parquet)
	python food_acquired.py

clean:
	-rm $(parquet)
	-rm $(VAR_DIR)/*.parquet

# crop_production: 2009-10 is a wave script (the two-season S4AV1 / S4AV2
# matrix has to be melted); 2013-14 and 2017-18 are YAML-path waves with no
# script, so there is no country-level $(VAR_DIR)/crop_production.parquet
# target -- the library's load_from_waves assembles the three waves
# (data_scheme.yml, crop_production block).
crop_production = $(shell find $(rounds) -name crop_production.py)
crop_production_parquet := $(crop_production:.py=.parquet)

../%/_/crop_production.parquet: $(crop_production)
	(cd $(@D) && python crop_production.py)

# plot_labor: all three waves are wave scripts (the `source` axis is a melt
# across column groups, which YAML cannot express), so as with
# crop_production there is no country-level $(VAR_DIR)/plot_labor.parquet
# target -- the library's load_from_waves assembles the three waves
# (data_scheme.yml, plot_labor block).
plot_labor = $(shell find $(rounds) -name plot_labor.py)
plot_labor_parquet := $(plot_labor:.py=.parquet)

../%/_/plot_labor.parquet: $(plot_labor)
	(cd $(@D) && python plot_labor.py)
