From: Michel Pollet Date: Tue, 15 Aug 2017 10:14:48 +0000 (+0100) Subject: make: Factored library making X-Git-Tag: v1.6~26 X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=d4228955c5d48d4dd43026a8c5a02b08f4e50a27;p=sx%2Fsimavr.git make: Factored library making Removed duplicate make commands for libraries Signed-off-by: Michel Pollet --- diff --git a/Makefile.common b/Makefile.common index 840a98e..9b56e27 100644 --- a/Makefile.common +++ b/Makefile.common @@ -184,12 +184,39 @@ ${OBJ}/%.elf: ifneq ($(E),) @echo LD $@ endif - ${E}$(CC) -MMD ${CFLAGS} ${LFLAGS} -o $@ $^ $(LDFLAGS) + ${E}$(CC) -MMD ${CFLAGS} ${LFLAGS} -o $@ ${filter %.o,$^} $(LDFLAGS) + + +.PRECIOUS: ${OBJ}/%.a ${OBJ}/%.so.1 +# +# Static library +# +${OBJ}/%.a: +ifneq ($(E),) + @echo AR $@ +endif + ${E}$(AR) cru $@ ${filter %.o,$^} && $(RANLIB) $@ + +# +# Shared library (Linux) +# +${OBJ}/%.so.1: ${OBJ}/%.a +ifneq ($(E),) + @echo SHARED $@ +endif + ${E}$(CC) -o $@ -shared \ + -Wl,--whole-archive,-soname,${basename ${notdir $@}}.1 \ + ${filter %.o %.a,$^} \ + -Wl,--no-whole-archive \ + ${filter-out -l%, $(LDFLAGS)} ${EXTRA_LDFLAGS} + +${OBJ}/%.so: ${OBJ}/%.so.1 + ln -sf ${notdir $<} $@ obj: ${OBJ} ${OBJ}: - @mkdir -p ${OBJ} + ${E}mkdir -p ${OBJ} clean-${OBJ}: rm -rf ${OBJ} diff --git a/examples/parts/Makefile b/examples/parts/Makefile index 3711379..153e64f 100644 --- a/examples/parts/Makefile +++ b/examples/parts/Makefile @@ -38,25 +38,14 @@ endif # # Static library # -static_lib = $(target).a - -${OBJ}/${static_lib} : ${objects} -${OBJ}/${static_lib} : - $(AR) cru $@ $^ -${target}: ${OBJ}/${static_lib} - +${OBJ}/${target}.a: ${objects} +${target}: ${OBJ}/${target}.a # # Shared library (Linux only) # -shared_lib = ${target}.so.1 - -${OBJ}/${shared_lib} : ${objects} -${OBJ}/${shared_lib} : - ${CC} -shared -Wl,-soname,${shared_lib} $^ -o $@ ifeq (${shell uname}, Linux) -${target}: ${OBJ}/${shared_lib} +${target}: ${OBJ}/${target}.so endif - @echo $@ done clean: clean-${OBJ} rm -rf *.hex *.a *.axf *.vcd .*.swo .*.swp .*.swm .*.swn *.so *.o diff --git a/simavr/Makefile b/simavr/Makefile index 09f7fcd..c4e009d 100644 --- a/simavr/Makefile +++ b/simavr/Makefile @@ -50,23 +50,7 @@ IPATH += ../../shared # Static library # ${OBJ}/libsimavr.a : ${sim_o} -ifneq ($(E),) - @echo AR $@ -endif - ${E}$(AR) cru $@ $^ && $(RANLIB) $@ - -# -# Shared library (Linux) -# -${OBJ}/libsimavr.so.1 : ${sim_o} -ifneq ($(E),) - @echo SHARED $@ -endif - ${E}$(CC) -shared -Wl,-soname,libsimavr.so.1 -o $@ $^ \ - ${filter-out -lsimavr, $(LDFLAGS)} -${OBJ}/libsimavr.so : ${OBJ}/libsimavr.so.1 - ln -sf libsimavr.so.1 $@ libsimavr : config ${OBJ}/libsimavr.a # shared library won't work that easily on non-linux @@ -74,6 +58,7 @@ ifeq (${shell uname}, Linux) libsimavr : ${OBJ}/libsimavr.so endif +${OBJ}/${target}.elf : libsimavr ${OBJ}/${target}.elf : ${OBJ}/${target}.o ${target} : ${OBJ}/${target}.elf @@ -168,7 +153,6 @@ sim_core_config.h ${OBJ}/cores.deps: $(cores) Makefile conf+="#define CONFIG_$$upper 1\n"; \ obj=$${file/.c/.o} ; obj=$${obj/cores\/}; \ printf "\$${OBJ}/libsimavr.a: \$${OBJ}/$$obj\n">>${OBJ}/cores.deps ; \ - printf "\$${OBJ}/libsimavr.so.1: \$${OBJ}/$$obj\n">>${OBJ}/cores.deps ; \ else \ conf+="#undef CONFIG_$$upper\n"; \ echo WARNING $$file did not compile, check your avr-gcc toolchain; \