2021-03-08 05:05:39 +03:00
|
|
|
BUILDDIR =
|
|
|
|
|
|
|
|
ifeq ($(BUILDDIR), )
|
|
|
|
$(error BUILDDIR not specified)
|
|
|
|
endif
|
2020-09-06 04:35:32 +03:00
|
|
|
|
2021-08-07 08:26:34 +03:00
|
|
|
TOOLCHAIN ?= limine
|
2021-04-03 01:48:38 +03:00
|
|
|
|
2021-08-07 08:26:34 +03:00
|
|
|
TOOLCHAIN_CC ?= $(TOOLCHAIN)-gcc
|
|
|
|
TOOLCHAIN_LD ?= $(TOOLCHAIN)-ld
|
|
|
|
TOOLCHAIN_OBJCOPY ?= $(TOOLCHAIN)-objcopy
|
2021-04-08 20:41:46 +03:00
|
|
|
|
2021-06-30 19:22:50 +03:00
|
|
|
ifeq ($(shell command -v $(TOOLCHAIN_CC) ; ), )
|
2021-08-07 08:26:34 +03:00
|
|
|
override TOOLCHAIN_CC := cc
|
2021-04-08 20:41:46 +03:00
|
|
|
endif
|
2021-06-30 19:22:50 +03:00
|
|
|
ifeq ($(shell command -v $(TOOLCHAIN_LD) ; ), )
|
2021-08-07 08:26:34 +03:00
|
|
|
override TOOLCHAIN_LD := ld
|
2021-05-31 01:32:43 +03:00
|
|
|
endif
|
2021-06-30 19:22:50 +03:00
|
|
|
ifeq ($(shell command -v $(TOOLCHAIN_OBJCOPY) ; ), )
|
2021-08-07 08:26:34 +03:00
|
|
|
override TOOLCHAIN_OBJCOPY := objcopy
|
2021-04-08 20:41:46 +03:00
|
|
|
endif
|
2021-04-03 01:48:38 +03:00
|
|
|
|
2021-08-07 08:26:34 +03:00
|
|
|
WERROR = -Werror
|
|
|
|
CFLAGS ?= -Os -pipe -Wall -Wextra $(WERROR)
|
2020-09-13 15:36:18 +03:00
|
|
|
|
2020-09-25 23:36:26 +03:00
|
|
|
INTERNAL_CFLAGS = \
|
2021-04-03 01:48:38 +03:00
|
|
|
-m32 \
|
2021-04-03 23:12:40 +03:00
|
|
|
-march=i386 \
|
2021-07-31 22:28:06 +03:00
|
|
|
-mabi=sysv \
|
2020-09-18 23:15:27 +03:00
|
|
|
-std=gnu11 \
|
2020-09-06 04:35:32 +03:00
|
|
|
-ffreestanding \
|
2020-09-13 15:36:18 +03:00
|
|
|
-fno-stack-protector \
|
|
|
|
-fno-pic \
|
2021-04-03 01:48:38 +03:00
|
|
|
-fno-pie \
|
2020-09-14 20:32:11 +03:00
|
|
|
-fomit-frame-pointer \
|
2020-09-21 13:46:42 +03:00
|
|
|
-Wno-address-of-packed-member \
|
2021-05-22 11:26:56 +03:00
|
|
|
-mno-80387 \
|
|
|
|
-mno-mmx \
|
|
|
|
-mno-3dnow \
|
|
|
|
-mno-sse \
|
|
|
|
-mno-sse2 \
|
2020-09-21 13:46:42 +03:00
|
|
|
-MMD \
|
|
|
|
-I.
|
2020-09-06 04:35:32 +03:00
|
|
|
|
2021-08-07 08:26:34 +03:00
|
|
|
LDFLAGS ?=
|
2020-09-13 15:36:18 +03:00
|
|
|
|
2020-09-06 04:35:32 +03:00
|
|
|
INTERNAL_LDFLAGS = \
|
2021-05-31 01:32:43 +03:00
|
|
|
-melf_i386 \
|
2020-09-06 04:35:32 +03:00
|
|
|
-nostdlib \
|
2020-09-25 23:36:26 +03:00
|
|
|
-z max-page-size=0x1000 \
|
2020-09-13 15:36:18 +03:00
|
|
|
-static \
|
|
|
|
-Tlinker.ld
|
2020-09-06 04:35:32 +03:00
|
|
|
|
2021-03-08 05:05:39 +03:00
|
|
|
.PHONY: all clean builddir
|
2020-09-06 04:35:32 +03:00
|
|
|
|
2021-02-22 06:34:36 +03:00
|
|
|
C_FILES := $(shell find -L ./ -type f -name '*.c' | sort)
|
|
|
|
ASM_FILES := $(shell find -L ./ -type f -name '*.asm' | sort)
|
2021-03-08 02:50:23 +03:00
|
|
|
OBJ := $(addprefix $(BUILDDIR)/, $(ASM_FILES:.asm=.o) $(C_FILES:.c=.o))
|
|
|
|
HEADER_DEPS := $(addprefix $(BUILDDIR)/, $(C_FILES:.c=.d))
|
2020-09-06 04:35:32 +03:00
|
|
|
|
2021-03-08 05:05:39 +03:00
|
|
|
all:
|
|
|
|
$(MAKE) builddir
|
|
|
|
$(MAKE) $(BUILDDIR)/decompressor.bin
|
2020-09-06 04:35:32 +03:00
|
|
|
|
2021-03-08 02:50:23 +03:00
|
|
|
builddir:
|
|
|
|
for i in $(OBJ); do mkdir -p `dirname $$i`; done
|
|
|
|
|
|
|
|
$(BUILDDIR)/decompressor.bin: $(OBJ)
|
2021-05-31 01:32:43 +03:00
|
|
|
$(TOOLCHAIN_LD) $(OBJ) $(LDFLAGS) $(INTERNAL_LDFLAGS) -o $(BUILDDIR)/decompressor.elf
|
2021-04-08 20:41:46 +03:00
|
|
|
$(TOOLCHAIN_OBJCOPY) -O binary $(BUILDDIR)/decompressor.elf $@
|
2020-09-06 04:35:32 +03:00
|
|
|
|
2020-09-21 13:46:42 +03:00
|
|
|
-include $(HEADER_DEPS)
|
|
|
|
|
2021-03-08 05:05:39 +03:00
|
|
|
$(BUILDDIR)/%.o: %.c
|
2021-08-07 08:26:34 +03:00
|
|
|
$(TOOLCHAIN_CC) $(CFLAGS) -Os $(INTERNAL_CFLAGS) -c $< -o $@
|
2020-09-06 04:35:32 +03:00
|
|
|
|
2021-03-08 05:05:39 +03:00
|
|
|
$(BUILDDIR)/%.o: %.asm
|
2020-09-18 23:15:27 +03:00
|
|
|
nasm $< -f elf32 -o $@
|
|
|
|
|
2020-09-06 04:35:32 +03:00
|
|
|
clean:
|
2021-03-08 02:50:23 +03:00
|
|
|
rm -rf $(BUILDDIR)
|