forked from Bananymous/banan-os
Improve buildsystem by making build directory
We now create build directory for kernel and libc so that source directories are kept more clean.
This commit is contained in:
parent
c292ef5471
commit
c17f61611e
|
@ -2,3 +2,4 @@
|
|||
isodir
|
||||
sysroot
|
||||
.vscode/
|
||||
.idea/
|
|
@ -13,8 +13,8 @@ EXEC_PREFIX?=$(PREFIX)
|
|||
BOOTDIR?=$(EXEC_PREFIX)/boot
|
||||
INCLUDEDIR?=$(PREFIX)/include
|
||||
|
||||
CFLAGS:=$(CFLAGS) -fstack-protector -ffreestanding -Wall -Wextra -Wno-unused-function
|
||||
CPPFLAGS:=$(CPPFLAGS) -D__is_kernel -Iinclude
|
||||
CFLAGS:=$(CFLAGS) -D__is_kernel -Iinclude -fstack-protector -ffreestanding -Wall -Wextra -Wno-unused-function
|
||||
CPPFLAGS:=$(CPPFLAGS)
|
||||
LDFLAGS:=$(LDFLAGS)
|
||||
LIBS:=$(LIBS) -nostdlib -lk -lgcc
|
||||
|
||||
|
@ -27,6 +27,8 @@ CPPFLAGS:=$(CPPFLAGS) $(KERNEL_ARCH_CPPFLAGS)
|
|||
LDFLAGS:=$(LDFLAGS) $(KERNEL_ARCH_LDFLAGS)
|
||||
LIBS:=$(LIBS) $(KERNEL_ARCH_LIBS)
|
||||
|
||||
BUILDDIR=$(abspath build)
|
||||
|
||||
KERNEL_OBJS=\
|
||||
$(KERNEL_ARCH_OBJS) \
|
||||
kernel/GDT.o \
|
||||
|
@ -51,28 +53,30 @@ $(LIBS) \
|
|||
$(ARCHDIR)/crtend.o \
|
||||
$(ARCHDIR)/crtn.o \
|
||||
|
||||
.PHONY: all clean install install-headers install-kernel
|
||||
.PHONY: all always clean install install-headers install-kernel
|
||||
.SUFFIXES: .o .cpp .S
|
||||
|
||||
all: banan-os.kernel
|
||||
|
||||
banan-os.kernel: $(OBJS) $(ARCHDIR)/linker.ld
|
||||
$(CXX) -T $(ARCHDIR)/linker.ld -o $@ $(CFLAGS) $(CPPFLAGS) $(LINK_LIST)
|
||||
grub-file --is-x86-multiboot banan-os.kernel
|
||||
banan-os.kernel: always $(OBJS) $(ARCHDIR)/linker.ld
|
||||
cd $(BUILDDIR) && $(CC) -T ../$(ARCHDIR)/linker.ld -o banan-os.kernel $(CFLAGS) $(LINK_LIST)
|
||||
cd $(BUILDDIR) && grub-file --is-x86-multiboot banan-os.kernel
|
||||
|
||||
$(ARCHDIR)/crtbegin.o $(ARCHDIR)/crtend.o:
|
||||
OBJ=`$(CXX) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -print-file-name=$(@F)` && cp "$$OBJ" $@
|
||||
OBJ=`$(CC) $(CFLAGS) $(LDFLAGS) -print-file-name=$(@F)` && cp "$$OBJ" $(BUILDDIR)/$@
|
||||
|
||||
.cpp.o:
|
||||
$(CXX) -MD -c $< -o $@ $(CFLAGS) $(CPPFLAGS)
|
||||
$(CXX) -MD -c $< -o $(BUILDDIR)/$@ $(CFLAGS) $(CPPFLAGS)
|
||||
|
||||
.S.o:
|
||||
$(CXX) -MD -c $< -o $@ $(CFLAGS) $(CPPFLAGS)
|
||||
$(CC) -MD -c $< -o $(BUILDDIR)/$@ $(CFLAGS)
|
||||
|
||||
always:
|
||||
mkdir -p $(BUILDDIR)/arch/i386
|
||||
mkdir -p $(BUILDDIR)/kernel
|
||||
|
||||
clean:
|
||||
rm -f banan-os.kernel
|
||||
rm -f $(OBJS) *.o */*.o */*/*.o
|
||||
rm -f $(OBJS:.o=.d) *.d */*.d */*/*.d
|
||||
rm -rf $(BUILDDIR)
|
||||
|
||||
install: install-headers install-kernel
|
||||
|
||||
|
@ -82,6 +86,6 @@ install-headers:
|
|||
|
||||
install-kernel: banan-os.kernel
|
||||
mkdir -p $(DESTDIR)$(BOOTDIR)
|
||||
cp banan-os.kernel $(DESTDIR)$(BOOTDIR)
|
||||
cp $(BUILDDIR)/banan-os.kernel $(DESTDIR)$(BOOTDIR)
|
||||
|
||||
-include $(OBJS:.o=.d)
|
|
@ -13,8 +13,8 @@ EXEC_PREFIX?=$(PREFIX)
|
|||
INCLUDEDIR?=$(PREFIX)/include
|
||||
LIBDIR?=$(EXEC_PREFIX)/lib
|
||||
|
||||
CFLAGS:=$(CFLAGS) -ffreestanding -Wall -Wextra
|
||||
CPPFLAGS:=$(CPPFLAGS) -D__is_libc -Iinclude
|
||||
CFLAGS:=$(CFLAGS) -D__is_libc -Iinclude -ffreestanding -Wall -Wextra
|
||||
CPPFLAGS:=$(CPPFLAGS)
|
||||
LIBK_CFLAGS:=$(CFLAGS)
|
||||
LIBK_CPPFLAGS:=$(CPPFLAGS) -D__is_libk
|
||||
|
||||
|
@ -27,6 +27,8 @@ CPPFLAGS:=$(CPPFLAGS) $(ARCH_CPPFLAGS)
|
|||
LIBK_CFLAGS:=$(LIBK_CFLAGS) $(KERNEL_ARCH_CFLAGS)
|
||||
LIBK_CPPFLAGS:=$(LIBK_CPPFLAGS) $(KERNEL_ARCH_CPPFLAGS)
|
||||
|
||||
BUILDDIR=$(abspath build)
|
||||
|
||||
FREEOBJS=\
|
||||
$(ARCH_FREEOBJS) \
|
||||
stdio/printf.o \
|
||||
|
@ -54,33 +56,36 @@ LIBK_OBJS=$(FREEOBJS:.o=.libk.o)
|
|||
#BINARIES=libc.a libk.a # Not ready for libc yet.
|
||||
BINARIES=libk.a
|
||||
|
||||
.PHONY: all clean install install-headers install-libs
|
||||
.PHONY: all always clean install install-headers install-libs
|
||||
.SUFFIXES: .o .libk.o .cpp .S
|
||||
|
||||
all: $(BINARIES)
|
||||
|
||||
libc.a: $(OBJS)
|
||||
$(AR) rcs $@ $(OBJS)
|
||||
libc.a: always $(OBJS)
|
||||
cd $(BUILDDIR) && $(AR) rcs $@ $(OBJS)
|
||||
|
||||
libk.a: $(LIBK_OBJS)
|
||||
$(AR) rcs $@ $(LIBK_OBJS)
|
||||
libk.a: always $(LIBK_OBJS)
|
||||
cd $(BUILDDIR) && $(AR) rcs $@ $(LIBK_OBJS)
|
||||
|
||||
.cpp.o:
|
||||
$(CXX) -MD -c $< -o $@ $(CFLAGS) $(CPPFLAGS)
|
||||
$(CXX) -MD -c $< -o $(BUILDDIR)/$@ $(CFLAGS) $(CPPFLAGS)
|
||||
|
||||
.S.o:
|
||||
$(CXX) -MD -c $< -o $@ $(CFLAGS) $(CPPFLAGS)
|
||||
$(CXX) -MD -c $< -o $(BUILDDIR)/$@ $(CFLAGS) $(CPPFLAGS)
|
||||
|
||||
.cpp.libk.o:
|
||||
$(CXX) -MD -c $< -o $@ $(LIBK_CFLAGS) $(LIBK_CPPFLAGS)
|
||||
$(CXX) -MD -c $< -o $(BUILDDIR)/$@ $(LIBK_CFLAGS) $(LIBK_CPPFLAGS)
|
||||
|
||||
.S.libk.o:
|
||||
$(CXX) -MD -c $< -o $@ $(LIBK_CFLAGS) $(LIBK_CPPFLAGS)
|
||||
$(CXX) -MD -c $< -o $(BUILDDIR)/$@ $(LIBK_CFLAGS) $(LIBK_CPPFLAGS)
|
||||
|
||||
clean:
|
||||
rm -f $(BINARIES) *.a
|
||||
rm -f $(OBJS) $(LIBK_OBJS) *.o */*.o */*/*.o
|
||||
rm -f $(OBJS:.o=.d) $(LIBK_OBJS:.o=.d) *.d */*.d */*/*.d
|
||||
rm -rf $(BUILDDIR)
|
||||
|
||||
always:
|
||||
mkdir -p $(BUILDDIR)/stdio
|
||||
mkdir -p $(BUILDDIR)/stdlib
|
||||
mkdir -p $(BUILDDIR)/string
|
||||
|
||||
install: install-headers install-libs
|
||||
|
||||
|
@ -90,7 +95,7 @@ install-headers:
|
|||
|
||||
install-libs: $(BINARIES)
|
||||
mkdir -p $(DESTDIR)$(LIBDIR)
|
||||
cp $(BINARIES) $(DESTDIR)$(LIBDIR)
|
||||
cp $(BUILDDIR)/$(BINARIES) $(DESTDIR)$(LIBDIR)
|
||||
|
||||
-include $(OBJS:.o=.d)
|
||||
-include $(LIBK_OBJS:.o=.d)
|
Loading…
Reference in New Issue