TARGETS := all
#SUBDIRS := $(wildcard */.)
SUBDIRS = src src/contrib
SUBDIRGOALS := all
SUBDIRSCLEAN=$(addsuffix -clean,$(SUBDIRS))

STRIP ?= strip
DESTDIR ?= dist

all: install

$(TARGETS): $(SUBDIRS)

$(SUBDIRS):
	$(MAKE) -C $@ $(SUBDIRGOALS)

%-clean: %
	$(MAKE) -C $< clean

install: $(SUBDIRS)
	mkdir -p $(DESTDIR)/opt/radangel
	cp -p src/radangel $(DESTDIR)/opt/radangel/radangel
	$(STRIP) -s $(DESTDIR)/opt/radangel/radangel
	mkdir -p $(DESTDIR)/opt/websockify
	cp -p src/contrib/websockify $(DESTDIR)/opt/websockify/websockify
	$(STRIP) -s $(DESTDIR)/opt/websockify/websockify
	mkdir -p $(DESTDIR)/etc/systemd/system
	cp -p service/*.service $(DESTDIR)/etc/systemd/system/
	mkdir -p $(DESTDIR)/var/www/html/gamma
	cp -rp html/. $(DESTDIR)/var/www/html/gamma/
	mkdir -p $(DESTDIR)/etc/nginx/sites-available
	cp -p config/nginx*.conf $(DESTDIR)/etc/nginx/sites-available/
	mkdir -p $(DESTDIR)/etc/udev/rules.d
	cp -p config/*.rules $(DESTDIR)/etc/udev/rules.d/

dist-clean:
	rm -rf dist

clean: $(SUBDIRSCLEAN) dist-clean

.PHONY: $(TARGETS) $(SUBDIRS)
