2020-09-04 06:21:58 +03:00
|
|
|
OPT_LEVEL = z
|
|
|
|
CFLAGS = -pipe -Wall -Wextra
|
2020-01-22 01:45:13 +03:00
|
|
|
|
|
|
|
INTERNAL_CFLAGS = \
|
2020-09-04 06:21:58 +03:00
|
|
|
-O$(OPT_LEVEL) \
|
2020-08-25 00:35:06 +03:00
|
|
|
-std=gnu99 \
|
2020-01-22 01:45:13 +03:00
|
|
|
-ffreestanding \
|
2020-09-04 06:21:58 +03:00
|
|
|
-flto \
|
2020-08-25 00:35:06 +03:00
|
|
|
-mno-80387 \
|
|
|
|
-mno-mmx \
|
2020-01-22 01:45:13 +03:00
|
|
|
-mno-sse \
|
|
|
|
-mno-sse2 \
|
2020-04-29 17:53:05 +03:00
|
|
|
-I. \
|
|
|
|
-Wno-address-of-packed-member
|
2020-01-22 01:45:13 +03:00
|
|
|
|
|
|
|
INTERNAL_LDFLAGS = \
|
2020-09-04 06:21:58 +03:00
|
|
|
-static \
|
2020-01-22 01:45:13 +03:00
|
|
|
-nostdlib \
|
2020-09-04 06:21:58 +03:00
|
|
|
-Tlinker.ld \
|
|
|
|
-no-pie
|
2020-01-22 01:45:13 +03:00
|
|
|
|
|
|
|
.PHONY: all clean
|
|
|
|
|
2020-09-06 04:35:32 +03:00
|
|
|
C_FILES := $(shell find ./ -type f -name '*.c' | grep -v bootsect | grep -v decompressor | sort)
|
|
|
|
ASM_FILES := $(shell find ./ -type f -name '*.asm' | grep -v bootsect | grep -v decompressor | sort)
|
2020-09-04 06:21:58 +03:00
|
|
|
ASM_OBJ := $(ASM_FILES:.asm=.o)
|
|
|
|
BC := $(C_FILES:.c=.bc)
|
2020-01-22 01:45:13 +03:00
|
|
|
|
2020-08-29 21:02:16 +03:00
|
|
|
all: limine.bin
|
2020-01-22 01:45:13 +03:00
|
|
|
|
2020-09-04 06:21:58 +03:00
|
|
|
limine.bin: libgcc.a $(BC) $(ASM_OBJ)
|
|
|
|
llvm-link $(BC) -o bundle.bc
|
|
|
|
opt --O$(OPT_LEVEL) bundle.bc -o optimised_bundle.bc
|
|
|
|
clang --target=i386-elf -O$(OPT_LEVEL) -c optimised_bundle.bc -o optimised_bundle.o
|
2020-09-09 17:04:06 +03:00
|
|
|
ld.lld optimised_bundle.o $(ASM_OBJ) $(INTERNAL_LDFLAGS) -o stage2.elf
|
2020-09-04 06:21:58 +03:00
|
|
|
llvm-objcopy -O binary stage2.elf stage2.bin
|
2020-09-06 04:35:32 +03:00
|
|
|
gzip -9 stage2.bin
|
|
|
|
$(MAKE) -C decompressor
|
2020-08-29 21:02:16 +03:00
|
|
|
cd bootsect && nasm bootsect.asm -fbin -o ../limine.bin
|
2020-01-22 01:45:13 +03:00
|
|
|
|
2020-09-04 06:21:58 +03:00
|
|
|
%.bc: %.c
|
|
|
|
clang --target=i386-elf $(CFLAGS) $(INTERNAL_CFLAGS) -c $< -o $@
|
2020-01-22 01:45:13 +03:00
|
|
|
|
2020-09-04 02:37:24 +03:00
|
|
|
%.o: %.asm
|
|
|
|
nasm $< -f elf32 -o $@
|
|
|
|
|
2020-01-22 01:45:13 +03:00
|
|
|
clean:
|
2020-09-06 04:35:32 +03:00
|
|
|
$(MAKE) -C decompressor clean
|
|
|
|
rm -f stage2.bin.gz limine.bin $(ASM_OBJ) $(BC)
|