2020-09-18 22:38:59 +03:00
|
|
|
CC = i386-elf-gcc
|
|
|
|
LD = i386-elf-gcc
|
|
|
|
OBJCOPY = i386-elf-objcopy
|
2020-11-15 19:56:10 +03:00
|
|
|
OBJDUMP = i386-elf-objdump
|
2021-02-21 01:04:06 +03:00
|
|
|
READELF = i386-elf-readelf
|
2020-01-22 01:45:13 +03:00
|
|
|
|
2021-02-23 03:16:12 +03:00
|
|
|
LIMINE_VERSION := $(shell git describe --exact-match --tags `git log -n1 --pretty='%h'` || git log -n1 --pretty='%h')
|
2020-10-18 07:23:39 +03:00
|
|
|
WERROR = -Werror
|
2020-11-15 19:56:10 +03:00
|
|
|
CFLAGS = -Os -pipe -Wall -Wextra $(WERROR)
|
2020-09-13 15:36:18 +03:00
|
|
|
|
2020-09-25 23:36:26 +03:00
|
|
|
INTERNAL_CFLAGS = \
|
2020-09-17 15:37:22 +03:00
|
|
|
-std=gnu11 \
|
|
|
|
-fplan9-extensions \
|
2020-01-22 01:45:13 +03:00
|
|
|
-ffreestanding \
|
2020-09-13 15:36:18 +03:00
|
|
|
-fno-stack-protector \
|
|
|
|
-fno-pic \
|
2020-11-15 19:56:10 +03:00
|
|
|
-fno-omit-frame-pointer \
|
2020-09-21 13:46:42 +03:00
|
|
|
-Wno-address-of-packed-member \
|
2020-09-16 18:22:05 +03:00
|
|
|
-masm=intel \
|
2020-08-25 00:35:06 +03:00
|
|
|
-mno-80387 \
|
|
|
|
-mno-mmx \
|
2020-09-14 20:32:11 +03:00
|
|
|
-mno-3dnow \
|
2020-01-22 01:45:13 +03:00
|
|
|
-mno-sse \
|
|
|
|
-mno-sse2 \
|
2020-09-21 13:46:42 +03:00
|
|
|
-MMD \
|
2020-12-31 01:42:39 +03:00
|
|
|
-DLIMINE_VERSION='"$(LIMINE_VERSION)"' \
|
2020-04-29 17:53:05 +03:00
|
|
|
-I. \
|
2020-09-21 13:46:42 +03:00
|
|
|
-I..
|
2020-01-22 01:45:13 +03:00
|
|
|
|
2020-11-15 19:56:10 +03:00
|
|
|
LDFLAGS = -Os
|
2020-09-13 15:36:18 +03:00
|
|
|
|
2020-01-22 01:45:13 +03:00
|
|
|
INTERNAL_LDFLAGS = \
|
2020-09-13 15:36:18 +03:00
|
|
|
-lgcc \
|
|
|
|
-static-libgcc \
|
2020-01-22 01:45:13 +03:00
|
|
|
-nostdlib \
|
2020-09-13 15:36:18 +03:00
|
|
|
-no-pie \
|
2020-09-25 23:36:26 +03:00
|
|
|
-z max-page-size=0x1000 \
|
2021-02-25 03:24:54 +03:00
|
|
|
-static
|
2020-01-22 01:45:13 +03:00
|
|
|
|
|
|
|
.PHONY: all clean
|
|
|
|
|
2021-02-21 07:01:18 +03:00
|
|
|
C_FILES := $(shell find -L ./ -type f -name '*.c' | sort)
|
|
|
|
ASM_FILES := $(shell find -L ./ -type f -name '*.asm' | sort)
|
2020-09-13 15:36:18 +03:00
|
|
|
OBJ := $(ASM_FILES:.asm=.o) $(C_FILES:.c=.o)
|
2020-09-21 13:46:42 +03:00
|
|
|
HEADER_DEPS := $(C_FILES:.c=.d)
|
2020-01-22 01:45:13 +03:00
|
|
|
|
2021-02-25 03:24:54 +03:00
|
|
|
all: limine.sys stage2.bin stage2.bin.gz
|
2021-02-22 22:43:51 +03:00
|
|
|
|
|
|
|
stage2.bin.gz: stage2.bin
|
|
|
|
gzip -n -9 < stage2.bin > stage2.bin.gz
|
2021-02-21 01:04:06 +03:00
|
|
|
|
2021-02-25 03:24:54 +03:00
|
|
|
stage2.bin: limine.sys
|
|
|
|
dd if=limine.sys bs=$$(( 0x$$($(READELF) -S limine.elf | grep .stage3.text | sed 's/^.*] //' | awk '{print $$3}' | sed 's/^0*//') - 0x8000 )) count=1 of=$@
|
2021-02-21 01:04:06 +03:00
|
|
|
|
2021-02-25 03:24:54 +03:00
|
|
|
limine.map.o: limine_nomap.elf
|
|
|
|
./gensyms.sh $(OBJDUMP) limine_nomap.elf limine
|
2020-01-22 01:45:13 +03:00
|
|
|
|
2021-02-25 03:24:54 +03:00
|
|
|
limine.sys: limine.elf
|
2020-11-15 19:56:10 +03:00
|
|
|
$(OBJCOPY) -O binary $< $@
|
|
|
|
|
2021-02-25 03:24:54 +03:00
|
|
|
limine_nomap.elf: $(OBJ)
|
|
|
|
$(LD) $(OBJ) $(LDFLAGS) $(INTERNAL_LDFLAGS) -Tlinker_nomap.ld -o $@
|
|
|
|
|
|
|
|
limine.elf: $(OBJ) limine.map.o
|
|
|
|
$(LD) $(OBJ) limine.map.o $(LDFLAGS) $(INTERNAL_LDFLAGS) -Tlinker.ld -o $@
|
2020-01-22 01:45:13 +03:00
|
|
|
|
2020-09-21 13:46:42 +03:00
|
|
|
-include $(HEADER_DEPS)
|
|
|
|
|
2020-09-13 15:36:18 +03:00
|
|
|
%.o: %.c
|
|
|
|
$(CC) $(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:
|
2021-02-25 03:24:54 +03:00
|
|
|
rm -f symlist.gen limine.elf limine.sys stage2.bin stage2.bin.gz $(OBJ) $(HEADER_DEPS)
|