prefix=@prefix@
etcdir=@sysconfdir@
bindir=${prefix}/bin
sbindir=${prefix}/sbin
libdir=${prefix}/lib
moddir=${libdir}/cdebconf/frontend
sharedir=${prefix}/share/debconf
mandir=${prefix}/share/man
incdir=${prefix}/include/cdebconf

PACKAGE=@PACKAGE@
CC=@CC@
CFLAGS=@CFLAGS@ -I.
LDFLAGS=@LDFLAGS@
GTK_CFLAGS=@GTK_CFLAGS@
GTK_LIBS=@GTK_LIBS@
VTE_CFLAGS=@VTE_CFLAGS@

CFLAGS += -funsigned-char -fstrict-aliasing -Wall -W -Werror -Wundef \
	-Wwrite-strings -Wsign-compare -Wno-unused-parameter -Winit-self \
	-Wpointer-arith -Wredundant-decls -Wno-format-zero-length \
	-Wmissing-prototypes -Wmissing-format-attribute

FRONTENDS=@FRONTENDS@
PLUGIN_MODULES=$(addsuffix -plugin-$(PACKAGE).so,$(FRONTENDS))

all: $(PLUGIN_MODULES)

install: $(PLUGIN_MODULES)
	for p in $(PLUGIN_MODULES); do \
		install -m755 -d $(DESTDIR)/$(moddir)/$${p%%-*} ; \
		install -m644 $$p $(DESTDIR)/$(moddir)/$${p%%-*}/$${p#*-} ; \
	done

newt-plugin-$(PACKAGE).so: newt-plugin-$(PACKAGE).opic
	$(CC) $(LDFLAGS) -shared -o $@ newt-plugin-$(PACKAGE).opic -lnewt

gtk-plugin-$(PACKAGE).so: gtk-plugin-$(PACKAGE).opic
	$(CC) $(LDFLAGS) -shared -o $@ $^ $(GTK_LIBS) -lvte

clean:
	rm -f $(PLUGIN_MODULES)
	rm -f *.opic

distclean: clean
	rm -f config.log config.status
	rm -f Makefile

gtk-%.opic: gtk-%.c
	@echo "Compiling $< to $@"
	$(CC) $(CFLAGS) $(GTK_CFLAGS) $(VTE_CFLAGS) -fPIC -o $@ -c $<

%.opic: %.c
	@echo "Compiling $< to $@"
	$(CC) $(CFLAGS) -fPIC -o $@ -c $<
