用于OpenRISC的Makefile示例

用于开源处理器OpenRISC精简版AltOR32的软件开发,使用的工具链为or1k-elf-gcc,Makefile和连接脚本为:
 1 #***********************************************************************************************
 2 #    File        : Makefile
 3 #    Author        : Lyu Yang
 4 #    Date          :
 5 #    Description : Makefile for OpenRISC
 6 #***********************************************************************************************
 7 
 8 TARGET = main
 9 
10 CROSS_COMPILE = or1k-elf-
11 
12 INCLUDE_DIRS = -I ./
13 LIBRARY_DIRS = -L ./
14 
15 CC = $(CROSS_COMPILE)gcc
16 CFLAGS =  $(INCLUDE_DIRS) -mno-delay -c -msoft-div -msoft-float -msoft-mul -mno-ror -mno-cmov -mno-sext -Os
17 
18 CXX = $(CROSS_COMPILE)g++
19 CXXFLAGS =  $(INCLUDE_DIRS) -c -mno-delay -msoft-float -msoft-mul -mno-ror -mno-cmov -mno-sext -Os
20 
21 AS = $(CROSS_COMPILE)as
22 ASFLAGS = -c
23 
24 LD = $(CROSS_COMPILE)ld
25 LDFLAGS = $(LIBRARY_DIRS) -T./openrisc.lds -Map $(TARGET).map -nostartfiles -nodefaultlibs -nostdlib
26 
27 OBJCP = $(CROSS_COMPILE)objcopy
28 OBJCPFLAGS = -O binary -j .text -j .rodata -j .data -j .bss
29 
30 AR = $(CROSS_COMPILE)ar
31 ARFLAGS = cr
32 
33 DUMP = $(CROSS_COMPILE)objdump
34 DUMPFLAG = --disassemble --syms --all-header
35 
36 SIZE = $(CROSS_COMPILE)size
37 
38 # Static library files
39 OBJS_LIB +=
40 
41 # User should list all object files
42 OBJS += $(patsubst %.S, %.o, $(wildcard *.S))
43 OBJS += $(patsubst %.c, %.o, $(wildcard *.c))
44 
45 # Make
46 .PHONY: all clean debug
47 all: $(TARGET).elf $(TARGET).bin $(TARGET).asm $(TARGET).mif
48     $(SIZE) $(TARGET).elf
49 
50 %.o: %.S
51     $(AS) $(ASFLAGS) $^ -o $@
52 
53 %.o: %.c
54     $(CC) $(CFLAGS) $^ -o $@
55 
56 $(TARGET).elf: $(OBJS)
57     $(LD) $(LDFLAGS) $(OBJS_LIB) -o $@ $^
58 
59 $(TARGET).asm: $(TARGET).elf
60     $(DUMP) $(DUMPFLAG) $(TARGET).elf > $(TARGET).asm
61 
62 $(TARGET).bin: $(TARGET).elf
63     $(OBJCP) $(OBJCPFLAGS) $< $@
64 
65 $(TARGET).mif: $(TARGET).bin
66     ./bin2fpga/bin2fpga 4096 $<
67 
68 clean:
69     rm -rf *.o *.asm *.elf *.bin *.mif *.map *.coe data.txt
70 
71 debug:
72     $(CROSS_COMPILE)gdb $(TARGET).elf -x gdbinit.txt
 1 /* Linker script for OpenRISC */
 2 
 3 OUTPUT_FORMAT("elf32-or1k")
 4 OUTPUT_ARCH(or1k)
 5 ENTRY(_reset)
 6 
 7 MEMORY
 8 {
 9     RAM (rwx) : ORIGIN = 0x0, LENGTH = 0x4000
10     DRAM (rwx) : ORIGIN = 0x10000000, LENGTH = 0x10000000
11 }
12 
13 
14 SECTIONS
15 {
16     .text :
17     {
18         _stext = .;
19         stext = .;
20         *(.text)
21         *(.text.*)
22         . = ALIGN(4);
23         _etext = .;
24         etext = .;
25     } > RAM
26 
27     .rodata :
28     {
29         _sdata = .;
30         sdata = .;
31         . = ALIGN(4);
32         *(.rodata)
33         *(.rodata.*)
34     } > RAM
35 
36     .data :
37     {
38         *(.sdata)
39         *(.data)
40         *(.rwdata)
41         *(.got.plt) *(.got)
42         *(.shdata)
43         *(.data.* .gnu.linkonce.d.*)
44         . = ALIGN (4);
45         _edata  =  .;
46         edata  =  .;
47     } > RAM
48 
49     .bss :
50     {
51         . = ALIGN(4);
52         __bss_start = .;
53         *(.sbss .sbss.*)
54         *(.bss .bss.*)
55         *(COMMON)
56         . = ALIGN (4);
57         __bss_end = .;
58     } > RAM
59 }
60 
61 /* Stack base address */
62 __stack_pointer = 0x4000;

 

 
posted @ 2016-02-18 12:30  BH5HSV  阅读(461)  评论(0编辑  收藏  举报