#********************************************************************************
#      Copyright:  (C) 2023 LingYun IoT System Studio
#                  All rights reserved.
#
#       Filename:  Makefile
#    Description:  This file used to compile all the C file to respective binary,
#                  and it will auto detect cross compile or local compile.
#
#        Version:  1.0.0(11/08/23)
#         Author:  Guo Wenxue <guowenxue@gmail.com>
#      ChangeLog:  1, Release initial version on "11/08/23 16:18:43"
#
#*******************************************************************************

PWD=$(shell pwd)
TOPDIR=${PWD}/../project/
OPENLIBS_INCPATH=${TOPDIR}/openlibs/install/include
OPENLIBS_LIBPATH=${TOPDIR}/openlibs/install/lib

BUILD_ARCH=$(shell uname -m)
ifneq ($(findstring $(BUILD_ARCH), "x86_64" "i386"),)
	CROSS_COMPILE?=arm-linux-gnueabihf-
endif

CC=${CROSS_COMPILE}gcc

CFLAGS+=-I${OPENLIBS_INCPATH}
LDFLAGS+=-L${OPENLIBS_LIBPATH} -lm -lgpiod

SRCFILES = $(wildcard *.c)
BINARIES=$(SRCFILES:%.c=%)

all: ${BINARIES}

%: %.c 
	$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)

clean:
	rm -f ${BINARIES}
