# SPDX-License-Identifier: MIT

PREFIX = /usr
BIN = $(PREFIX)/bin
SBIN = $(PREFIX)/sbin
ETC = /etc
INITD = $(ETC)/init.d
RULESD = /usr/lib/udev/rules.d
NWDISPA = $(ETC)/NetworkManager/dispatcher.d

.PHONY: all install clean tools

CFLAGS := -Wall -Wextra

tools: tools/send-at tools/ems31-mux

tools/ems31-mux: tools/ems31-mux.c tools/linmuxcfg/linmuxcfg.c

clean:
	rm -f tools/send-at tools/ems31-mux

install: all
	install -D -t $(DESTDIR)$(INITD) init.d/connection-recover
	install -D -t $(DESTDIR)$(BIN) tools/connection-recover
	install -D -t $(DESTDIR)$(BIN) tools/send-at tools/wwan-force-restart
	install -D -t $(DESTDIR)$(BIN) tools/wwan-poweroff tools/wwan-safe-poweroff
	install -D -t $(DESTDIR)$(BIN) tools/ec25-clean-reset
	install -D -t $(DESTDIR)$(ETC)/atmark -m 0644 etc/atmark/connection-recover.conf.example
	install -D -t $(DESTDIR)$(RULESD) -m 0644 lib/udev/rules.d/76-aiotg4-mm-restart.rules
	install -D -t $(DESTDIR)$(BIN) tools/ems31-boot tools/ems31-mux tools/ems31-power-ctrl
	install -D -t $(DESTDIR)$(ETC)/atmark -m 0644 etc/atmark/ems31-boot.conf.example
	install -D -t $(DESTDIR)$(INITD) init.d/ems31-boot
	install -D -t $(DESTDIR)$(BIN) tools/wwan-led
	install -D -t $(DESTDIR)$(INITD) init.d/wwan-led
	install -D -t $(DESTDIR)$(INITD) init.d/wwan-safe-poweroff
	install -D -t $(DESTDIR)$(BIN) tools/els31-firewall-disable
	install -D -t $(DESTDIR)$(BIN) tools/els31-firewall-enable
	install -D -t $(DESTDIR)$(BIN) tools/els31-firewall-get-status
	install -D -t $(DESTDIR)$(ETC)/atmark -m 0644 etc/atmark/els31.conf.example
	install -D -t $(DESTDIR)$(NWDISPA) etc/NetworkManager/dispatcher.d/98-els31-firewall
	install -D -t $(DESTDIR)$(RULESD) -m 0644 lib/udev/rules.d/85-nm-unmanaged-els31.rules
	install -D -t $(DESTDIR)$(BIN) tools/ec25-ims-disable
	install -D -t $(DESTDIR)$(BIN) tools/mm-modem-num
	install -D -t $(DESTDIR)$(SBIN) tools/connection-recover-log
	install -D -t $(DESTDIR)$(BIN) tools/sim7672-boot
	install -D -t $(DESTDIR)$(ETC)/atmark -m 0644 etc/atmark/sim7672-boot.conf.example
	install -D -t $(DESTDIR)$(INITD) init.d/sim7672-boot
	install -D -t $(DESTDIR)$(RULESD) -m 0644 lib/udev/rules.d/76-aiota9e-sim7672-fwupdate.rules
	install -D -t $(DESTDIR)$(RULESD) -m 0644 lib/udev/rules.d/76-highg1es1-mm-restart.rules
	install -D -t $(DESTDIR)$(BIN) tools/wwan-clean-reset
