#*********************************************************************************
|
# Copyright: (C) 2018 LingYun IoT Studio
|
# All rights reserved.
|
#
|
# Filename: Makefile
|
# Description: This is the common subdir Makefile which to compile all the C
|
# source code to object files and then generate the shared or
|
# static library named lib$(FOLDER_NAME).a orlib $(FOLDER_NAME).so,
|
# which depends on the variable $LINK_MODE.
|
#
|
# Version: 1.0.0
|
# Author: Guo Wenxue <guowenxue@gmail.com>
|
# ChangeLog: 1, Release initial version on "11/20/2018 11:29:33 AM"
|
#
|
#********************************************************************************/
|
|
PWD=$(shell pwd)
|
LIBNAME=$(shell basename ${PWD})
|
STALIB=lib${LIBNAME}.a
|
DYNLIB=lib${LIBNAME}.so
|
|
CROSS_COMPILE?=/opt/rpi/arm-bcm2708/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-
|
|
VPATH= .
|
SRCS = $(wildcard ${VPATH}/*.c)
|
OBJS = $(patsubst %.c,%.o,$(SRCS))
|
|
PRJDIR?=$(shell dirname ${PWD})
|
CFLAGS+=-I${PRJDIR}
|
CC = ${CROSS_COMPILE}gcc
|
AR = ${CROSS_COMPILE}ar
|
|
|
ifeq ("${LINK_MODE}", "STATIC")
|
LIBS = ${STALIB}
|
else
|
LIBS=${DYNLIB}
|
endif
|
|
all: entry ${LIBS} install
|
|
entry:
|
@echo " ";
|
@echo " =========================================================";
|
@echo " ** Compile subdir ${LIBNAME} for ${ARCH} ";
|
@echo " =========================================================";
|
|
#$(LD) -g --relocatable $(OBJS) -o lib${LIBNAME}.o
|
${STALIB}: $(OBJS)
|
$(AR) -rcu $@ $(OBJS)
|
|
${DYNLIB}: $(OBJS)
|
$(CC) -fPIC -shared -o $@ $(OBJS)
|
|
%.o : %.c
|
$(CC) -c $< $(CFLAGS)
|
|
install:
|
@if [ ! -z "${LIBS_PATH}" ] ; then \
|
mkdir -p ${LIBS_PATH} ; \
|
cp ${LIBS} ${LIBS_PATH}; \
|
fi;
|
|
|
clean:
|
@rm -f *.o
|
@rm -rf *.gdb *.a *.so
|
|
distclean: clean
|
@rm -f tags cscope*
|
|
.PHONY: clean entry
|