CC = @CC@
CFLAGS = @CFLAGS@
CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@
PREFIX = @PREFIX@

BUILD_DIR = build

INSTALL = install
INSTALL_PROGRAM = $(INSTALL)
INSTALL_DATA = $(INSTALL) -m 644
MSGFMT = msgfmt

PO_FILES = $(wildcard *.po)
MO_FILES = $(patsubst %.po,$(BUILD_DIR)/%.mo,$(PO_FILES))

all: $(BUILD_DIR)/dcraw $(MO_FILES)

$(BUILD_DIR)/dcraw: $(BUILD_DIR)
	$(CC) -o $(BUILD_DIR)/dcraw $(CFLAGS) dcraw.c -ljpeg -llcms -lintl -liconv $(CPPFLAGS) $(LDFLAGS) -DLOCALEDIR=\"$(PREFIX)/share/locale/\"

$(BUILD_DIR)/%.mo: %.po $(BUILD_DIR)
	$(MSGFMT) -o $@ $<

$(BUILD_DIR):
	mkdir -p $(BUILD_DIR)

.PHONY: install
install:
	$(INSTALL_PROGRAM) -s -m 755 $(BUILD_DIR)/dcraw $(DESTDIR)$(PREFIX)/bin
