1# This file is part of snapcast 2# Copyright (C) 2014-2021 Johannes Pohl 3# 4# This program is free software: you can redistribute it and/or modify 5# it under the terms of the GNU General Public License as published by 6# the Free Software Foundation, either version 3 of the License, or 7# (at your option) any later version. 8# 9# This program is distributed in the hope that it will be useful, 10# but WITHOUT ANY WARRANTY; without even the implied warranty of 11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12# GNU General Public License for more details. 13# 14# You should have received a copy of the GNU General Public License 15# along with this program. If not, see <http://www.gnu.org/licenses/>. 16 17VERSION = 0.25.0 18BIN = snapclient 19 20ifeq ($(TARGET), FREEBSD) 21SHELL = /usr/local/bin/bash 22else 23SHELL = /bin/bash 24endif 25 26ifdef DESTDIR 27# dh_auto_install (Debian) sets this variable 28 TARGET_DIR = $(DESTDIR)/usr 29else 30 TARGET_DIR ?= /usr 31endif 32 33DEBUG ?= 0 34ifeq ($(DEBUG), 1) 35 CXXFLAGS += -g 36else 37 CXXFLAGS += -O2 38endif 39 40ifneq ($(SANITIZE), ) 41 CXXFLAGS += -fsanitize=$(SANITIZE) -g 42 LDFLAGS += -fsanitize=$(SANITIZE) 43endif 44 45CXXFLAGS += $(ADD_CFLAGS) -std=c++14 -Wall -Wextra -Wpedantic -Wno-unused-function -DBOOST_ERROR_CODE_HEADER_ONLY -DHAS_FLAC -DHAS_OGG -DHAS_OPUS -DHAS_SOXR -DVERSION=\"$(VERSION)\" -I. -I.. -I../common 46LDFLAGS += $(ADD_LDFLAGS) -logg -lFLAC -lopus -lsoxr 47OBJ = snapclient.o stream.o client_connection.o time_provider.o player/player.o player/file_player.o decoder/pcm_decoder.o decoder/ogg_decoder.o decoder/flac_decoder.o decoder/opus_decoder.o controller.o ../common/sample_format.o ../common/resampler.o 48 49 50ifneq (,$(TARGET)) 51CXXFLAGS += -D$(TARGET) 52endif 53 54ifeq ($(ENDIAN), BIG) 55CXXFLAGS += -DIS_BIG_ENDIAN 56endif 57 58ifeq ($(TARGET), ANDROID) 59 60CXX = $(PROGRAM_PREFIX)clang++ 61CXXFLAGS += -pthread -fPIC -DHAS_TREMOR -DHAS_OPENSL -DHAS_OBOE -I$(TOOLCHAIN)/sysroot/usr/include -I$(TOOLCHAIN)/sysroot/$(NDK_TARGET)/usr/local/include 62LDFLAGS = -L$(TOOLCHAIN)/sysroot/$(NDK_TARGET)/usr/local/lib -pie -lvorbisidec -logg -lFLAC -lopus -lsoxr -lOpenSLES -loboe -latomic -llog -static-libstdc++ 63OBJ += player/opensl_player.o player/oboe_player.o 64 65else ifeq ($(TARGET), OPENWRT) 66 67CXXFLAGS += -pthread -DNO_CPP11_STRING -DHAS_TREMOR -DHAS_ALSA -DHAS_AVAHI -DHAS_DAEMON 68LDFLAGS += -lasound -lvorbisidec -lavahi-client -lavahi-common -latomic 69OBJ += ../common/daemon.o player/alsa_player.o browseZeroConf/browse_avahi.o 70 71else ifeq ($(TARGET), BUILDROOT) 72 73CXXFLAGS += -pthread -DNO_CPP11_STRING -DHAS_TREMOR -DHAS_ALSA -DHAS_AVAHI -DHAS_DAEMON 74LDFLAGS += -lasound -lvorbisidec -lavahi-client -lavahi-common -latomic 75OBJ += ../common/daemon.o player/alsa_player.o browseZeroConf/browse_avahi.o 76 77else ifeq ($(TARGET), MACOS) 78 79CXX = g++ 80CXXFLAGS += -DHAS_COREAUDIO -DHAS_VORBIS -DFREEBSD -DMACOS -DHAS_BONJOUR -DHAS_DAEMON -I/usr/local/include -Wno-unused-local-typedef -Wno-deprecated 81LDFLAGS += -lvorbis -lFLAC -L/usr/local/lib -framework AudioToolbox -framework CoreAudio -framework CoreFoundation -framework IOKit 82OBJ += ../common/daemon.o player/coreaudio_player.o browseZeroConf/browse_bonjour.o 83 84else 85 86CXX = g++ 87CXXFLAGS += -pthread -DHAS_VORBIS -DHAS_ALSA -DHAS_PULSE -DHAS_AVAHI -DHAS_DAEMON 88LDFLAGS += -lrt -lasound -lpulse -lvorbis -lavahi-client -lavahi-common -latomic 89OBJ += ../common/daemon.o player/alsa_player.o player/pulse_player.o browseZeroConf/browse_avahi.o 90 91endif 92 93 94all: check-env $(BIN) 95 96check-env: 97ifeq ($(TARGET), ANDROID) 98 $(eval TOOLCHAIN:=$(NDK_DIR)/toolchains/llvm/prebuilt/linux-x86_64) 99ifndef NDK_DIR 100 $(error android NDK_DIR is not set) 101endif 102ifndef ARCH 103 $(error ARCH is not set (arm, aarch64, x86)) 104endif 105ifeq ($(ARCH), x86) 106 $(eval NDK_TARGET:=x86_64-linux-android) 107 $(eval API:=21) 108else ifeq ($(ARCH), arm) 109 $(eval NDK_TARGET:=armv7a-linux-androideabi) 110 $(eval API:=16) 111 $(eval CXXFLAGS:=$(CXXFLAGS) -march=armv7) 112else ifeq ($(ARCH), aarch64) 113 $(eval NDK_TARGET:=aarch64-linux-android) 114 $(eval API:=21) 115endif 116 $(eval PROGRAM_PREFIX:=$(TOOLCHAIN)/bin/$(NDK_TARGET)$(API)-) 117endif 118 119$(BIN): $(OBJ) 120 $(CXX) $(CXXFLAGS) -o $(BIN) $(OBJ) $(LDFLAGS) 121 122%.o: %.cpp 123 $(CXX) $(CXXFLAGS) -c $< -o $@ 124 125clean: 126 rm -rf $(BIN) $(OBJ) *~ player/*.o 127 128ifdef DESTDIR 129 130install: 131 $(MAKE) installfiles 132 133else ifeq ($(TARGET), MACOS) 134 135install: 136 echo macOS 137 install -s -g wheel -o root $(BIN) $(TARGET_DIR)/local/bin/$(BIN) 138 install -g wheel -o root $(BIN).1 $(TARGET_DIR)/local/share/man/man1/$(BIN).1 139 install -g wheel -o root etc/$(BIN).plist /Library/LaunchAgents/de.badaix.snapcast.$(BIN).plist 140 launchctl load /Library/LaunchAgents/de.badaix.snapcast.$(BIN).plist 141 142else 143 144install: 145 $(MAKE) adduser 146 $(MAKE) installfiles 147 install -g audio -o snapclient -d /var/run/$(BIN) 148 149 @if [[ `systemctl` =~ -\.mount ]]; then \ 150 $(MAKE) installsystemd; \ 151 elif [[ `/sbin/init --version` =~ upstart ]]; then \ 152 $(MAKE) installsysv; \ 153 elif [[ -f /etc/init.d/cron && ! -h /etc/init.d/cron ]]; then \ 154 $(MAKE) installsysv; \ 155 else \ 156 echo cannot tell; \ 157 fi; \ 158 159endif 160 161installfiles: 162 install -s -D -g root -o root $(BIN) $(TARGET_DIR)/bin/$(BIN) 163 install -D -g root -o root $(BIN).1 $(TARGET_DIR)/share/man/man1/$(BIN).1 164 165installsystemd: 166 @echo using systemd; \ 167 cp ../debian/$(BIN).service /lib/systemd/system/$(BIN).service; \ 168 cp -n ../debian/$(BIN).default /etc/default/$(BIN); \ 169 systemctl daemon-reload; \ 170 systemctl enable $(BIN); \ 171 systemctl start $(BIN); \ 172 173installsysv: 174 @echo using sysv; \ 175 cp ../debian/$(BIN).init /etc/init.d/$(BIN); \ 176 cp -n ../debian/$(BIN).default /etc/default/$(BIN); \ 177 update-rc.d $(BIN) defaults; \ 178 /etc/init.d/$(BIN) start; \ 179 180adduser: 181 sh ../debian/snapclient.postinst configure 182 183ifeq ($(TARGET), MACOS) 184 185uninstall: 186 @launchctl unload /Library/LaunchAgents/de.badaix.snapcast.$(BIN).plist; \ 187 killall -9 $(BIN); \ 188 rm -f $(TARGET_DIR)/local/bin/$(BIN); \ 189 rm -f $(TARGET_DIR)/local/share/man/man1/$(BIN).1; \ 190 rm -f /Library/LaunchAgents/de.badaix.snapcast.$(BIN).plist; \ 191 192else 193 194uninstall: 195 rm -f $(TARGET_DIR)/share/man/man1/$(BIN).1 196 @if [[ `systemctl` =~ -\.mount ]]; then \ 197 $(MAKE) uninstallsystemd; \ 198 elif [[ `/sbin/init --version` =~ upstart ]]; then \ 199 $(MAKE) uninstallsysv; \ 200 elif [[ -f /etc/init.d/cron && ! -h /etc/init.d/cron ]]; then \ 201 $(MAKE) uninstallsysv; \ 202 else \ 203 echo cannot tell; \ 204 fi; \ 205 rm -rf /var/run/$(BIN) 206 $(MAKE) deluser 207 208endif 209 210uninstallsysv: 211 @/etc/init.d/$(BIN) stop; \ 212 killall -9 $(BIN); \ 213 rm -f /usr/bin/$(BIN); \ 214 rm -f /etc/init.d/$(BIN); \ 215 rm -f /etc/default/$(BIN); \ 216 update-rc.d -f $(BIN) remove; \ 217 218uninstallsystemd: 219 @systemctl stop $(BIN); \ 220 systemctl disable $(BIN); \ 221 killall -9 $(BIN); \ 222 rm -f /usr/bin/$(BIN); \ 223 rm -f /lib/systemd/system/$(BIN).service; \ 224 rm -f /etc/default/$(BIN); \ 225 systemctl daemon-reload; \ 226 227deluser: 228 sh ../debian/snapclient.postrm purge 229 230