Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #-------------------------------------#
- # OS Kernel Makefile #
- #-------------------------------------#
- #
- # Current functionality:
- #
- # Creation of binary images to be
- # loaded by bootloader
- #
- # Toolchain to use
- ARMGNU ?= arm-none-eabi
- # Directory for misc build objects
- BUILD = build/
- # Directory for c build objs
- CBUILD = build/c/
- # Directory for assembly build objs
- ASBUILD = build/as/
- # Directory for src objects
- SOURCE = src/
- # Name of output file
- TARGET = harpos.bin
- # Name of assembler list file to generate
- LIST = $(BUILD)harpos.list
- # Name of map file to generate
- MAP = $(BUILD)harpos.map
- # Name of linker script to use
- LINKER = memorymap.ld
- # Additional libraries
- LIBRARIES =
- #csud
- # Additional compiler flags for c files
- # General warning flags (wall), midlevel optimisations (02), no standard system startup files or libraries (nostdlib nostartfiles)
- # assert freestanding environment where stdlib may not exist and program startup may not be at main (freestanding) treat wchar as 16bit value (short-wchar)
- COPTS = -Wall -O2 -nostdlib -nostartfiles -ffreestanding -fshort-wchar
- # Names of object files to be built
- # Uses pattern substitute to find source files and add object names
- # Assembly files then c files
- OBJS = $(patsubst $(SOURCE)%.s,$(ASBUILD)%.o,$(wildcard $(SOURCE)*.s)) $(patsubst $(SOURCE)%.c,$(CBUILD)%.o,$(wildcard $(SOURCE)*.c))
- # Rule for all
- all: $(TARGET)
- # Rule to make target image : depends on elf
- # Objcopy elf to binary image
- $(TARGET) : $(BUILD)harpos.elf
- $(ARMGNU)-objcopy $(BUILD)harpos.elf -O binary $(TARGET)
- # Rule to make elf : depends on objects and linker script
- # Link all objects, link to additional libraries, create map file, output to harpos.elf, replace default linker script with ours
- # Objdump elf to list file
- # Objcopy elf to hex file
- $(BUILD)harpos.elf : $(LINKER) $(OBJS)
- echo $(OBJS)
- $(ARMGNU)-ld $(OBJS) -L. $(patsubst %,-l %,$(LIBRARIES)) -Map $(MAP) -o $(BUILD)harpos.elf -T $(LINKER)
- $(ARMGNU)-objdump -D $(BUILD)harpos.elf > $(LIST)
- $(ARMGNU)-objcopy $(BUILD)harpos.elf -O ihex $(BUILD)harpos.hex
- # Rule to make the c object files.
- $(CBUILD)%.o: $(SOURCE)%.c
- $(ARMGNU)-gcc $(COPTS) -c $< -o $@
- # Rule to make the assembly object files.
- $(ASBUILD)%.o: $(SOURCE)%.s
- $(ARMGNU)-as -I $(SOURCE) $< -o $@
- # Rule to clean
- clean:
- rm -f $(CBUILD)*.o
- rm -f $(ASBUILD)*.o
- rm -f $(BUILD)*.elf
- rm -f $(BUILD)*.hex
- rm -f $(TARGET)
- rm -f $(LIST)
- rm -f $(MAP)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement