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$(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 38$(COMPONENT_OUTPUT_DIR)/${LIBFILE_DYN} : $(COMPONENT_OUTPUT_DIR) ${OBJS} $(A_LIBS) 39 @${CC} -o $@ -fPIC -shared $^ ${LDFLAGS} ${SO_LIBS} ${A_LIBS} ${COVERAGE} 40 41${A_LIBS}:; 42 $(error Required library ($@) not found. Run top level make to build all dependencies in order) 43 44clean: 45 @echo "Deleting intermediate compilation results" 46 @find $(COMPONENT_OUTPUT_DIR) -name "*.a" -or -name "*.o" -or -name "*.so" -or -name "*.d" | xargs rm 47 @rm $(COMPONENT_OUTPUT_DIR)/${LIBFILE} $(COMPONENT_OUTPUT_DIR)/${LIBFILE_DYN} &> /dev/null ; true 48 49clean_coverage: 50 @find $(COMPONENT_OUTPUT_DIR) -name "*.gcda" -or -name "*.gcno" | xargs rm -f ; true 51 52clean_all: clean clean_coverage 53 54${BSIM_LIBS_DIR}/${VERSION_FILE}: version 55 @if [[ -f "$<" ]]; then\ 56 cp $< $@; \ 57 else \ 58 echo "unknown" > $@; \ 59 fi 60 61${BSIM_LIBS_DIR}/% : $(COMPONENT_OUTPUT_DIR)/% 62 @cp $< $@ 63 64install: ${BSIM_LIBS_DIR}/${LIBFILE_DYN} ${BSIM_LIBS_DIR}/${LIBFILE} ${BSIM_LIBS_DIR}/${VERSION_FILE} 65 66Makefile: ; 67