#
# When building a package or installing otherwise in the system, make
# sure that the variable PREFIX is defined, e.g. make PREFIX=/usr/local
#
PROGNAME=faup1090
DUMP1090=dump1090

include /usr/share/dpkg/buildflags.mk

PREFIX=/usr

ifdef PREFIX
BINDIR=$(PREFIX)/bin
SHAREDIR=$(PREFIX)/share/$(DUMP1090)
HTMLDIR=$(SHAREDIR)/public_html
EXTRACFLAGS=-DHTMLPATH=\"$(HTMLDIR)\"
endif

#CFLAGS=-O2 -g -Wall -W `pkg-config --cflags librtlsdr`
#CFLAGS+=-Wall -W `pkg-config --cflags librtlsdr`
CFLAGS+=-Wall -W
#LIBS=`pkg-config --libs librtlsdr` -lpthread -lm
LIBS=-lpthread -lm
CC=gcc

info:
	@echo "'make all' compile faup1090"
	@echo "'make install-faup1090' install faup1090"
	@echo "'make install-dump1090' install dump1090"
	@echo "'make install-autostart' make dump1090 autostart upon boot"
	@echo "'make full-install' all of the above"

all: faup1090

%.o: %.c
	$(CC) $(CFLAGS) $(EXTRACFLAGS) -c $<

faup1090.o: faup1090.c faup1090.h

faup1090: faup1090.o

faup1090: faup1090.o anet.o interactive.o mode_ac.o mode_s.o net_io.o
	$(CC) $(LDFLAGS) -g -o faup1090 faup1090.o anet.o interactive.o mode_ac.o mode_s.o net_io.o $(LIBS)

clean:
	rm -f *.o faup1090

install-faup1090: faup1090
	install $(PROGNAME) $(BINDIR)

install-dump1090:
	install $(DUMP1090) $(BINDIR)
	mkdir -p $(HTMLDIR)
	cp -R public_html $(SHAREDIR)

install-autostart:
	install fadump1090.sh /etc/init.d/
	update-rc.d fadump1090.sh defaults

full-install:	install-faup1090 install-dump1090 install-autostart
