added gcc flags to make binaries more relocatable

master
Anton Lydike 3 years ago
parent 1cf5458247
commit e08a58a29d

@ -1,5 +1,4 @@
# simple makefile for this kernel project # small makefile for compiling the kernel
# This is BAD. it should be reworked before anyone else uses this.
# kernel lib dir # kernel lib dir
KLIBDIR=kinclude KLIBDIR=kinclude
@ -12,9 +11,9 @@ GCC_PREF=riscv32-unknown-elf-
CC=$(GCC_PREF)gcc CC=$(GCC_PREF)gcc
OBJDUMP=$(GCC_PREF)objdump OBJDUMP=$(GCC_PREF)objdump
CFLAGS=-I$(KLIBDIR) -O3 -MD CFLAGS=-I$(KLIBDIR) -O3 -MD -mcmodel=medany -mexplicit-relocs
KERNEL_CFLAGS=-nostdlib -T linker.ld KERNEL_CFLAGS=-nostdlib -T linker.ld
ARCH = rv32im ARCH = rv32im # here you
### Build configuration: ### Build configuration:
@ -41,20 +40,29 @@ DEPS = $(patsubst %,$(KLIBDIR)/%,$(_DEPS))
OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ)) OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))
.PHONY: clean
.PHONY: directories
.PHONY: kernel
directories:
mkdir -p $(ODIR) $(TARGET)
$(ODIR)/boot.o: $(KLIBDIR)/boot.S $(ODIR)/boot.o: $(KLIBDIR)/boot.S
$(CC) -c -o $@ $(KLIBDIR)/boot.S $(CFLAGS) -D__assembly=1 $(CC) -c -o $@ $(KLIBDIR)/boot.S $(CFLAGS) -D__assembly
$(ODIR)/%.o: $(KLIBDIR)/%.c $(KLIBDIR)/%.h $(ODIR)/%.o: $(KLIBDIR)/%.c $(KLIBDIR)/%.h
$(CC) -c -o $@ $(KLIBDIR)/$*.c $(CFLAGS) $(CC) -c -o $@ $(KLIBDIR)/$*.c $(CFLAGS)
kernel: $(OBJ) _kernel: $(OBJ)
mkdir -p $(TARGET) $(CC) -o $(TARGET)/kernel $^ kernel.c $(CFLAGS) $(KERNEL_CFLAGS)
$(CC) -o $(TARGET)/$@ $^ kernel.c $(CFLAGS) $(KERNEL_CFLAGS)
kernel: directories _kernel
kernel-dump: kernel kernel-dump: kernel
$(OBJDUMP) -SFlDf $(TARGET)/kernel > $(TARGET)/kernel-objects $(OBJDUMP) -SFlDf $(TARGET)/kernel > $(TARGET)/kernel-objects
.PHONY: clean all: kernel-dump
clean: clean:
rm -rf $(ODIR) *~ $(KLIBDIR)/*~ $(TARGET) rm -rf $(ODIR) *~ $(KLIBDIR)/*~ $(TARGET)

Loading…
Cancel
Save