include features.mk
depends	:= x11 alsa
headers := xbelld.h
sources	:= xbelld.c
objects	:= $(sources:.c=.o)
distfiles := $(headers) $(sources) Makefile features.mk README xbelld.1 \
		ChangeLog
VERSION := 0.3.3

CFLAGS := $(CFLAGS) -Wall -DVERSION=\"$(VERSION)\" -std=gnu99

ifdef NO_DEBUG
    CFLAGS += -DNDEBUG
else
    CFLAGS += -DDEBUG -g
endif

ifdef WITHOUT_ALSA
    depends := $(filter-out alsa, $(depends))
else
    CFLAGS += -DHAVE_ALSA
endif

# Make sure that the dependencies we have exist
$(if $(shell pkg-config --exists $(depends) && echo 1), \
    ,\
    $(error Could not resolv dependencies: $(depends)))

# Get correct CFLAGS / LDLIBS from dependencies.
CFLAGS += $(shell pkg-config $(depends) --cflags)
LDLIBS += $(shell pkg-config $(depends) --libs)

%.o :  %.c $(headers) features.mk
	$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@

xbelld: $(objects) features.mk
	$(CC) $(LDFLAGS) $(LOADLIBES) $(LDLIBS) $(objects) -o xbelld

clean:
	rm -f *.o xbelld

.PHONY: cl
cl:
	svn2cl https://xbelld.googlecode.com/svn

.PHONY: dist
dist: $(distfiles)
	export distdir=xbelld-$(VERSION)				\
	&& mkdir -p $$distdir						\
	&& cp $(distfiles) $$distdir/					\
	&& tar -c $$distdir | bzip2 > $$distdir.tbz2			\
	&& rm -rf $$distdir
