removes external dependency on tinf by replacing the compression algorithm with a simpler, faster, smaller and more auditable fixed-width LZ77 encoding purpose-tailored to x86 code mixed with data. before: decompressor.bin 2,492 bytes (tinf dependency) with .text 0x875 and .rodata 0x13c bytes each. after: decompressor.bin consists only of .text, 0xe6-byte decompressor; 90.8% reduction in decompressor volume. the dependency on gzip during compile-time is replaced by host/limlzpack.c, a Lempel-Ziv encoder in 275 SLoC that uses a suffix array matchfinder (prefix-doubling in mathcal O(n log^2 n) and Storer-Szymanski backwards parse. the fixed-width formats packets as [F][LLLL][MMM], favouring a literal-skewed distribution with F switching between one-byte and two-byte offsets (favouring recent statistics). integrity checking is done via crc32 with the polynomial 0xEDB88320, reflected. the effective loss in compression ratio by using a tremendously simpler and less packed with edge cases algorithm causes a compression ratio hit well below 1KB, factoring in the stub sizes. also adds new machinery for host cc detection per review.
84 lines
2.3 KiB
Makefile
84 lines
2.3 KiB
Makefile
.SUFFIXES:
|
|
|
|
override SPACE := $(subst ,, )
|
|
|
|
override MKESCAPE = $(subst $(SPACE),\ ,$(1))
|
|
override SHESCAPE = $(subst ','\'',$(1))
|
|
override OBJESCAPE = $(subst .a ,.a' ',$(subst .o ,.o' ',$(call SHESCAPE,$(1))))
|
|
|
|
override CC_FOR_TARGET_IS_CLANG := $(shell ! $(CC_FOR_TARGET) --version 2>/dev/null | $(GREP) -q '^Target: '; echo $$?)
|
|
|
|
ifeq ($(CC_FOR_TARGET_IS_CLANG),1)
|
|
override CC_FOR_TARGET += \
|
|
-target i686-unknown-none-elf
|
|
endif
|
|
|
|
override CFLAGS_FOR_TARGET += \
|
|
-Os \
|
|
-Wall \
|
|
-Wextra \
|
|
-Wshadow \
|
|
-Wvla \
|
|
$(WERROR_FLAG) \
|
|
-std=gnu11 \
|
|
-nostdinc \
|
|
-ffreestanding \
|
|
-ffunction-sections \
|
|
-fdata-sections \
|
|
-fno-stack-protector \
|
|
-fno-stack-check \
|
|
-fomit-frame-pointer \
|
|
-fno-strict-aliasing \
|
|
-fno-lto \
|
|
-fno-PIC \
|
|
-m32 \
|
|
-march=i686 \
|
|
-mabi=sysv \
|
|
-mno-80387 \
|
|
-mno-mmx
|
|
|
|
override CPPFLAGS_FOR_TARGET := \
|
|
-I . \
|
|
-isystem ../freestnd-c-hdrs/include \
|
|
$(CPPFLAGS_FOR_TARGET) \
|
|
-MMD \
|
|
-MP
|
|
|
|
override LDFLAGS_FOR_TARGET += \
|
|
-m elf_i386 \
|
|
-nostdlib \
|
|
-z max-page-size=0x1000 \
|
|
--gc-sections \
|
|
-static \
|
|
-T linker.ld
|
|
|
|
override NASMFLAGS_FOR_TARGET := \
|
|
-f elf32 \
|
|
$(patsubst -g,-g -F dwarf,$(NASMFLAGS_FOR_TARGET)) \
|
|
-Wall \
|
|
-w-unknown-warning \
|
|
-w-reloc \
|
|
$(WERROR_FLAG)
|
|
|
|
override C_FILES := $(shell find . -type f -name '*.c' | LC_ALL=C sort)
|
|
override ASM_FILES := $(shell find . -type f -name '*.asm' | LC_ALL=C sort)
|
|
override OBJ := $(addprefix $(call MKESCAPE,$(BUILDDIR))/, $(ASM_FILES:.asm=.o) $(C_FILES:.c=.o))
|
|
override HEADER_DEPS := $(addprefix $(call MKESCAPE,$(BUILDDIR))/, $(C_FILES:.c=.d))
|
|
|
|
.PHONY: all
|
|
all: $(call MKESCAPE,$(BUILDDIR))/decompressor.bin
|
|
|
|
$(call MKESCAPE,$(BUILDDIR))/decompressor.bin: $(OBJ)
|
|
$(LD_FOR_TARGET) $(LDFLAGS_FOR_TARGET) '$(call OBJESCAPE,$^)' -o '$(call SHESCAPE,$(BUILDDIR))/decompressor.elf'
|
|
$(OBJCOPY_FOR_TARGET) -O binary '$(call SHESCAPE,$(BUILDDIR))/decompressor.elf' '$(call SHESCAPE,$@)'
|
|
|
|
-include $(HEADER_DEPS)
|
|
|
|
$(call MKESCAPE,$(BUILDDIR))/%.o: %.c
|
|
$(MKDIR_P) "$$(dirname '$(call SHESCAPE,$@)')"
|
|
$(CC_FOR_TARGET) $(CFLAGS_FOR_TARGET) $(CPPFLAGS_FOR_TARGET) -c '$(call SHESCAPE,$<)' -o '$(call SHESCAPE,$@)'
|
|
|
|
$(call MKESCAPE,$(BUILDDIR))/%.o: %.asm
|
|
$(MKDIR_P) "$$(dirname '$(call SHESCAPE,$@)')"
|
|
nasm '$(call SHESCAPE,$<)' $(NASMFLAGS_FOR_TARGET) -o '$(call SHESCAPE,$@)'
|