CROSS_COMPILE ?= 
CC := $(CROSS_COMPILE)gcc

LIB += -lcurl -lip4tc clamscan/clamscan.o clamscan/manager.o -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64   -lclamav ./clamscan/shared/libshared.a -lssl -lcrypto -lz -lpthread

IPTC_CFLAGS += -DHAVE_CONFIG_H -I./libiptc -D_LARGEFILE_SOURCE=1 -D_LARGE_FILES -D_FILE_OFFSET_BITS=64 -D_REENTRANT

OBG = rhost

CLAMSCAN_CFLAGS += -Wall -Os -DHAVE_CONFIG_H -I./clamscan -I./clamscan/shared -I./clamscan/libclamav -I./clamscan/libclamunrar_iface -I/usr/include/json-c -Wdate-time -D_FORTIFY_SOURCE=2 -fstack-protector-strong -Wall -D_FILE_OFFSET_BITS=64  -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
SHARED_CFLAGS += -Wall -Os -DHAVE_CONFIG_H -I./clamscan -I./clamscan/shared -I./clamscan/libclamav -I./clamscan/libclamunrar_iface -I/usr/include/json-c -Wdate-time -D_FORTIFY_SOURCE=2 -g -O2  -fstack-protector-strong -Wformat -Werror=format-security -Wall -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
CFLAGS += -Os -g -Wall -DCRON_USE_LOCAL_TIME -DCRON_TEST_MALLOC

all: conf.o rhost.o libiptc.o ccronexpr.o 

	$(CC) $(SHARED_CFLAGS) -c ./clamscan/shared/actions.c  -fPIC -DPIC -o ./clamscan/shared/actions.o
	$(CC) $(SHARED_CFLAGS) -c ./clamscan/shared/cdiff.c  -fPIC -DPIC -o ./clamscan/shared/cdiff.o
	$(CC) $(SHARED_CFLAGS) -c ./clamscan/shared/cert_util.c  -fPIC -DPIC -o ./clamscan/shared/cert_util.o
	$(CC) $(SHARED_CFLAGS) -c ./clamscan/shared/clamdcom.c  -fPIC -DPIC -o ./clamscan/shared/clamdcom.o
	$(CC) $(SHARED_CFLAGS) -c ./clamscan/shared/getopt.c  -fPIC -DPIC -o ./clamscan/shared/getopt.o
	$(CC) $(SHARED_CFLAGS) -c ./clamscan/shared/hostid.c  -fPIC -DPIC -o ./clamscan/shared/hostid.o
	$(CC) $(SHARED_CFLAGS) -c ./clamscan/shared/idmef_logging.c  -fPIC -DPIC -o ./clamscan/shared/idmef_logging.o
	$(CC) $(SHARED_CFLAGS) -c ./clamscan/shared/misc.c  -fPIC -DPIC -o ./clamscan/shared/misc.o
	$(CC) $(SHARED_CFLAGS) -c ./clamscan/shared/optparser.c  -fPIC -DPIC -o ./clamscan/shared/optparser.o
	$(CC) $(SHARED_CFLAGS) -c ./clamscan/shared/output.c  -fPIC -DPIC -o ./clamscan/shared/output.o
	$(CC) $(SHARED_CFLAGS) -c ./clamscan/shared/tar.c  -fPIC -DPIC -o ./clamscan/shared/tar.o
	$(CC) $(SHARED_CFLAGS) -c ./clamscan/shared/linux/cert_util_linux.c  -fPIC -DPIC -o ./clamscan/shared/linux/cert_util_linux.o
	ar cr ./clamscan/shared/libshared.a ./clamscan/shared/actions.o ./clamscan/shared/cdiff.o ./clamscan/shared/cert_util.o ./clamscan/shared/clamdcom.o ./clamscan/shared/getopt.o ./clamscan/shared/hostid.o ./clamscan/shared/idmef_logging.o ./clamscan/shared/misc.o ./clamscan/shared/optparser.o ./clamscan/shared/output.o ./clamscan/shared/tar.o ./clamscan/shared/linux/cert_util_linux.o
	$(CC) $(CLAMSCAN_CFLAGS) -c clamscan/clamscan.c -o clamscan/clamscan.o
	$(CC) $(CLAMSCAN_CFLAGS) -c clamscan/manager.c -o clamscan/manager.o
	$(CC) $(CFLAGS) $^ -o $(OBG) $(LIB)
	
	chmod +x $(OBG)


static: conf.o rhost.o libiptc.o
	$(CC) $(IPTC_CFLAGS) -c libiptc/libip4tc.c -o libiptc/libip4tc.o
	ar crs libiptc/libip4tc.a libiptc/libip4tc.o
	$(CC) $(CFLAGS) $^ libiptc/libip4tc.o -o $(OBG) `/data/curl/bin/curl-config --cflags --static-libs` `pkg-config --libs --static libbrotlidec`

clean:
	rm -rf *.o
	rm -rf libiptc/*.o libiptc/*.a
	rm -rf clamscan/shared/*.o clamscan/shared/libshared.a clamscan/*.o
	rm -rf $(OBG)