Skip to content

Commit

Permalink
Allow to build shell-fm without dependencies.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
wavexx authored and Jonas Kramer committed Sep 19, 2009
1 parent f241e1a commit d1f6dde
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 26 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
*~
*.o
*.a
*.[doa]
.*.swp
manual/shell-fm.1.gz
source/shell-fm
Expand Down
21 changes: 13 additions & 8 deletions source/Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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) \
Expand All @@ -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)
8 changes: 8 additions & 0 deletions source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
42 changes: 26 additions & 16 deletions source/play.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

#define _GNU_SOURCE

#include <mad.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand All @@ -23,6 +21,9 @@
#include <sys/stat.h>
#include <assert.h>

#ifndef EXTERN_ONLY
#include <mad.h>

#ifdef LIBAO
#include <ao/ao.h>
#else
Expand All @@ -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
Expand All @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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.