#!/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../../../../wxc2plat/snmp -lsnmp \
-L../../../omcLib/c_program/omcLib -lomcLib \
-L../../../../wxc2plat/debug -ldebug \
-L../../../../wxc2plat/iptrans -liptrans \
-L../../../../wxc2plat/public -lpublic \
-L/usr/local/mysql/lib -lmariadbclient -lz

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

COMPILE_SUFFIX = $(dbINCLUDE_FLAGS)
COMPILE_SUFFIX.ES = $(dbINCLUDE_FLAGS.ES)

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

PROGS = logCollector

LOGCOLLECTOR_OBJ =	logCollectorMain.o logCollector.o
LOGCOLLECTOR_OBJ.ES =	logCollectorMain.o.ES logCollector.o.ES

LIB_OBJ = logCollector.o
LIB_OBJ.ES = logCollector.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: $(LOGCOLLECTOR_OBJ)
	@echo Linking $(PROGS)
	@$(CC) $(CFLAGS) -o $(PROGS) $(LOGCOLLECTOR_OBJ) $(LINK_SUFFIX) -lm
	ar r liblogCollector.a $(LIB_OBJ)
	rm -f *.o core *~
	cp -f $(PROGS) ../../../bin/
	cp -f $(PROGS) /usr/local/omc/bin/

linuxES: $(LOGCOLLECTOR_OBJ.ES)
	@echo Linking $(PROGS)
	@$(CC) $(CFLAGS) -o $(PROGS) $(LOGCOLLECTOR_OBJ) $(LINK_SUFFIX.ES) -lm
	ar r liblogCollector.a $(LIB_OBJ)
	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

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

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

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

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

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