# along with simavr. If not, see <http://www.gnu.org/licenses/>.
# get the first character of what the compiler says it is, unless it's 'x86_64' doh
-ARCH = ${shell $(CC) -dumpmachine | sed -e 's/^x/i/' -e 's/\(.\).*/\1/'}
+ARCH = ${shell $(CC) -dumpmachine | sed -e 's/^x/i/' -e 's/\(.\).*/\1/'}
ifeq ($(ARCH), i)
-CFLAGS += -mfpmath=sse -msse2
+CFLAGS += -mfpmath=sse -msse2
endif
CFLAGS += -g --std=gnu99 -Wall
LDFLAGS += -lelf
ifeq (${shell uname}, Darwin)
-AVR_ROOT := "/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/"
-AVR_INC := ${AVR_ROOT}/avr-4/
-AVR := ${AVR_ROOT}/bin/avr-
-LFLAGS += -L/opt/local/lib
+AVR_ROOT := "/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/"
+AVR_INC := ${AVR_ROOT}/avr-4/
+AVR := ${AVR_ROOT}/bin/avr-
+LFLAGS += -L/opt/local/lib
else
-AVR_ROOT := /usr/lib/avr
-AVR_INC := ${AVR_ROOT}
-AVR := avr-
-CFLAGS += -fPIC
+AVR_ROOT := /usr/lib/avr
+AVR_INC := ${AVR_ROOT}
+AVR := avr-
+CFLAGS += -fPIC
endif
-CC ?= gcc
-AR ?= ar
-RANLIB ?= ranlib
+CC ?= gcc
+AR ?= ar
+RANLIB ?= ranlib
+MKDIR ?= mkdir -p
+INSTALL ?= install
+
+# simavr directory
+SIMAVR ?= ${shell for p in . .. ../.. ../../..;do test -d $$p/simavr/sim && echo $$p/simavr; done}
+
+OBJ = obj-${shell $(CC) -dumpmachine}
+LIBDIR = ${shell pwd}/${SIMAVR}/${OBJ}
+LDFLAGS += -L${LIBDIR} -lsimavr
+
+ifeq (${shell uname}, Linux)
+# allow the shared library to be found in the build directory
+LFLAGS += -Wl,-rpath,${LIBDIR}
+endif
# The code is compiled "optimized" to the max.
#
${^} -o ${@}
@${AVR}size ${@}|sed '1d'
-OBJ = obj-${shell $(CC) -dumpmachine}
-
# this rule has precedence
${OBJ}/sim_%.o : cores/sim_%.c
ifeq ($(V),1)
#
-# Copyright 2008, 2009 Michel Pollet <buserror@gmail.com>
+# Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
#
# This file is part of simavr.
#
# You should have received a copy of the GNU General Public License
# along with simavr. If not, see <http://www.gnu.org/licenses/>.
+SIMAVR_VERSION = 1.0a10
+SIMAVR_REVISION = 1
+
target = run_avr
CFLAGS += -O3 -Wall -Werror
# it otherwise eat quite a bit of few cycles, even disabled
#CFLAGS += -DCONFIG_SIMAVR_TRACE=1
-all: obj libsimavr ${target}
+all: obj ${target}
include ../Makefile.common
IPATH += ../include
# Thats for MacPorts libelf
+ifeq (${shell test -d /opt/local && echo Exists}, Exists)
IPATH += /opt/local/include
LFLAGS = -L/opt/local/lib/
-
-# shared library won't work that easily on non-linux
-ifeq (${shell uname}, Linux)
-all: ${OBJ}/libsimavr.so
endif
-
+#
+# Static library
+#
${OBJ}/libsimavr.a : ${cores_o}
${OBJ}/libsimavr.a : ${sim_o}
@echo AR $@
@$(AR) cru $@ $^ && $(RANLIB) $@
-libsimavr: ${OBJ}/libsimavr.a
-
-${OBJ}/libsimavr.so : ${cores_o}
-${OBJ}/libsimavr.so : ${sim_o}
- @echo LD $@
- @$(CC) -shared -fPIC -o $@ $(LFLAGS) $^ $(LDFLAGS)
+#
+# Shared library (Linux)
+#
+${OBJ}/libsimavr.so.1 : ${cores_o}
+${OBJ}/libsimavr.so.1 : ${sim_o}
+ @echo SHARED $@
+ @$(CC) -shared -Wl,-soname,libsimavr.so.1 -o $@ $^
-${OBJ}/${target}.elf : ${OBJ}/${target}.o
-${OBJ}/${target}.elf : ${OBJ}/libsimavr.a
+${OBJ}/libsimavr.so : ${OBJ}/libsimavr.so.1
+ ln -sf libsimavr.so.1 $@
+
+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}.o : libsimavr
+${OBJ}/${target}.elf : ${OBJ}/${target}.o
${target} : ${OBJ}/${target}.elf
ln -sf $< $@
clean: clean-${OBJ}
rm -rf ${target} *.a *.so
+
+DESTDIR = /usr/local
+
+install : all
+ $(MKDIR) $(DESTDIR)/include/simavr/avr
+ $(INSTALL) sim/*.h $(DESTDIR)/include/simavr/
+ $(INSTALL) ../include/*.h $(DESTDIR)/include/simavr/avr/
+ $(MKDIR) $(DESTDIR)/lib
+ $(INSTALL) ${OBJ}/libsimavr.a $(DESTDIR)/lib/
+ $(MKDIR) $(DESTDIR)/lib/pkgconfig/
+ sed -e "s|PREFIX|${DESTDIR}|g" -e "s|VERSION|${SIMAVR_VERSION}|g" \
+ simavr.pc >$(DESTDIR)/lib/pkgconfig/simavr.pc
+ifeq (${shell uname}, Linux)
+ $(INSTALL) ${OBJ}/libsimavr.so.1 $(DESTDIR)/lib/
+ ln -sf libsimavr.so.1 $(DESTDIR)/lib/libsimavr.so
+endif
+ $(MKDIR) $(DESTDIR)/bin
+ $(INSTALL) ${OBJ}/${target}.elf $(DESTDIR)/bin/simavr
--- /dev/null
+simavr.pc:
+prefix=PREFIX
+exec_prefix=${prefix}
+includedir=${prefix}/include
+libdir=${exec_prefix}/lib
+
+Name: simavr
+Description: Atmel(tm) AVR 8 bits simulator
+Version: VERSION
+Cflags: -I${includedir}
+Libs: -L${libdir} -lsimavr
+
+simavr-avr.pc:
+prefix=PREFIX
+exec_prefix=${prefix}
+includedir=${prefix}/include
+libdir=${exec_prefix}/lib
+
+Name: simavr-avr
+Description: Atmel(tm) AVR 8 bits simulator - avr-gcc flags
+Version: VERSION
+Cflags: -I${includedir}/avr -ffunction-sections -fdata-sections \
+ -Wl,--relax,--gc-sections \
+ -Wl,--undefined=_mmcu,--section-start=.mmcu=0x910000
+Libs: -L${libdir} -lsimavr
+