#!/bin/sh

CC = gcc
CFLAGS=-D_REENTRANT -g -Wall

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

dbLib		= -L/usr/local/mysql/lib -lmariadbclient -lz
dbLib.ES	= -L/opt/lampp/lib/mysql -lmariadbclient -lssl -lz -ldl -lcrypto -pthread -lm

publicLib	= -L../../../../plat/public/lib -lpublic 
LIB_FLAGS	= $(publicLib)

LINK_SUFFIX = $(dbINCLUDE_FLAGS) $(LIB_FLAGS) ${dbLib}
LINK_SUFFIX.ES = $(dbINCLUDE_FLAGS.ES) $(LIB_FLAGS) ${dbLib.ES}

PROGS = omcLibTest

BIN_OBJ 	=	omcLibMain.o omcFuncLib.o omcDbLib.o mib_parse.o
BIN_OBJ.ES	=	omcLibMain.o.ES omcFuncLib.o.ES omcDbLib.o.ES mib_parse.o.ES

LIB_OBJ = omcFuncLib.o omcDbLib.o mib_parse.o
LIB_OBJ.ES = omcFuncLib.o.ES omcDbLib.o.ES mib_parse.o.ES

default: linuxES

all: 
	@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: $(BIN_OBJ)
	@echo Linking $(PROGS)
	@$(CC) $(CFLAGS) -o $(PROGS) $(BIN_OBJ) $(LINK_SUFFIX)
	rm -f *.a
	ar r libomcLib.a $(LIB_OBJ)
	rm -f *.o core *~

linuxES: $(BIN_OBJ.ES)
	@echo Linking $(PROGS)
	@$(CC) $(CFLAGS) -o $(PROGS) $(BIN_OBJ) $(LINK_SUFFIX.ES)
	# rm -f *.a
	ar r libomcLib.a $(LIB_OBJ)

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

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

installall: installbin installomc

omcLibMain.o: omcLibMain.c omcLib.h
	$(CC) $(CFLAGS) -c omcLibMain.c $(dbINCLUDE_FLAGS)

omcFuncLib.o: omcFuncLib.c omcFuncLib.h
	$(CC) $(CFLAGS) -c omcFuncLib.c

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

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

omcLibMain.o.ES: omcLibMain.c omcLib.h
	$(CC) $(CFLAGS) -c omcLibMain.c $(dbINCLUDE_FLAGS.ES)

omcFuncLib.o.ES: omcFuncLib.c omcFuncLib.h
	$(CC) $(CFLAGS) -c omcFuncLib.c

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

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

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