# SPDX-License-Identifier: GPL-2.0
# Makefile for ycc user space driver and libraries
include ../../scripts/Makefile.include

export ULIB_DIR=$(CURDIR)
prefix ?= /usr/local

OUTPUTS ?= $(CURDIR)/outputs
OBJ_TMP ?= $(CURDIR)/obj_tmp

CFLAGS += -Wall -Wextra -g -D_GNU_SOURCE
LDFLAGS += -lpthread -ludev -lssl -lcrypto -L$(OUTPUTS) -ludma -lasn1

hal_objs:
	make -C $(CURDIR)/hal/ all

udma_objs:
	make -C $(CURDIR)/udma/ all

drv_objs:
	make -C $(CURDIR)/drv/ all

algs_objs:
	make -C $(CURDIR)/algs/ all

output:
	mkdir -p $(OUTPUTS)

sample: output hal_objs drv_objs algs_objs
	make -C $(CURDIR)/samples/ all

test: output hal_objs drv_objs algs_objs
	make -C $(CURDIR)/tests/ all

base: output hal_objs udma_objs drv_objs algs_objs
	$(CC) $(CFLAGS) $(LDFLAGS) -shared -o $(OUTPUTS)/libycc_drv.so $(OBJ_TMP)/*.o

all: base sample test

clean:
	rm -rf $(OUTPUTS)
	make -C $(CURDIR)/drv clean
	make -C $(CURDIR)/udma/ clean
	make -C $(CURDIR)/hal/ clean
	make -C $(CURDIR)/algs/ clean
	make -C $(CURDIR)/samples/ clean
	make -C $(CURDIR)/tests/ clean

.PHONY: $(ALL_TARGETS)

.DEFAULT_GOAL := all
