Hardcode target in makefile

This commit is contained in:
Jenny Curle 2019-04-01 01:40:42 +00:00
parent 26586447f5
commit a9d826c317

188
makefile
View File

@ -1,94 +1,94 @@
DEFAULT_HOST!=../default-host.sh DEFAULT_HOST!=i686-elf
HOST?=DEFAULT_HOST HOST?=DEFAULT_HOST
HOSTARCH!=../target_to_arch.sh $(HOST) HOSTARCH!=i386
CFLAGS?= -O2 -g CFLAGS?= -O2 -g
CPPFLAGS?= CPPFLAGS?=
LDFLAGS?= LDFLAGS?=
LIBS?= LIBS?=
DESTDIR?= DESTDIR?=
PREFIX?=/usr/local PREFIX?=/usr/local
EXEC_PREFIX?=$(PREFIX) EXEC_PREFIX?=$(PREFIX)
BOOTDIR?=$(EXEC_PREFIX)/boot BOOTDIR?=$(EXEC_PREFIX)/boot
INCLUDEDIR?=$(PREFIX)/include INCLUDEDIR?=$(PREFIX)/include
CFLAGS:=$(CFLAGS) -ffreestanding -Wall -Wextra CFLAGS:=$(CFLAGS) -ffreestanding -Wall -Wextra
CPPFLAGS:=$(CPPFLAGS) -D__is_kernel -Iinclude CPPFLAGS:=$(CPPFLAGS) -D__is_kernel -Iinclude
LDFLAGS:=$(LDFLAGS) LDFLAGS:=$(LDFLAGS)
LIBS:=$(LIBS) -nostdlib -lk -lgcc LIBS:=$(LIBS) -nostdlib -lk -lgcc
ARCHDIR=arch/$(HOSTARCH) ARCHDIR=arch/$(HOSTARCH)
include $(ARCHDIR)/make.config include $(ARCHDIR)/make.config
CFLAGS:=$(CFLAGS) $(KERNEL_ARCH_CFLAGS) CFLAGS:=$(CFLAGS) $(KERNEL_ARCH_CFLAGS)
CPPFLAGS:=$(CPPFLAGS) $(KERNEL_ARCH_CPPFLAGS) CPPFLAGS:=$(CPPFLAGS) $(KERNEL_ARCH_CPPFLAGS)
LDFLAGS:=$(LDFLAGS) $(KERNEL_ARCH_LDFLAGS) LDFLAGS:=$(LDFLAGS) $(KERNEL_ARCH_LDFLAGS)
LIBS:=$(LIBS) $(KERNEL_ARCH_LIBS) LIBS:=$(LIBS) $(KERNEL_ARCH_LIBS)
KERNEL_OBJS=\ KERNEL_OBJS=\
$(KERNEL_ARCH_OBJS)\ $(KERNEL_ARCH_OBJS)\
kernel/kernel.o kernel/kernel.o
OBJS=\ OBJS=\
$(ARCHDIR)/crti.o \ $(ARCHDIR)/crti.o \
$(ARCHDIR)/crtbegin.o \ $(ARCHDIR)/crtbegin.o \
$(KERNEL_OBJS) \ $(KERNEL_OBJS) \
$(ARCHDIR)/crtend.o \ $(ARCHDIR)/crtend.o \
$(ARCHDIR)/crtn.o $(ARCHDIR)/crtn.o
LINK_LIST=\ LINK_LIST=\
$(LDFLAGS) \ $(LDFLAGS) \
$(ARCHDIR)/crti.o \ $(ARCHDIR)/crti.o \
$(ARCHDIR)/crtbegin.o \ $(ARCHDIR)/crtbegin.o \
$(KERNEL_OBJS) \ $(KERNEL_OBJS) \
$(LIBS) \ $(LIBS) \
$(ARCHDIR)/crtend.o \ $(ARCHDIR)/crtend.o \
$(ARCHDIR)/crtn.o $(ARCHDIR)/crtn.o
.PHONY: all clean install install-headers install-kernel .PHONY: all clean install install-headers install-kernel
.SUFFIXES: .o .c .s .SUFFIXES: .o .c .s
all: red.kernel all: red.kernel
red.kernel: $(OBJS) $(ARCHDIR)/linker.ld red.kernel: $(OBJS) $(ARCHDIR)/linker.ld
$(CC) -T $(ARCHDIR)/linker.ld -o $@ $(CFLAGS) $(LINK_LIST) $(CC) -T $(ARCHDIR)/linker.ld -o $@ $(CFLAGS) $(LINK_LIST)
$(ARCHDIR)/crtbegin.o $(ARCHDIR)/crtend.o: $(ARCHDIR)/crtbegin.o $(ARCHDIR)/crtend.o:
OBJ=`$(CC) $(CFLAGS) $(LDFLAGS) -print-file-name=$(@F)` && cp "$$OBJ" $@ OBJ=`$(CC) $(CFLAGS) $(LDFLAGS) -print-file-name=$(@F)` && cp "$$OBJ" $@
.c.o: .c.o:
$(CC) -MD -c $< -o $@ -std=gnull $(CFLAGS) $(CPPFLAGS) $(CC) -MD -c $< -o $@ -std=gnull $(CFLAGS) $(CPPFLAGS)
.s.o: .s.o:
$(CC) -MD -c $< -o $@ $(CFLAGS) $(CPPFLAGS) $(CC) -MD -c $< -o $@ $(CFLAGS) $(CPPFLAGS)
clean: clean:
rm -f red.kernel rm -f red.kernel
rm -f $(OBJS) *.0 */*.o */*/*.o rm -f $(OBJS) *.0 */*.o */*/*.o
rm -f $(OBJS:.o=.d) *.d */*.d */*/*.d rm -f $(OBJS:.o=.d) *.d */*.d */*/*.d
install: install-headers install-kernel gen-iso install: install-headers install-kernel gen-iso
install-headers: install-headers:
mkdir -p $(DESTDIR)$(INCLUDEDIR) mkdir -p $(DESTDIR)$(INCLUDEDIR)
cp -R --preserve=timestamps include/. $(DESTDIR)$(INCLUDEDIR)/. cp -R --preserve=timestamps include/. $(DESTDIR)$(INCLUDEDIR)/.
install-kernel: red.kernel install-kernel: red.kernel
mkdir -p $(DESTDIR)$(BOOTDIR) mkdir -p $(DESTDIR)$(BOOTDIR)
cp red.kernel $(DESTDIR)$(BOOTDIR) cp red.kernel $(DESTDIR)$(BOOTDIR)
gen-iso: gen-iso:
rm -f red.iso \ rm -f red.iso \
cp red.kernel iso/boot/kernel.elf \ cp red.kernel iso/boot/kernel.elf \
genisoimage -R\ genisoimage -R\
-b boot/grub/stage2_eltorito\ -b boot/grub/stage2_eltorito\
-no-emul-boot\ -no-emul-boot\
-A ProjectRED\ -A ProjectRED\
-input-charset utf8\ -input-charset utf8\
-quiet -quiet
-boot-info-table\ -boot-info-table\
-o red.iso\ -o red.iso\
iso iso
-include $(OBJS:.o=.d) -include $(OBJS:.o=.d)