Description: libsimavr build
 - link to elf library
 - sort the symbols for reproducible builds
Author: Milan Kupcevic <milan@debian.org>
Forwarded: not-needed
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/simavr/Makefile
+++ b/simavr/Makefile
@@ -26,15 +26,14 @@
 # it otherwise eat quite a bit of few cycles, even disabled
 #CFLAGS	+= -DCONFIG_SIMAVR_TRACE=1
 
-all:
-	$(MAKE) obj config
-	$(MAKE) libsimavr ${target}
+all: $(target)
+
+EXTRA_LDFLAGS += -lelf
 
 include ../Makefile.common
 
 cores	:= ${wildcard cores/*.c}
 sim		:= ${wildcard sim/sim_*.c} ${wildcard sim/avr_*.c}
-sim_o 	:= ${patsubst sim/%.c, ${OBJ}/%.o, ${sim}}
 
 VPATH	= cores
 VPATH	+= sim
@@ -46,18 +45,23 @@
 #
 # Static library
 #
-${OBJ}/libsimavr.a	:	${sim_o}
 
 
-libsimavr	: config ${OBJ}/libsimavr.a
+libsimavr	: ${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
 
+${OBJ}/libsimavr.so.2:
+	${E}$(CC) -o $@ -shared \
+		-Wl,-soname,libsimavr.so.2 $^ \
+		${filter-out -l%, $(LDFLAGS)} ${EXTRA_LDFLAGS}
+
+${OBJ}/libsimavr.so: ${OBJ}/libsimavr.so.2
+	ln -sf ${notdir $<} $@
+
 ${target}	: ${OBJ}/${target}.elf
 
 # FIXME uname -o doesn't work on BSD
@@ -125,7 +129,15 @@
         usr/bin ) && \
 	echo Done
 
-config: ${OBJ}/cores.deps sim_core_config.h sim_core_decl.h
+${OBJ}/sim.deps: $(sim) sim_core_decl.h
+	if [ ! -d "${OBJ}" ] ; then mkdir -p "${OBJ}"; fi; \
+	for file in $$(ls sim/sim_*.c sim/avr_*.c | LC_ALL=C sort) ; do \
+	  objst=$${file/.c/.sto} ; objst=$${objst/sim\/}; \
+	  obj=$${file/.c/.o} ; obj=$${obj/sim\/}; \
+	  printf "\$${OBJ}/libsimavr.a: \$${OBJ}/$$objst\n">>${OBJ}/sim.deps.tmp ; \
+	  printf "\$${OBJ}/libsimavr.so.2: \$${OBJ}/$$obj\n">>${OBJ}/sim.deps.tmp ; \
+	done ; \
+	mv ${OBJ}/sim.deps.tmp ${OBJ}/sim.deps
 
 #
 # this tries to preprocess all the cores and decide
@@ -142,14 +154,16 @@
 	@echo CONF $@
 	@conf=""; decl=""; array=""; \
 	mkdir -p ${OBJ} ; echo >${OBJ}/cores.deps ; echo >$(DEBUGLOG) ;\
-	for core in cores/*.c ; do \
+	for core in $$(ls cores/*.c | LC_ALL=C sort) ; do \
 		file=$$core; global=$${core/cores\/sim_}; global=$${global/.c}; \
 		upper=$$(echo $$global|tr '[a-z]' '[A-Z]'); \
 		if $(CC) -E $(CFLAGS) ${AVR_CPPFLAGS} $$file \
 			>>$(DEBUGLOG) 2>&1 ; then \
 			conf+="#define CONFIG_$$upper 1\n"; \
+			objst=$${file/.c/.sto} ; objst=$${objst/cores\/}; \
 			obj=$${file/.c/.o} ; obj=$${obj/cores\/}; \
-			printf "\$${OBJ}/libsimavr.a: \$${OBJ}/$$obj\n">>${OBJ}/cores.deps ; \
+			printf "\$${OBJ}/libsimavr.a: \$${OBJ}/$$objst\n">>${OBJ}/cores.deps ; \
+			printf "\$${OBJ}/libsimavr.so.2: \$${OBJ}/$$obj\n">>${OBJ}/cores.deps ; \
 		else \
 			conf+="#undef CONFIG_$$upper\n"; \
 			echo WARNING $$file did not compile, check your avr-gcc toolchain; \
@@ -170,7 +184,7 @@
 sim_core_decl.h: sim_core_config.h $(cores) Makefile
 	@echo CONF $@
 	@decl=""; array=""; \
-	for core in $$(grep -r avr_kind_t cores/|awk -F '[ :]' '{print $$1 "=" $$3;}') ; do \
+	for core in $$(grep -r avr_kind_t cores/|awk -F '[ :]' '{print $$1 "=" $$3;}' | LC_ALL=C sort) ; do \
 		file=$${core/=*}; global=$${core/*=}; \
 		upper=$$global; upper=$${upper/.c}; \
 		upper=$$(echo $$global|tr '[a-z]' '[A-Z]'); \
@@ -187,3 +201,4 @@
 	) >sim_core_decl.h
 
 -include ${OBJ}/cores.deps
+-include ${OBJ}/sim.deps
