PLATFORM = lm8-elf CFLAGS = \ -mcall-stack-size=16 \ -I. -Iinclude # This causes the stack-setup code to be invoked as a function # rather than in-lined. It saves code space as the expense of # performance overhead when calling other functions CFLAGS += -mcall-prologues CFLAGS += \ -Wall \ -Wundef \ -Werror \ -Wno-trigraphs \ -Wsign-compare \ -Wuninitialized \ -Wnested-externs \ -Wno-pointer-sign \ -Wchar-subscripts \ -Wstrict-prototypes #CFLAGS += -ggdb -O0 CFLAGS += -O3 CFLAGS += \ -fno-common \ -fno-builtin \ -ffreestanding \ -fno-strict-aliasing \ -fomit-frame-pointer CFLAGS += \ -fdata-sections \ -ffunction-sections LDFLAGS += -static -nostdlib --gc-sections LM8_ROOT = /usr/local/lm8/gtools #CFLAGS += -mcmodel=small -m16regs #LIBGCC += $(LM8_ROOT)/lib/gcc/lm8-elf/4.4.3/small/r16/libgcc.a #CFLAGS += -mcmodel=small #LIBGCC += $(LM8_ROOT)/lib/gcc/lm8-elf/4.4.3/small/libgcc.a CFLAGS += -mcmodel=medium -m16regs LIBGCC += $(LM8_ROOT)/lib/gcc/lm8-elf/4.4.3/r16/libgcc.a #CFLAGS += -mcmodel=medium #LIBGCC += $(LM8_ROOT)/lib/gcc/lm8-elf/4.4.3/libgcc.a #CFLAGS += -mcmodel=large #LIBGCC += $(LM8_ROOT)/lib/gcc/lm8-elf/4.4.3/large/libgcc.a CC=$(PLATFORM)-gcc LD=$(PLATFORM)-ld OBJCOPY=$(PLATFORM)-objcopy OBJDUMP=$(PLATFORM)-objdump HOSTCC=gcc HOSTCFLAGS=-Wall -Wstrict-prototypes -O2 -fomit-frame-pointer %.o : %.c @echo " -CC- Compiling '$<'" @$(CC) -c $(CFLAGS) -o $@ $< %.o : %.dat @echo " -BIN- Embedding data file '$<'" $(OBJCOPY) -I binary -O $(PLATFORM) $< $@ %.S : %.c @echo " -CC- Compiling '$<'" @$(CC) -S -c $(CFLAGS) -o $@ $< %.o: %.S @echo " -ASM- Assembling '$<'" @$(CC) -c $(CFLAGS) -D__ASSEMBLY__=1 -o $@ $< %.dasm: %.elf @echo " -DASM- Disassembling '$<' -> '$@'" @$(OBJDUMP) -S --line-number $< > $@ # objcopy args drop-sections = .reginfo .comment .note .pdr strip-flags = $(addprefix --remove-section=,$(drop-sections)) %.bin : %.elf @echo " -STRIP- Stripping '$<' -> '$@'" @$(OBJCOPY) --gap-fill 0xff -O binary $(strip-flags) $< $@ %.text : %.elf @echo " -TEXT- Extracting .text $<' -> '$@'" @$(OBJCOPY) --gap-fill 0 -O binary -j .text $< $@ %.data : %.elf @echo " -TEXT- Extracting .data $<' -> '$@'" @$(OBJCOPY) --gap-fill 0 -O binary -j .data $< $@ %.gz : %.bin @echo " -GZIP- Compressing '$<' -> '$@'" @cat $< | gzip -c9n > $@ %_code.mem : %.text bin/dis @echo " -FLAT- Flattening '$<' -> '$@'" @./bin/dis $< > $@ %_data.mem : %.data bin/dis @echo " -FLAT- Flattening '$<' -> '$@'" @./bin/dis --raw $< > $@ OBJS = \ test.o \ mico8/crt0.o \ mico8/usleep.o \ mico8/msleep.o \ mico8/set_ip.o \ mico8/get_ip.o \ mico8/system.o \ mico8/int.o \ mico8/uart.o all: $(OBJS) bin/test.text bin/test_code.mem bin/test.data bin/test_data.mem bin/dis : dis.c @echo " -CC- Compiling '$<'" @$(HOSTCC) $(HOSTCFLAGS) -o $@ $< bin/test.elf: $(OBJS) linker.ld @echo " -LD- Linking '$@'" @$(LD) -T linker.ld $(LDFLAGS) -o $@ -Map bin/test.map $(OBJS) $(LIBGCC) clean: -rm -f bin/* $(OBJS) *~