# SPDX-FileCopyrightText: Copyright (c) 2021-2022 KUNLUNXIN CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: MIT
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

SRCS = async_task.c
ASYNC_UTEST_SRCS = async_task_unittest.c
OBJS = $(SRCS:.c=.o)
ASYNC_UTEST_OBJS = $(ASYNC_UTEST_SRCS:.c=.o)
LIB = libutils.a
INCLUDE = -I../../../source/inc

ifeq ($(M32), -m64)
DEFINES+=-DUSE_64BIT_ENV
endif

.PHONY: all
all: lib

utils: CFLAGS=-g -c -Wall -Wextra -pedantic $(INCLUDE) $(DEFINES) $(M32) -fPIC
#utils: LIBS=-lpthread -lrt
utils: LIBS= -lrt
utils: $(OBJS)
	$(CC) $(CFLAGS) $(LIBS)

arm: CC=aarch64-linux-gnu-gcc
arm: CFLAGS=-g -c -Wall -Wextra -pedantic $(INCLUDE) $(DEFINES)  -fPIC  -std=c99
arm: LIBS=-lpthread -lrt
arm: $(OBJS)
	$(CC) $(CFLAGS) $(LIBS)

lib: utils
	$(AR) rcv $(LIB) $(OBJS)

pclinux: lib
osfree: lib
pcie: lib

arm_pclinux: arm
	$(AR) rcv $(LIB) $(OBJS)

versatile: arm
	$(AR) rcv $(LIB) $(OBJS)

async_task_test: EXEC=async_task
async_task_test: CFLAGS=-g -Wall $(INCLUDE) $(DEFINES) $(M32)
async_task_test: LIBS=-lpthread
async_task_test: lib utils $(ASYNC_UTEST_OBJS)
	$(CC) $(CFLAGS) $(ASYNC_UTEST_OBJS) $(LIBS) $(LIB) -o $(EXEC)

clean:
	rm -f fifo
	rm -f async_task
	rm -f $(LIB)
	rm -f *.o
