#!/bin/sh

# Makefile for smcli module.

CC = gcc
CFLAGS=-D_REENTRANT -g -Wall

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

dbLib		= -L/usr/local/mysql/lib	-lmariadbclient -lz
dbLib.ES	= -L/usr/lib/mysql	-lmariadbclient -lm

omcLib	= -L../../../omcLib/c_program/omcLib -lomcLib

LIB_FLAGS		= $(omcLib) $(dbLib)


LIB_FLAGS.ES=-L../../../omcLib/c_program/omcLib -lomcLib \
-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/usr/lib/mysql	-lmariadbclient -lm

CHECK_INDENT=indent -kr -ts4 *.c *.h

LINK_SUFFIX		= $(LIB_FLAGS)
LINK_SUFFIX.ES	= $(LIB_FLAGS.ES)

PROGS = smcli

PROGS_OBJ	 = commands.o smcli.o pmcli.o
PROGS_OBJ.ES = commands.o.ES smcli.o.ES pmcli.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: $(PROGS_OBJ)
	@cd ../../../omcLib/c_program/omcLib; make clean; make linux72; cd -
	@cd ../../../accountMgr/c_program/smcli;
	@echo Linking $(PROGS)
	#$(CHECK_INDENT)
	@$(CC) $(CFLAGS) -o $(PROGS) $(PROGS_OBJ) $(LINK_SUFFIX)
	rm -f *.o core *~
	cp -f $(PROGS) ../../../bin
	cp -f $(PROGS) /usr/local/omc/bin/

linuxES: $(PROGS_OBJ.ES)
	@cd ../../../omcLib/c_program/omcLib; make linuxES; cd -
	@cd ../../../accountMgr/c_program/smcli;
	@echo Linking $(PROGS)
	#$(CHECK_INDENT)
	@$(CC) $(CFLAGS) -o $(PROGS) $(PROGS_OBJ) $(LINK_SUFFIX.ES)

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

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

installall: installbin installomc

commands.o: commands.c smcli.h
	$(CC) $(CFLAGS) -c commands.c $(dbINCLUDE_FLAGS)

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

#added for the configuration of parameters
pmcli.o: pmcli.c 
	$(CC) $(CFLAGS) -c pmcli.c $(dbINCLUDE_FLAGS)

commands.o.ES: commands.c smcli.h
	$(CC) $(CFLAGS) -c commands.c $(dbINCLUDE_FLAGS.ES)

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

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

clean:
	rm -f *.o *.a $(PROGS)
	@cd ../../../accountMgr/c_program/smcli;		rm -f *.o *.a; cd ..
	
