#!/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/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 \

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

PROGS = beatProc

ALL_OBJ = beatProcMain.o beatProc.o 
ALL_OBJ.ES = beatProcMain.o.ES beatProc.o.ES

LIB_OBJ = beatProc.o  
LIB_OBJ.ES = beatProc.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 libbeatProc.a $(LIB_OBJ)
	#@$(CC) $(CFLAGS) -o $(PROGS) $(ALL_OBJ) $(LINK_SUFFIX) -lm 
	rm  -f *.o core *~
	#cp -f $(PROGS) ../../../../bin/
	#cp -f $(PROGS) /usr/local/omc/bin/

linuxES: $(ALL_OBJ.ES)
	@echo Linking $(PROGS)
	ar r libbeatProc.a $(LIB_OBJ)
	@$(CC) $(CFLAGS) -o $(PROGS) $(ALL_OBJ) $(LINK_SUFFIX.ES) -lm  
	rm  -f *.o core *~
	#cp -f $(PROGS) ../../../../bin/
	#cp -f $(PROGS) /usr/local/omc/bin/

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

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

installall: installbin installomc

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

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

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

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

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