#!/bin/sh

CC = gcc
CFLAGS=-D_REENTRANT -g -Wall

dbINCLUDE_FLAGS = -I/usr/local/mysql/include
dbINCLUDE_FLAGS.ES = -I/usr/include/mariadb

LINKFLAG=-L../../../omcLib/c_program/omcLib -lomcLib \
-L/usr/local/mysql/lib -lmariadbclient -lz \
-L../../../../plat/snmp/lib -lsnmp \
-L../../../../plat/sccp/lib -lsccp \
-L../../../../plat/iptrans/lib -liptrans \
-L../../../../plat/debug/lib -ldebug \
-L../../../../plat/public/lib -lpublic \

LINKFLAG.ES=-L../../../omcLib/c_program/omcLib -lomcLib \
-L/usr/lib/mysql -lmariadbclient -lz \
-L../../../../plat/snmp/lib -lsnmp \
-L../../../../plat/sccp/lib -lsccp \
-L../../../../plat/iptrans/lib -liptrans \
-L../../../../plat/debug/lib -ldebug \
-L../../../../plat/public/lib -lpublic \
-L../../../faultMgr/c_program/sysStat -lsysStat \

LINK_SUFFIX = $(dbINCLUDE_FLAGS) $(LINKFLAG)
LINK_SUFFIX.ES = $(dbINCLUDE_FLAGS.ES) $(LINKFLAG.ES)

PROGS = beatSend

ALL_OBJ = beatSendMain.o beatSend.o  sys_stat.o
ALL_OBJ.ES = beatSendMain.o.ES beatSend.o.ES sys_stat.o.ES

LIB_OBJ = beatSend.o sys_stat.o
LIB_OBJ.ES = beatSend.o.ES sys_stat.o.ES

default:linuxES

all:
	@echo " **** Compiling $(PROGS) ****"
	@echo "make clean    -- Delete the target files"
	@echo "make linux72  -- Generate target files for Redhat Linux 72"
	@echo "make linuxES  -- Generate target files for Redhat Linux ES"

linux72: $(ALL_OBJ)
	@echo Linking $(PROGS)
	ar r libbeatSend.a $(LIB_OBJ)
	@$(CC) $(CFLAGS) -o $@ $(ALL_OBJ) $(LINK_SUFFIX)
	rm -rf *.o *~ core

linuxES: $(ALL_OBJ.ES)
	@echo Linking $(PROGS)
	ar r libbeatSend.a $(LIB_OBJ)
	@$(CC) $(CFLAGS) -o $(PROGS) $(ALL_OBJ) $(LINK_SUFFIX.ES) -lm
	rm -rf *.o *~ core

installbin: linuxES
	cp -f $(PROGS) ../../../../bin/

installomc: linuxES	
	cp -f $(PROGS) /usr/local/omc/bin/

installall: installbin installomc

beatSendMain.o: beatSendMain.c 
	$(CC) $(CFLAGS) -c beatSendMain.c $(dbINCLUDE_FLAGS)

beatSend.o: beatSend.c 
	$(CC) $(CFLAGS) -c beatSend.c $(dbINCLUDE_FLAGS)

sys_stat.o: sys_stat.c
	        $(CC) $(CFLAGS) -c sys_stat.c $(dbINCLUDE_FLAGS)

beatSendMain.o.ES: beatSendMain.c 
	$(CC) $(CFLAGS) -c beatSendMain.c $(dbINCLUDE_FLAGS.ES)

beatSend.o.ES: beatSend.c 
	$(CC) $(CFLAGS) -c beatSend.c $(dbINCLUDE_FLAGS.ES)

sys_stat.o.ES: sys_stat.c
	        $(CC) $(CFLAGS) -c sys_stat.c $(dbINCLUDE_FLAGS.ES)

clean:
	rm -f $(PROGS) *.o *.a
