rulimine/decompressor/GNUmakefile

89 lines
2.8 KiB
Makefile
Raw Normal View History

2023-02-19 12:07:21 +03:00
override MAKEFLAGS += -rR
include $(CROSS_FILE)
2022-06-15 08:16:41 +03:00
2022-01-02 14:45:15 +03:00
BUILDDIR ?=
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))))
2022-08-15 18:41:04 +03:00
ifeq ($(call MKESCAPE,$(BUILDDIR)),)
$(error BUILDDIR not specified)
endif
override CROSS_CFLAGS += \
-Os \
-std=gnu11 \
-nostdinc \
2022-08-15 18:41:04 +03:00
-ffreestanding \
-fno-stack-protector \
-fno-stack-check \
-fomit-frame-pointer \
2022-08-15 18:41:04 +03:00
-fno-strict-aliasing \
-fno-lto \
-fno-pie \
-fno-pic \
-m32 \
-march=i686 \
-mabi=sysv \
-mno-80387 \
2022-08-15 18:41:04 +03:00
-Wshadow \
2023-02-25 03:38:26 +03:00
-Wvla
override CROSS_CPPFLAGS := \
2022-08-15 18:41:04 +03:00
-I../freestanding-headers \
-I'$(call SHESCAPE,$(BUILDDIR))/tinf' \
2023-02-25 03:38:26 +03:00
-I. \
$(CROSS_CPPFLAGS) \
-MMD
override CROSS_LDFLAGS += \
-m elf_i386 \
2022-08-15 18:41:04 +03:00
-nostdlib \
-z max-page-size=0x1000 \
-static \
-T linker.ld
2022-08-29 22:52:59 +03:00
ifeq ($(CROSS_LD_HAS_NO_PIE),yes)
override CROSS_LDFLAGS += -no-pie
endif
2022-08-27 06:09:42 +03:00
override C_FILES := $(shell find . -type f -name '*.c')
override ASM_FILES := $(shell find . -type f -name '*.asm')
override OBJ := $(addprefix $(call MKESCAPE,$(BUILDDIR))/, $(ASM_FILES:.asm=.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
2022-06-21 09:47:48 +03:00
$(call MKESCAPE,$(BUILDDIR))/decompressor.bin: $(OBJ) ../libgcc-binaries/libgcc-i686.a $(call MKESCAPE,$(BUILDDIR))/tinf/tinfgzip.o $(call MKESCAPE,$(BUILDDIR))/tinf/tinflate.o
$(CROSS_LD) '$(call OBJESCAPE,$^)' $(CROSS_LDFLAGS) -o '$(call SHESCAPE,$(BUILDDIR))/decompressor.elf'
$(CROSS_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,$@)')"
2023-02-25 03:38:26 +03:00
$(CROSS_CC) $(CROSS_CFLAGS) $(CROSS_CPPFLAGS) -c '$(call SHESCAPE,$(@:.o=.c))' -o '$(call SHESCAPE,$@)'
$(call MKESCAPE,$(BUILDDIR))/tinf/tinflate.o: $(call MKESCAPE,$(BUILDDIR))/tinf-copied
$(MKDIR_P) "$$(dirname '$(call SHESCAPE,$@)')"
2023-02-25 03:38:26 +03:00
$(CROSS_CC) $(CROSS_CFLAGS) $(CROSS_CPPFLAGS) -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
$(MKDIR_P) "$$(dirname '$(call SHESCAPE,$@)')"
2023-02-25 03:38:26 +03:00
$(CROSS_CC) $(CROSS_CFLAGS) $(CROSS_CPPFLAGS) -c '$(call SHESCAPE,$<)' -o '$(call SHESCAPE,$@)'
$(call MKESCAPE,$(BUILDDIR))/%.o: %.asm
$(MKDIR_P) "$$(dirname '$(call SHESCAPE,$@)')"
nasm '$(call SHESCAPE,$<)' -f elf32 -o '$(call SHESCAPE,$@)'