refactor logger
[simavr] / Makefile.common
index e019689..205ef6b 100644 (file)
@@ -27,7 +27,7 @@
 #      along with simavr.  If not, see <http://www.gnu.org/licenses/>.
 
 # simavr directory
-SIMAVR         ?= ${shell for p in . .. ../.. ../../..;do test -d $$p/simavr/sim && echo $$p/simavr; done}
+SIMAVR         := ${shell for p in . .. ../.. ../../..;do test -d $$p/simavr/sim && echo $$p/simavr; done}
 
 # You can override the build settings with local changes in this file
 # for example:
@@ -41,6 +41,7 @@ ARCH          = ${shell $(CC) -dumpmachine | sed -e 's/^x/i/' -e 's/\(.\).*/\1/'}
 
 CFLAGS         += -O2 -Wall
 CFLAGS         += -g
+CORE_CFLAGS    = -nostdinc
 
 ifeq (${shell uname}, Darwin)
 # gcc 4.2 from MacOS is really not up to scratch anymore 
@@ -57,8 +58,18 @@ else
 AVR_ROOT       := /usr/lib/avr
 AVR_INC        := ${AVR_ROOT}
 AVR            := avr-
+ifeq (${shell uname -o}, Msys)
+AVR_ROOT    := ${shell echo "${AVR32_HOME}" | tr '\\' '/'}
+AVR_INC     := ${AVR_ROOT}/avr
+AVR         := ${AVR_ROOT}/bin/avr-
+IPATH       += ${PREFIX}/include
+CFLAGS      += -I${PREFIX}/include
+LDFLAGS                += -L/lib -L/local/lib
+CFLAGS                 += -DNO_COLOR
+else
 CFLAGS                 += -fPIC
 endif
+endif
 
 CPPFLAGS       += --std=gnu99 -Wall
 CPPFLAGS       += ${patsubst %,-I%,${subst :, ,${IPATH}}}
@@ -78,10 +89,20 @@ LDFLAGS     += -L${LIBDIR} -lsimavr
 
 LDFLAGS        += -lelf 
 
+ifeq (${shell uname -o}, Msys)
+LDFLAGS      += -lws2_32
+endif
+
 ifeq (${shell uname}, Linux)
+ifeq ($(RELEASE),1)
+# allow the shared library to be found in the build directory
+# only for linking, the install time location is used at runtime
+LFLAGS         += -Wl,-rpath-link,${LIBDIR}
+else
 # allow the shared library to be found in the build directory
 LFLAGS         += -Wl,-rpath,${LIBDIR}
 endif
+endif
 
 # The code is compiled "optimized" to the max.
 # 
@@ -106,18 +127,18 @@ endif
                        -ffunction-sections -fdata-sections \
                        -Wl,--relax,--gc-sections \
                        -Wl,--undefined=_mmcu,--section-start=.mmcu=0x910000 \
-                       -I../include -I../../include \
+                       -I../simavr/sim/avr -I../../simavr/sim/avr \
                        ${^} -o ${@}
        @${AVR}size ${@}|sed '1d'
 
 # this rule has precedence
 ${OBJ}/sim_%.o : cores/sim_%.c
 ifeq ($(V),1)
-       $(CC) $(CPPFLAGS) $(CFLAGS) -MMD \
+       $(CC) $(CPPFLAGS) $(CFLAGS) $(CORE_CFLAGS) -MMD \
                ${AVR_CPPFLAGS} \
                $<  -c -o $@
 else
-       @$(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS) -MMD \
+       @$(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS) $(CORE_CFLAGS) -MMD \
                ${AVR_CPPFLAGS} \
                $<  -c -o $@
        @echo CORE $<