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}
#
# 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
# 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
libsimavr : ${OBJ}/libsimavr.so
endif
+${OBJ}/${target}.elf : libsimavr
${OBJ}/${target}.elf : ${OBJ}/${target}.o
${target} : ${OBJ}/${target}.elf
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; \