Makefile updates
[simavr] / Makefile.common
index e9fabcc..022f1f1 100644 (file)
 #      You should have received a copy of the GNU General Public License
 #      along with simavr.  If not, see <http://www.gnu.org/licenses/>.
 
-CFLAGS += -g --std=gnu99 -O2
+# get the first character of what the compiler says it is
+ARCH = ${shell $(CC) -dumpmachine | sed 's/\(.\).*/\1/'}
+
+ifeq ($(ARCH), i)
+CFLAGS += -mfpmath=sse -msse2 -fPIC
+endif
+
+CFLAGS += -g --std=gnu99
 CFLAGS += ${patsubst %,-I%,${subst :, ,${IPATH}}}
 LDFLAGS += -lelf 
 
@@ -41,6 +48,10 @@ AVR_INC := ${AVR_ROOT}
 AVR := avr-
 endif
 
+CC ?= gcc
+AR ?= ar
+RANLIB ?= ranlib
+
 # The code is compiled "optimized" to the max.
 # 
 # The wierd "-Wl,--undefined=_mmcu,--section-start=.mmcu=0x910000"
@@ -68,15 +79,47 @@ endif
                        ${^} -o ${@}
        @${AVR}size ${@}|sed '1d'
 
-OBJ = obj
+OBJ = obj-${shell $(CC) -dumpmachine}
+
+# this rule has precedence
+${OBJ}/sim_%.o : cores/sim_%.c
+ifeq ($(V),1)
+       $(CC) $(CFLAGS) -MD \
+               -I${AVR_INC}/include/ \
+               $<  -c -o $@
+else
+       @$(CC) $(CFLAGS) -MD \
+               -I${AVR_INC}/include/ \
+               $<  -c -o $@
+       @echo CORE $<
+endif
 
 ${OBJ}/%.o: %.c
+ifeq ($(V),1)
+       $(CC) $(CFLAGS) -MD \
+               $<  -c -o $@
+else
        @$(CC) $(CFLAGS) -MD \
                $<  -c -o $@
        @echo CC $<
+endif
 
+${OBJ}/%.elf:
+ifeq ($(V),1)
+       echo $^ / $<
+       $(CC) -MD ${CFLAGS}  ${LFLAGS} -o $@ $^ $(LDFLAGS)
+else
+       @echo LD $@
+       @$(CC) -MD ${CFLAGS}  ${LFLAGS} -o $@ $^ $(LDFLAGS)
+endif
+
+obj: ${OBJ}
 ${OBJ}: 
        @mkdir -p ${OBJ}
 
+clean-${OBJ}:
+       rm -rf ${OBJ}
+
 # include the dependency files generated by gcc, if any
 -include ${wildcard ${OBJ}/*.d}