#/bin/sh

# Makefile for cstaCollector Module.

CC = gcc
CFLAGS=-g -Wall -I/usr/local/mysql/include
CFLAGS.ES=-g -Wall -I/usr/include/mariadb

COMPILE.c=$(CC) $(CFLAGS) 
COMPILE.c.ES=$(CC) $(CFLAGS.ES)

LINK.c=$(CC) $(CFLAGS) 
LINK.c.ES=$(CC) $(CFLAGS.ES) 

LINKFLAG=-L../../../omcLib/c_program/ftp -lftp \
-L../../../../wxc2plat/snmp -lsnmp \
-L../../../../wxc2plat/debug -ldebug \
-L../../../../wxc2plat/iptrans -liptrans \
-L../../../../wxc2plat/public -lpublic \
-L/usr/local/mysql/lib -lmariadbclient -lz

LINKFLAG.ES=-L../../../omcLib/c_program/omcLib -lomcLib \
-L../../../../plat/snmp/lib -lsnmp \
-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

PROGS=cstaCollector
CSTA_OBJ  =	csta.o 
CSTA_OBJ.ES  =	csta.o.ES cstamain.o.ES

default: linuxES

all:
	@echo " **** Compiling $(PROGS) ****"
	@echo "make clean   --  Delete the target files(*.o, *.a)"
	@echo "make linux72 --  Generate target files for Redhat Linux 7.2"
	@echo "make linuxES --  Generate target files for Redhat ES 4.0"

linux72: $(CSTA_OBJ) cstamain.o
	@echo Linking $(PROGS)
	@$(LINK.c) -o $(PROGS) cstamain.o $(CSTA_OBJ) $(LINKFLAG) -lm
	ar r libcsta.a $(CSTA_OBJ)
	rm -rf *.o
	rm -rf *bak
	rm -rf *~
	cp -f $(PROGS) ../../../bin
	cp -f $(PROGS) /usr/local/omc/bin/

linuxES: $(CSTA_OBJ.ES) cstamain.o.ES
	@echo Linking $(PROGS)
	@$(LINK.c.ES) -o $(PROGS) cstamain.o $(CSTA_OBJ) $(LINKFLAG.ES) -lm
	ar r libcsta.a $(CSTA_OBJ)
	# rm -rf *.o
	# rm -rf *bak
	# rm -rf *~
	# 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

cstamain.o: cstamain.c 
	$(COMPILE.c) -c cstamain.c

csta.o: csta.c csta.h 
	$(COMPILE.c) -c csta.c
	
cstamain.o.ES: cstamain.c 
	$(COMPILE.c.ES) -c cstamain.c

csta.o.ES: csta.c csta.h 
	$(COMPILE.c.ES) -c csta.c

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