From: Michel Pollet Date: Mon, 27 Feb 2012 10:53:28 +0000 (+0000) Subject: Makefiles: general update X-Git-Tag: v1.0b1~38 X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=6f9832bd93bebac02589a16a2cdc6967b1df4285;p=sx%2Fsimavr.git Makefiles: general update + Now uses the shared library if present, and added some logic to find where it was built. + Added an "official" version number + Added a "make install DESTDIR=..." target + Added a "simavr.pc" pkg-config file --- diff --git a/Makefile.common b/Makefile.common index 9f48342..f781c16 100644 --- a/Makefile.common +++ b/Makefile.common @@ -27,10 +27,10 @@ # along with simavr. If not, see . # 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 @@ -38,20 +38,34 @@ CFLAGS += ${patsubst %,-I%,${subst :, ,${IPATH}}} 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. # @@ -80,8 +94,6 @@ RANLIB ?= ranlib ${^} -o ${@} @${AVR}size ${@}|sed '1d' -OBJ = obj-${shell $(CC) -dumpmachine} - # this rule has precedence ${OBJ}/sim_%.o : cores/sim_%.c ifeq ($(V),1) diff --git a/simavr/Makefile b/simavr/Makefile index 4e57f89..a52c1f7 100644 --- a/simavr/Makefile +++ b/simavr/Makefile @@ -1,5 +1,5 @@ # -# Copyright 2008, 2009 Michel Pollet +# Copyright 2008-2012 Michel Pollet # # This file is part of simavr. # @@ -16,6 +16,9 @@ # You should have received a copy of the GNU General Public License # along with simavr. If not, see . +SIMAVR_VERSION = 1.0a10 +SIMAVR_REVISION = 1 + target = run_avr CFLAGS += -O3 -Wall -Werror @@ -24,7 +27,7 @@ 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 @@ -41,32 +44,59 @@ IPATH += ../../shared 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 diff --git a/simavr/simavr.pc b/simavr/simavr.pc new file mode 100644 index 0000000..87607fb --- /dev/null +++ b/simavr/simavr.pc @@ -0,0 +1,26 @@ +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 + diff --git a/tests/Makefile b/tests/Makefile index e2d04c2..007dbb2 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -28,8 +28,6 @@ simavr = .. IPATH += ${simavr}/include IPATH += ${simavr}/simavr/sim -CFLAGS += -Wall -LDFLAGS += -L${simavr}/simavr/${OBJ} -lsimavr tests_src = ${wildcard test_*.c} tests = ${patsubst %.c, ${OBJ}/%.tst, ${tests_src}}