rulimine/decompressor/GNUmakefile

93 lines
2.8 KiB
Makefile
Raw Normal View History

2022-01-02 14:45:15 +03:00
BUILDDIR ?=
USING_CLANG ?= 0
2021-12-08 19:41:19 +03:00
override SPACE := $(subst ,, )
2021-11-28 21:14:34 +03:00
MKESCAPE = $(subst $(SPACE),\ ,$(1))
SHESCAPE = $(subst ','\'',$(1))
OBJESCAPE = $(subst .a ,.a' ',$(subst .o ,.o' ',$(call SHESCAPE,$(1))))
ifeq ($(call MKESCAPE,$(BUILDDIR)), )
2021-12-08 19:41:19 +03:00
$(error BUILDDIR not specified)
endif
2022-01-02 14:45:15 +03:00
ifeq ($(USING_CLANG), 1)
2022-01-17 00:41:37 +03:00
override LIMINE_CC += --target=i686-elf
2021-12-22 03:44:33 +03:00
endif
2021-12-08 19:41:19 +03:00
override INTERNAL_CFLAGS := \
2022-01-17 00:41:37 +03:00
$(WERROR) \
-m32 \
-march=i686 \
2021-10-11 22:35:23 +03:00
-mtune=generic \
2021-07-31 22:28:06 +03:00
-mabi=sysv \
-std=gnu11 \
-ffreestanding \
2020-09-13 15:36:18 +03:00
-fno-stack-protector \
-fno-stack-check \
-fno-strict-aliasing \
-fno-lto \
2020-09-13 15:36:18 +03:00
-fno-pic \
-fno-pie \
2020-09-14 20:32:11 +03:00
-fomit-frame-pointer \
-nostdinc \
2020-09-21 13:46:42 +03:00
-Wno-address-of-packed-member \
2022-02-18 03:09:51 +03:00
-Wshadow \
-Wvla \
-mno-80387 \
-mno-mmx \
-mno-3dnow \
-mno-sse \
-mno-sse2 \
2020-09-21 13:46:42 +03:00
-MMD \
-I../freestanding_headers \
2021-10-22 21:08:11 +03:00
-I. \
-I'$(call SHESCAPE,$(BUILDDIR))/tinf'
2021-12-08 19:41:19 +03:00
override INTERNAL_LDFLAGS := \
-melf_i386 \
-nostdlib \
-z max-page-size=0x1000 \
2020-09-13 15:36:18 +03:00
-static \
-Tlinker.ld
2022-01-22 05:10:25 +03:00
override C_FILES := $(shell find ./ -type f -name '*.c')
2022-05-12 17:14:20 +03:00
override ASM_FILES := $(shell find ./ -type f -name '*.S')
override OBJ := $(addprefix $(call MKESCAPE,$(BUILDDIR))/, $(ASM_FILES:.S=.o) $(C_FILES:.c=.o))
2021-12-08 19:41:19 +03:00
override HEADER_DEPS := $(addprefix $(call MKESCAPE,$(BUILDDIR))/, $(C_FILES:.c=.d))
2021-12-08 19:41:19 +03:00
.PHONY: all
all: $(call MKESCAPE,$(BUILDDIR))/decompressor.bin
2021-03-08 02:50:23 +03:00
$(call MKESCAPE,$(BUILDDIR))/decompressor.bin: $(OBJ) $(call MKESCAPE,$(BUILDDIR))/tinf/tinfgzip.o $(call MKESCAPE,$(BUILDDIR))/tinf/tinflate.o
2022-01-17 00:41:37 +03:00
$(LIMINE_LD) '$(call OBJESCAPE,$^)' $(LIMINE_LDFLAGS) $(INTERNAL_LDFLAGS) -o '$(call SHESCAPE,$(BUILDDIR))/decompressor.elf'
$(LIMINE_OBJCOPY) -O binary '$(call SHESCAPE,$(BUILDDIR))/decompressor.elf' '$(call SHESCAPE,$@)'
$(call MKESCAPE,$(BUILDDIR))/tinf-copied: ../tinf/*
rm -rf '$(call SHESCAPE,$(BUILDDIR))/tinf'
mkdir -p '$(call SHESCAPE,$(BUILDDIR))'
cp -r ../tinf '$(call SHESCAPE,$(BUILDDIR))/'
touch '$(call SHESCAPE,$(BUILDDIR))/tinf-copied'
2021-10-22 21:08:11 +03:00
$(call MKESCAPE,$(BUILDDIR))/tinf/tinfgzip.o: $(call MKESCAPE,$(BUILDDIR))/tinf-copied
mkdir -p "$$(dirname '$(call SHESCAPE,$@)')"
$(LIMINE_CC) $(LIMINE_CFLAGS) -Os $(INTERNAL_CFLAGS) -c '$(call SHESCAPE,$(@:.o=.c))' -o '$(call SHESCAPE,$@)'
$(call MKESCAPE,$(BUILDDIR))/tinf/tinflate.o: $(call MKESCAPE,$(BUILDDIR))/tinf-copied
2021-12-23 00:08:19 +03:00
mkdir -p "$$(dirname '$(call SHESCAPE,$@)')"
2022-01-17 00:41:37 +03:00
$(LIMINE_CC) $(LIMINE_CFLAGS) -Os $(INTERNAL_CFLAGS) -c '$(call SHESCAPE,$(@:.o=.c))' -o '$(call SHESCAPE,$@)'
2021-10-22 21:08:11 +03:00
2020-09-21 13:46:42 +03:00
-include $(HEADER_DEPS)
$(call MKESCAPE,$(BUILDDIR))/%.o: %.c $(call MKESCAPE,$(BUILDDIR))/tinf-copied
2021-12-23 00:08:19 +03:00
mkdir -p "$$(dirname '$(call SHESCAPE,$@)')"
2022-01-17 00:41:37 +03:00
$(LIMINE_CC) $(LIMINE_CFLAGS) -Os $(INTERNAL_CFLAGS) -c '$(call SHESCAPE,$<)' -o '$(call SHESCAPE,$@)'
2022-05-12 17:14:20 +03:00
$(call MKESCAPE,$(BUILDDIR))/%.o: %.S
2021-12-23 00:08:19 +03:00
mkdir -p "$$(dirname '$(call SHESCAPE,$@)')"
2022-05-12 17:14:20 +03:00
$(LIMINE_CC) $(LIMINE_CFLAGS) -Os $(INTERNAL_CFLAGS) -c '$(call SHESCAPE,$<)' -o '$(call SHESCAPE,$@)'
2021-12-08 19:41:19 +03:00
.PHONY: clean
clean:
rm -rf '$(call SHESCAPE,$(BUILDDIR))'