From 717f8986cd49d896d1566e68973f6e261d40a29f Mon Sep 17 00:00:00 2001 From: Ansa89 Date: Mon, 23 Jun 2014 21:55:32 +0200 Subject: [PATCH] Makefile: checks for libs --- src/Makefile | 45 +++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/src/Makefile b/src/Makefile index f40799b..7a25215 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,30 +1,43 @@ -SUPPORT_AUDIO ?= 0 - LIBS = libtoxcore ncurses CFLAGS = -std=gnu99 -pthread LDFLAGS = -ldl -lresolv -DESTDIR=/usr/local +DESTDIR ?= /usr/local OBJ = chat.o chat_commands.o configdir.o dns.o execute.o OBJ += file_senders.o friendlist.o global_commands.o groupchat.o line_info.o OBJ += log.o misc_tools.o prompt.o settings.o toxic.o toxic_strings.o windows.o -ifeq ($(SUPPORT_AUDIO), 1) -CHECK_OPENAL = $(shell pkg-config openal || echo -n "no_audio") -CHECK_TOXAV = $(shell pkg-config libtoxav || echo -n "no_audio") -ifeq (no_audio, $(filter no_audio, $(CHECK_OPENAL) $(CHECK_TOXAV))) - SUPPORT_AUDIO = 0 +AUDIO_LIBS = libtoxav openal +AUDIO_CFLAGS = -D_SUPPORT_AUDIO +AUDIO_OBJ = device.o audio_call.o + +CHECK_AUDIO_LIBS = $(shell pkg-config $(AUDIO_LIBS) || echo -n "error") +ifneq ($(CHECK_AUDIO_LIBS), error) + LIBS += $(AUDIO_LIBS) + CFLAGS += $(AUDIO_CFLAGS) + OBJ += $(AUDIO_OBJ) else - CFLAGS += -D_SUPPORT_AUDIO - OBJ += device.o audio_call.o - LIBS += openal libtoxav +ifneq ($(MAKECMDGOALS), clean) +MISSING_AUDIO_LIBS = $(shell for lib in $(AUDIO_LIBS) ; do if ! pkg-config $$lib ; then echo $$lib ; fi ; done) +$(warning WARNING -- Toxic will be compiled without audio support) +$(warning WARNING -- You need these libraries for audio support) +$(warning WARNING -- $(MISSING_AUDIO_LIBS)) endif endif -ifneq ($(LIBS),) - CFLAGS += $(shell pkg-config --cflags $(LIBS)) - LDFLAGS += $(shell pkg-config --libs $(LIBS)) +CHECK_LIBS = $(shell pkg-config $(LIBS) || echo -n "error") +ifneq ($(CHECK_LIBS), error) + CFLAGS += $(shell pkg-config --cflags $(LIBS)) + LDFLAGS += $(shell pkg-config --libs $(LIBS)) +else +ifneq ($(MAKECMDGOALS), clean) +MISSING_LIBS = $(shell for lib in $(LIBS) ; do if ! pkg-config $$lib ; then echo $$lib ; fi ; done) +$(warning ERROR -- Cannot compile Toxic) +$(warning ERROR -- You need these libraries) +$(warning ERROR -- $(MISSING_LIBS)) +$(error ERROR) +endif endif all: toxic @@ -36,8 +49,6 @@ install: toxic mkdir -pv $(DESTDIR)/bin install -m 0755 toxic $(DESTDIR)/bin --include $(OBJ:.o=.d) - %.o: %.c $(CC) $(CFLAGS) -o $*.o -c $*.c $(CC) -MM $(CFLAGS) $*.c > $*.d @@ -45,4 +56,6 @@ install: toxic clean: rm -rf *.d *.o toxic +-include $(OBJ:.o=.d) + .PHONY: clean all install