rulimine/decompressor/Makefile

69 lines
1.3 KiB
Makefile
Raw Normal View History

BUILDDIR =
ifeq ($(BUILDDIR), )
$(error BUILDDIR not specified)
endif
TOOLCHAIN = x86_64-elf
CC = $(TOOLCHAIN)-gcc
OBJCOPY = $(TOOLCHAIN)-objcopy
CFLAGS = -flto -Os -pipe -Wall -Wextra -Werror
2020-09-13 15:36:18 +03:00
INTERNAL_CFLAGS = \
-m32 \
-std=gnu11 \
-ffreestanding \
2020-09-13 15:36:18 +03:00
-fno-stack-protector \
-fno-pic \
-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 \
-masm=intel \
2021-03-08 02:50:23 +03:00
-mgeneral-regs-only \
2020-09-21 13:46:42 +03:00
-MMD \
-I.
LDFLAGS = -flto -Os
2020-09-13 15:36:18 +03:00
INTERNAL_LDFLAGS = \
-m32 \
-Wl,-melf_i386 \
-nostdlib \
2020-09-13 15:36:18 +03:00
-no-pie \
-fno-pic \
-fno-pie \
-z max-page-size=0x1000 \
2020-09-13 15:36:18 +03:00
-static \
-Tlinker.ld
.PHONY: all clean builddir
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))
all:
$(MAKE) builddir
$(MAKE) $(BUILDDIR)/decompressor.bin
2021-03-08 02:50:23 +03:00
builddir:
for i in $(OBJ); do mkdir -p `dirname $$i`; done
$(BUILDDIR)/decompressor.bin: $(OBJ)
$(CC) $(OBJ) $(LDFLAGS) $(INTERNAL_LDFLAGS) -o $(BUILDDIR)/decompressor.elf
2021-03-08 02:50:23 +03:00
$(OBJCOPY) -O binary $(BUILDDIR)/decompressor.elf $@
2020-09-21 13:46:42 +03:00
-include $(HEADER_DEPS)
$(BUILDDIR)/%.o: %.c
2020-09-13 15:36:18 +03:00
$(CC) $(CFLAGS) $(INTERNAL_CFLAGS) -c $< -o $@
$(BUILDDIR)/%.o: %.asm
nasm $< -f elf32 -o $@
clean:
2021-03-08 02:50:23 +03:00
rm -rf $(BUILDDIR)