INCLUDE_DIRS = -I . -L .

ERROR_LEVEL = 5

HOST_OS := $(shell uname -s)

ifeq ($(shell echo $(HOST_OS) | grep -c QNX), 1)
 QNX := 1
 CFLAGS = -D ERROR_LEVEL=${ERROR_LEVEL} -g ${INCLUDE_DIRS} -D_QNX -DUNIX
 AUV_BIN_DIR = ../onboard/bin
 all: charger-project.qnx
 targets = charger
endif

ifeq ($(shell echo $(HOST_OS) | grep -c CYGWIN), 1)
 CYGWIN := 1
 CFLAGS = -D ERROR_LEVEL=${ERROR_LEVEL} -g ${INCLUDE_DIRS} -Wall
 AUV_BIN_DIR = $(HOME)/bin
 all: charger-project.cygwin
 targets = charger.exe
endif

objects = charger.o serial.o smart_battery.o util.o xfr.o error.o

.PHONY: charger-project.cygwin
charger-project.cygwin: $(objects)
	$(CC) $(CFLAGS) -o charger $(objects)

.PHONY: charger-project.qnx
charger-project.qnx: $(objects)
	$(CC) -N 128K $(CFLAGS) -o charger $(objects)

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

.PHONY: clean
clean:
	-rm *~ $(objects) charger charger.exe 

.PHONY: cleanlogs
cleanlogs:
	-rm *.log

install: $(targets)
	cp -f $(targets) $(AUV_BIN_DIR)/.

charger.o: error.h xfr.h smart_battery.h serial.h charger.h
smart_battery.o: smart_battery.h serial.h error.h util.h
serial.o: serial.h error.h util.h
xfr.o: xfr.h serial.h error.h
error.o: error.h

