1# Copyright 2018 Oticon A/S 2# SPDX-License-Identifier: Apache-2.0 3 4OBJS=$(abspath $(addprefix $(COMPONENT_OUTPUT_DIR)/,${SRCS:.c=.o})) 5OBJS32=$(abspath $(addprefix $(COMPONENT_OUTPUT_DIR)/,${SRCS:.c=.32.o})) 6LIBFILE=${LIB_NAME}.a 7LIBFILE_DYN=${LIB_NAME}.so 8VERSION_FILE:=${LIB_NAME}.version 9 10all: install 11 12DEPENDFILES:=$(addsuffix .d,$(basename ${OBJS})) 13 14-include ${DEPENDFILES} 15 16always_run_this_target: 17#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) 18# 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) 19 20.PHONY: all install compile lib clean clean_all ${DEPENDFILES} always_run_this_target version 21#setting the dependencies as phony targets will actually speed up things.. (otherwise make will check if there is implicit rules to remake them) 22 23compile: $(COMPONENT_OUTPUT_DIR)/${LIBFILE_DYN} $(COMPONENT_OUTPUT_DIR)/${LIBFILE} 24 25lib: compile 26 27$(COMPONENT_OUTPUT_DIR): 28 @mkdir -p $(COMPONENT_OUTPUT_DIR) 29 30$(COMPONENT_OUTPUT_DIR)/%.o: %.c 31 @if [ ! -d $(dir $@) ]; then mkdir -p $(dir $@); fi 32 @${CC} ${CPPFLAGS} ${CFLAGS} ${COVERAGE} -c $< -o $@ 33 34%.c: ; 35%.h: ; 36 37$(COMPONENT_OUTPUT_DIR)/${LIBFILE}: $(COMPONENT_OUTPUT_DIR) ${OBJS} ${A_LIBS} 38 @rm $(COMPONENT_OUTPUT_DIR)/${LIBFILE} &> /dev/null ; true 39 @${AR} -cr $(COMPONENT_OUTPUT_DIR)/${LIBFILE} ${OBJS} ${A_LIBS} 40 41$(COMPONENT_OUTPUT_DIR)/${LIBFILE_DYN} : $(COMPONENT_OUTPUT_DIR) ${OBJS} $(A_LIBS) 42 @${CC} -o $@ -fPIC -shared $^ ${LDFLAGS} ${SO_LIBS} ${A_LIBS} ${COVERAGE} 43 44${A_LIBS}:; 45 $(error Required library ($@) not found. Run top level make to build all dependencies in order) 46 47clean: 48 @echo "Deleting intermediate compilation results" 49 @find $(COMPONENT_OUTPUT_DIR) -name "*.a" -or -name "*.o" -or -name "*.so" -or -name "*.d" | xargs rm 50 @rm $(COMPONENT_OUTPUT_DIR)/${LIBFILE} $(COMPONENT_OUTPUT_DIR)/${LIBFILE_DYN} &> /dev/null ; true 51 52clean_coverage: 53 @find $(COMPONENT_OUTPUT_DIR) -name "*.gcda" -or -name "*.gcno" | xargs rm -f ; true 54 55clean_all: clean clean_coverage 56 57${BSIM_LIBS_DIR}/${VERSION_FILE}: version 58 @if [[ -f "$<" ]]; then\ 59 cp $< $@; \ 60 else \ 61 echo "unknown" > $@; \ 62 fi 63 64${BSIM_LIBS_DIR}/% : $(COMPONENT_OUTPUT_DIR)/% 65 @cp $< $@ 66 67install: ${BSIM_LIBS_DIR}/${LIBFILE_DYN} ${BSIM_LIBS_DIR}/${LIBFILE} ${BSIM_LIBS_DIR}/${VERSION_FILE} 68 69Makefile: ; 70