1# Copyright 2018 Oticon A/S 2# Copyright 2023 Nordic Semiconductor ASA 3# SPDX-License-Identifier: Apache-2.0 4 5OBJS=$(abspath $(addprefix $(COMPONENT_OUTPUT_DIR)/,${SRCS:.c=.${VARIANT}.o})) 6LIBFILE=${LIB_NAME}.a 7VERSION_FILE:=${LIB_NAME}.version 8 9all: compile 10 11DEPENDFILES:=$(addsuffix .d,$(basename ${OBJS})) 12 13-include ${DEPENDFILES} 14 15always_run_this_target: 16#phony target to trigger the rerun of the make of each library, but ensure that make checks if the library was regenerated (so it doesnt relink the binary if it wasnt) 17# we could do like in the root Makefile, and just go first over all the libraries makefiles we may need instead, but this is slighly more efficient (although more messy) 18 19.PHONY: all install compile lib clean clean_all ${DEPENDFILES} always_run_this_target version 20#setting the dependencies as phony targets will actually speed up things.. (otherwise make will check if there is implicit rules to remake them) 21 22compile: $(COMPONENT_OUTPUT_DIR)/${LIBFILE} 23 24$(COMPONENT_OUTPUT_DIR): 25 @mkdir -p $(COMPONENT_OUTPUT_DIR) 26 27$(COMPONENT_OUTPUT_DIR)/%.${VARIANT}.o: %.c 28 @if [ ! -d $(dir $@) ]; then mkdir -p $(dir $@); fi 29 @${CC} ${CPPFLAGS} ${CFLAGS} ${COVERAGE} -c $< -o $@ 30 31%.c: ; 32%.h: ; 33 34$(COMPONENT_OUTPUT_DIR)/${LIBFILE}: $(COMPONENT_OUTPUT_DIR) ${OBJS} ${A_LIBS} 35 @rm $(COMPONENT_OUTPUT_DIR)/${LIBFILE} &> /dev/null ; true 36 @${AR} -cr $(COMPONENT_OUTPUT_DIR)/${LIBFILE} ${OBJS} ${A_LIBS} 37 38lib :compile 39 40${A_LIBS}:; 41 $(error Required library ($@) not found. Run top level make to build all dependencies in order) 42 43clean: 44 @echo "Deleting intermediate compilation results" 45 @find $(COMPONENT_OUTPUT_DIR) -name "*.o" -or -name "*.so" -or -name "*.a" -or -name "*.d" | xargs rm -f 46 @rm $(COMPONENT_OUTPUT_DIR)/${LIBFILE} &> /dev/null ; true 47 48clean_coverage: 49 @find $(COMPONENT_OUTPUT_DIR) -name "*.gcda" -or -name "*.gcno" | xargs rm -f ; true 50 51clean_all: clean clean_coverage 52 53${BSIM_LIBS_DIR}/${VERSION_FILE}: version 54 @if [[ -f "$<" ]]; then\ 55 cp $< $@; \ 56 else \ 57 echo "unknown" > $@; \ 58 fi 59 60${BSIM_LIBS_DIR}/% : $(COMPONENT_OUTPUT_DIR)/% 61 @cp $< $@ 62 63install: ${BSIM_LIBS_DIR}/${LIBFILE} ${BSIM_LIBS_DIR}/${VERSION_FILE} 64 65# Let's explicitly tell make there is rules to make these make files: 66make_inc/pre.mk: ; 67make_inc/common_post.mk: ; 68${BSIM_BASE_PATH}/common/pre.make.inc: ; 69