TARGETS	= $(OBJDIR)channels$(SOEXT) $(OBJDIR)mute$(SOEXT) $(OBJDIR)radio$(SOEXT) $(OBJDIR)set$(SOEXT) $(OBJDIR)template$(SOEXT)
OBJDIR	=
PREFIX	= /usr/local
DESTDIR	=
LIBDIR	= $(PREFIX)/lib
CC	= cc
CPPFLAGSF= -I../../include
CPPFLAGS=
CFLAGSF	= `pkg-config --cflags libDesktop`
CFLAGS	= -W -Wall -g -O2 -fPIC -D_FORTIFY_SOURCE=2 -fstack-protector
LDFLAGSF= `pkg-config --libs libDesktop`
LDFLAGS	= -Wl,-z,relro -Wl,-z,now
EXEEXT	=
AR	= ar
ARFLAGS	= -rc
RANLIB	= ranlib
CCSHARED= $(CC) -shared
SOEXT	= .so
RM	= rm -f
LN	= ln -f
MKDIR	= mkdir -m 0755 -p
INSTALL	= install


all: $(TARGETS)

channels_OBJS = $(OBJDIR)channels.o
channels_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
channels_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)

$(OBJDIR)channels$(SOEXT): $(channels_OBJS)
	$(CCSHARED) -o $(OBJDIR)channels$(SOEXT) $(channels_OBJS) $(channels_LDFLAGS)

mute_OBJS = $(OBJDIR)mute.o
mute_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
mute_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)

$(OBJDIR)mute$(SOEXT): $(mute_OBJS)
	$(CCSHARED) -o $(OBJDIR)mute$(SOEXT) $(mute_OBJS) $(mute_LDFLAGS)

radio_OBJS = $(OBJDIR)radio.o
radio_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
radio_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)

$(OBJDIR)radio$(SOEXT): $(radio_OBJS)
	$(CCSHARED) -o $(OBJDIR)radio$(SOEXT) $(radio_OBJS) $(radio_LDFLAGS)

set_OBJS = $(OBJDIR)set.o
set_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
set_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)

$(OBJDIR)set$(SOEXT): $(set_OBJS)
	$(CCSHARED) -o $(OBJDIR)set$(SOEXT) $(set_OBJS) $(set_LDFLAGS)

template_OBJS = $(OBJDIR)template.o
template_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
template_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)

$(OBJDIR)template$(SOEXT): $(template_OBJS)
	$(CCSHARED) -o $(OBJDIR)template$(SOEXT) $(template_OBJS) $(template_LDFLAGS)

$(OBJDIR)channels.o: channels.c ../../include/Mixer/control.h
	$(CC) $(channels_CFLAGS) -o $(OBJDIR)channels.o -c channels.c

$(OBJDIR)mute.o: mute.c ../../include/Mixer/control.h
	$(CC) $(mute_CFLAGS) -o $(OBJDIR)mute.o -c mute.c

$(OBJDIR)radio.o: radio.c ../../include/Mixer/control.h
	$(CC) $(radio_CFLAGS) -o $(OBJDIR)radio.o -c radio.c

$(OBJDIR)set.o: set.c ../../include/Mixer/control.h
	$(CC) $(set_CFLAGS) -o $(OBJDIR)set.o -c set.c

$(OBJDIR)template.o: template.c ../../include/Mixer/control.h
	$(CC) $(template_CFLAGS) -o $(OBJDIR)template.o -c template.c

clean:
	$(RM) -- $(channels_OBJS) $(mute_OBJS) $(radio_OBJS) $(set_OBJS) $(template_OBJS)

distclean: clean
	$(RM) -- $(TARGETS)

install: all
	$(MKDIR) $(DESTDIR)$(LIBDIR)/Mixer/controls
	$(INSTALL) -m 0755 $(OBJDIR)channels$(SOEXT) $(DESTDIR)$(LIBDIR)/Mixer/controls/channels$(SOEXT)
	$(MKDIR) $(DESTDIR)$(LIBDIR)/Mixer/controls
	$(INSTALL) -m 0755 $(OBJDIR)radio$(SOEXT) $(DESTDIR)$(LIBDIR)/Mixer/controls/radio$(SOEXT)
	$(MKDIR) $(DESTDIR)$(LIBDIR)/Mixer/controls
	$(INSTALL) -m 0755 $(OBJDIR)set$(SOEXT) $(DESTDIR)$(LIBDIR)/Mixer/controls/set$(SOEXT)

uninstall:
	$(RM) -- $(DESTDIR)$(LIBDIR)/Mixer/controls/channels$(SOEXT)
	$(RM) -- $(DESTDIR)$(LIBDIR)/Mixer/controls/radio$(SOEXT)
	$(RM) -- $(DESTDIR)$(LIBDIR)/Mixer/controls/set$(SOEXT)

.PHONY: all clean distclean install uninstall
