Skip to content

Commit

Permalink
make: Factored library making
Browse files Browse the repository at this point in the history
Removed duplicate make commands for libraries

Signed-off-by: Michel Pollet <[email protected]>
  • Loading branch information
buserror committed Aug 15, 2017
1 parent bfe3c83 commit d422895
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 33 deletions.
31 changes: 29 additions & 2 deletions Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
17 changes: 3 additions & 14 deletions examples/parts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 1 addition & 17 deletions simavr/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,30 +50,15 @@ 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
ifeq (${shell uname}, Linux)
libsimavr : ${OBJ}/libsimavr.so
endif

${OBJ}/${target}.elf : libsimavr
${OBJ}/${target}.elf : ${OBJ}/${target}.o

${target} : ${OBJ}/${target}.elf
Expand Down Expand Up @@ -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; \
Expand Down

0 comments on commit d422895

Please sign in to comment.