#/bin/sh

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/usr/local/mysql/lib -lmariadbclient -lz
LINKFLAG.ES=-L/usr/lib/mysql -lmariadbclient -lz

PROGS=ftpclient
FTP_OBJ  =	ftpclient.o ftp.o
FTP_OBJ.ES  =	ftpclient.o.ES ftp.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: $(FTP_OBJ)
	@echo Linking $(PROGS)
	@$(LINK.c) -o $(PROGS) $(FTP_OBJ) $(LINKFLAG) -lm
	ar r libftp.a ftp.o
	rm -rf *.o
	rm -rf *bak
	rm -rf *~

linuxES: $(FTP_OBJ.ES)
	@echo Linking $(PROGS)
	@$(LINK.c.ES) -o $(PROGS) $(FTP_OBJ) $(LINKFLAG.ES) -lm
	ar r libftp.a ftp.o

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

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

installall: installbin installomc

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

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

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

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

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