Permalink
Browse files

Allow to build shell-fm without dependencies.

Call make with EXTERN_ONLY=1:

  make EXTERN_ONLY=1 [args]

to build shell-fm without built-in playback capabilities.

Signed-off-by: Jonas Kramer <jkramer@nex.scrapping.cc>
  • Loading branch information...
1 parent f241e1a commit d1f6dde330da8c25fc72a51dc54d7d23c8c7f47e @wavexx wavexx committed with Jonas Kramer Sep 16, 2009
Showing with 48 additions and 26 deletions.
  1. +1 −2 .gitignore
  2. +13 −8 source/Makefile
  3. +8 −0 source/main.c
  4. +26 −16 source/play.c
View
@@ -1,6 +1,5 @@
*~
-*.o
-*.a
+*.[doa]
.*.swp
manual/shell-fm.1.gz
source/shell-fm
View
@@ -1,10 +1,15 @@
MAIN := main.c
SOURCE := $(filter-out $(MAIN),$(wildcard *.c))
OBJECT := $(subst .c,.o,$(SOURCE))
+DEP := $(subst .c,.d,$(SOURCE))
BINARY := shell-fm
LIB := libshellfm.so
STATIC := libshellfm.a
+CFLAGS += -Os -Wall -MD -W -I./include/
+ifdef EXTERN_ONLY
+ CFLAGS += -DEXTERN_ONLY
+else
ifeq ($(shell uname -s), OpenBSD)
LDFLAGS += -lossaudio
endif
@@ -15,7 +20,7 @@ ifeq ($(shell uname -s), Darwin)
CFLAGS += -D__darwin__
endif
-CFLAGS += -Os -Wall -W -I./include/ -DLIBAO \
+CFLAGS += -DLIBAO \
$(shell pkg-config --cflags mad) \
$(shell pkg-config --cflags ao)
LDFLAGS += $(shell pkg-config --libs mad) \
@@ -25,25 +30,25 @@ ifeq ($(shell pkg-config --exists taglib_c && echo 1), 1)
CFLAGS += $(shell pkg-config --cflags taglib_c) -DTAGLIB
LDFLAGS += $(shell pkg-config --libs taglib_c)
endif
+endif
.PHONY: clean tags cscope
-all : shell-fm
-
-objects : $(SOURCE)
- $(CC) $(CFLAGS) -fPIC -c $(SOURCE)
+all : $(BINARY)
$(LIB) : $(OBJECT)
- $(CC) -shared -Wl,-soname,$(LIB) -o $(LIB) $(OBJECT)
+ $(CC) -shared -Wl,-soname,$(LIB) -o $(LIB) $(OBJECT)
$(STATIC) : $(OBJECT)
$(AR) -cvq $(STATIC) $(OBJECT)
-$(BINARY) : $(STATIC)
+$(BINARY) : $(STATIC) $(MAIN)
$(CC) -o $(BINARY) $(CFLAGS) $(MAIN) $(LDFLAGS) $(STATIC)
clean :
- rm -f $(OBJECT) $(BINARY) $(LIB) $(STATIC)
+ rm -f $(OBJECT) $(BINARY) $(LIB) $(STATIC) $(DEP)
tags cscope :
$(MAKE) -C .. $@
+
+sinclude $(DEP)
View
@@ -154,9 +154,17 @@ int main(int argc, char ** argv) {
if(nerror)
help(argv[0], EXIT_FAILURE);
+#ifdef EXTERN_ONLY
+ /* Abort if EXTERN_ONLY is defined and no extern command is present */
+ if(!haskey(& rc, "extern")) {
+ fputs("Can't continue without extern command.\n", stderr);
+ exit(EXIT_FAILURE);
+ }
+#else
#ifndef LIBAO
if(!haskey(& rc, "device"))
set(& rc, "device", "/dev/audio");
+#endif
#endif
if(!background) {
View
@@ -8,8 +8,6 @@
#define _GNU_SOURCE
-#include <mad.h>
-
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -23,6 +21,9 @@
#include <sys/stat.h>
#include <assert.h>
+#ifndef EXTERN_ONLY
+#include <mad.h>
+
#ifdef LIBAO
#include <ao/ao.h>
#else
@@ -39,16 +40,18 @@
#endif
+#ifdef TAGLIB
+#include <taglib/tag_c.h>
+#endif
+#endif
+
#include "settings.h"
#include "pipe.h"
#include "play.h"
#include "interface.h"
#include "globals.h"
-#ifdef TAGLIB
-#include <taglib/tag_c.h>
-#endif
-
+#ifndef EXTERN_ONLY
struct stream {
FILE * streamfd;
#ifdef LIBAO
@@ -67,13 +70,16 @@ struct stream {
int timeout;
int preload;
};
+#endif
#define BUFSIZE (32*1024)
+#ifndef EXTERN_ONLY
static enum mad_flow input(void *, struct mad_stream *);
static enum mad_flow output(void *, const struct mad_header *, struct mad_pcm *);
inline signed scale(mad_fixed_t);
static int timed_read(int, unsigned char *, int, int);
+#endif
int killed = 0;
@@ -115,12 +121,13 @@ mkpath(char *path)
}
int playback(FILE * streamfd, int pipefd) {
- const char * freetrack = NULL;
-
killed = 0;
signal(SIGUSR1, sighand);
+#ifndef EXTERN_ONLY
if(!haskey(& rc, "extern")) {
+ const char * freetrack = NULL;
+
struct stream data;
struct mad_decoder dec;
@@ -262,8 +269,10 @@ int playback(FILE * streamfd, int pipefd) {
free(data.path);
}
-
- } else {
+ }
+ else
+#endif
+ {
pid_t ppid = getppid(), cpid = 0;
const char * cmd = meta(value(& rc, "extern"), M_SHELLESC, & track);
FILE * ext = openpipe(cmd, & cpid);
@@ -303,6 +312,12 @@ int playback(FILE * streamfd, int pipefd) {
return !0;
}
+static void sighand(int sig) {
+ if(sig == SIGUSR1)
+ killed = !0;
+}
+
+#ifndef EXTERN_ONLY
static enum mad_flow input(void * data, struct mad_stream * stream) {
static unsigned char buf[BUFSIZE + 1] = { 0 };
struct stream * ptr = (struct stream *) data;
@@ -517,12 +532,6 @@ inline signed scale(register mad_fixed_t sample) {
return (sample >> (MAD_F_FRACBITS + 1 - 16)) * volume / MAX_VOLUME;
}
-static void sighand(int sig) {
- if(sig == SIGUSR1)
- killed = !0;
-}
-
-
static int timed_read(int fd, unsigned char * p, int count, int timeout) {
fd_set fdset;
struct timeval tv;
@@ -546,3 +555,4 @@ static int timed_read(int fd, unsigned char * p, int count, int timeout) {
fprintf(stderr, "Track stream timed out (%d).\n", timeout);
return -1;
}
+#endif

0 comments on commit d1f6dde

Please sign in to comment.