#  Install directory
INSTDIR=/usr/local/bin

#  Windoze/Msys/PDCurses
ifeq "$(OS)" "Windows_NT"
allfall.exe:allfall.c
	gcc --std=gnu99 -Wall -o $@ $^ pdcurses.a -lpthread
clean:
	rm allfall.exe
#  All Unices
else
#  OSX
ifeq "$(shell uname)"  "Darwin"
ALLFALL=allfall.osx
$(ALLFALL): allfall.c
	clang --std=gnu99 -Wall -o $@ $^ -lncurses -lpthread
install:$(ALLFALL)
	cp -a $^ $(INSTDIR)/allfall
#  Linux rPi2
else ifeq "$(shell uname -m)"  "armv6l"
ALLFALL=allfall.rpi
$(ALLFALL): allfall.c
	gcc --std=gnu99 -Wall -o $@ $^ -l:libncurses.a -l:libtinfo.a -lpthread
install:$(ALLFALL)
	cp -a $^ $(INSTDIR)/allfall
#  Linux rPi3
else ifeq "$(shell uname -m)"  "armv7l"
ALLFALL=allfall.rpi
$(ALLFALL): allfall.c
	gcc --std=gnu99 -Wall -o $@ $^ -l:libncurses.a -l:libtinfo.a -lpthread
install:$(ALLFALL)
	cp -a $^ $(INSTDIR)/allfall
#  Redhat based Linux uses MySQL
else ifneq ("$(wildcard /etc/redhat-release)","")
ALLFALL=allfall.rhl
$(ALLFALL): allfall.c
	gcc --std=gnu99 -Wall -DMySQL -I /usr/include/mysql -o $@ $^ -lncurses -lpthread -L/usr/lib64/mysql -lmysqlclient
install:$(ALLFALL)
	cp -a $^ $(INSTDIR)/allfall
#  Debian based Linux uses MariaDB
else
ALLFALL=allfall.lnx
$(ALLFALL): allfall.c
	gcc --std=gnu99 -Wall -DMySQL -I /usr/include/mariadb -o $@ $^ -l:libncurses.a -l:libtinfo.a -lpthread -lmariadbclient
# CentOS
# gcc --std=gnu99 -Wall -DMySQL -I /usr/include/mysql -o $@ $^ -lncurses -lpthread -L/usr/lib64/mysql -lmysqlclient
install:$(ALLFALL)
	cp -a $^ $(INSTDIR)/allfall
endif
#  Clean
clean:
	rm $(ALLFALL)
endif
