#/bin/sh

# Makefile for CDR 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/omcLib -lomcLib \
-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../../../omcLib/c_program/ftp -lftp \
-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=cdrCollector
CDR_OBJ  =	cdr.o cdrdb.o
CDR_OBJ.ES  =	cdr.o.ES cdrdb.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: $(CDR_OBJ) cdrmain.o
	@cd ../../../omcLib/c_program/ftp; make linux72;		cd ..
	@cd ../../../accountMgr/c_program/cdrCollector;
	@echo Linking $(PROGS)
	@$(LINK.c) -o $(PROGS) cdrmain.o $(CDR_OBJ) $(LINKFLAG) -lm
	ar r libcdr.a $(CDR_OBJ)
	rm -rf *.o
	rm -rf *bak
	rm -rf *~
	cp -f $(PROGS) ../../../bin
	cp -f $(PROGS) /usr/local/omc/bin/

linuxES: $(CDR_OBJ.ES) cdrmain.o.ES
	@cd ../../../omcLib/c_program/ftp; make linuxES;		cd ..
	@cd ../../../accountMgr/c_program/cdrCollector;
	@echo Linking $(PROGS)
	@$(LINK.c.ES) -o $(PROGS) cdrmain.o $(CDR_OBJ) $(LINKFLAG.ES) -lm
	ar r libcdr.a $(CDR_OBJ)

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

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

installall: installbin installomc

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

cdr.o: cdr.c cdr.h 
	$(COMPILE.c) -c cdr.c

cdrmain.o.ES: cdrmain.c 
	$(COMPILE.c.ES) -c cdrmain.c

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

cdrdb.o.ES: cdrdb.c
	$(COMPILE.c.ES) -c cdrdb.c

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