|
|
|
@ -8,8 +8,14 @@ endif
|
|
|
|
|
ifeq ($(SRCS),)
|
|
|
|
|
SRCS = $(wildcard *.c) $(wildcard *.S)
|
|
|
|
|
endif
|
|
|
|
|
ifeq ($(OBJS),)
|
|
|
|
|
TMP = $(SRCS:.c=.o)
|
|
|
|
|
OBJS = $(TMP:.S=.o)
|
|
|
|
|
endif
|
|
|
|
|
ifneq ($(OUTDIR),)
|
|
|
|
|
# OUTDIR is not used with uefi/*.o deliberately
|
|
|
|
|
OUTDIR:=$(addsuffix /,$(OUTDIR))
|
|
|
|
|
endif
|
|
|
|
|
CFLAGS += -fshort-wchar -fno-strict-aliasing -ffreestanding -fno-stack-protector -fno-stack-check -I. -I./uefi \
|
|
|
|
|
-I/usr/include -I/usr/include/efi -I/usr/include/efi/protocol -I/usr/include/efi/$(ARCH) -D__$(ARCH)__
|
|
|
|
|
ifeq ($(ARCH),x86_64)
|
|
|
|
@ -31,7 +37,7 @@ CFLAGS += -maccumulate-outgoing-args
|
|
|
|
|
endif
|
|
|
|
|
CFLAGS += -Wno-builtin-declaration-mismatch -fpic -fPIC
|
|
|
|
|
LDFLAGS += -nostdlib -shared -Bsymbolic -Luefi uefi/crt_$(ARCH).o
|
|
|
|
|
LIBS += -o $(TARGET).so -luefi -T uefi/elf_$(ARCH)_efi.lds
|
|
|
|
|
LIBS += -o $(addprefix $(OUTDIR),$(TARGET).so) -luefi -T uefi/elf_$(ARCH)_efi.lds
|
|
|
|
|
# see if we're cross-compiling
|
|
|
|
|
ifneq ($(ARCH),$(MYARCH))
|
|
|
|
|
CC = $(ARCH)-elf-gcc
|
|
|
|
@ -51,7 +57,7 @@ AR ?= ar
|
|
|
|
|
else
|
|
|
|
|
CFLAGS += --target=$(ARCH)-pc-win32-coff -Wno-builtin-requires-header -Wno-incompatible-library-redeclaration -Wno-long-long
|
|
|
|
|
LDFLAGS += -subsystem:efi_application -nodefaultlib -dll -entry:uefi_init uefi/*.o
|
|
|
|
|
LIBS = -out:$(TARGET)
|
|
|
|
|
LIBS = -out:$(addprefix $(OUTDIR),$(TARGET))
|
|
|
|
|
CC = clang
|
|
|
|
|
LD = lld -flavor link
|
|
|
|
|
OBJCOPY = true
|
|
|
|
@ -59,12 +65,17 @@ endif
|
|
|
|
|
|
|
|
|
|
# recipies
|
|
|
|
|
ifeq ($(wildcard uefi/Makefile),)
|
|
|
|
|
ALLTARGETS = crt_$(ARCH).o libuefi.a build
|
|
|
|
|
ALLTARGETS = crt_$(ARCH).o libuefi.a buildlib
|
|
|
|
|
else
|
|
|
|
|
ALLTARGETS = uefi/crt_$(ARCH).o uefi/libuefi.a $(OBJS) $(TARGET)
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
all: $(ALLTARGETS) $(EXTRA) $(ALSO)
|
|
|
|
|
all: $(OUTDIR) $(ALLTARGETS) $(EXTRA) $(ALSO)
|
|
|
|
|
|
|
|
|
|
ifneq ($(OUTDIR),)
|
|
|
|
|
$(OUTDIR):
|
|
|
|
|
@mkdir -p $(OUTDIR)
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
uefi/libuefi.a:
|
|
|
|
|
@make --no-print-directory -C uefi libuefi.a USE_GCC=$(USE_GCC) ARCH=$(ARCH)
|
|
|
|
@ -79,30 +90,36 @@ else
|
|
|
|
|
@true
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
$(TARGET): $(TARGET).so
|
|
|
|
|
$(TARGET): $(addprefix $(OUTDIR),$(TARGET).so)
|
|
|
|
|
ifneq ($(USE_GCC),)
|
|
|
|
|
@$(OBJCOPY) -j .text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel -j .rela -j .rel.* -j .rela.* -j .reloc --target $(EFIARCH) --subsystem=10 $^ $@ || echo target: $(EFIARCH)
|
|
|
|
|
@rm $(TARGET).so
|
|
|
|
|
$(OBJCOPY) -j .text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel -j .rela -j .rel.* -j .rela.* -j .reloc --target $(EFIARCH) --subsystem=10 $^ $(addprefix $(OUTDIR),$@) || echo target: $(EFIARCH)
|
|
|
|
|
@rm $(addprefix $(OUTDIR),$(TARGET).so)
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
$(TARGET).so: $(OBJS) $(EXTRA)
|
|
|
|
|
$(addprefix $(OUTDIR),$(TARGET).so): $(addprefix $(OUTDIR),$(OBJS)) $(EXTRA)
|
|
|
|
|
$(LD) $(LDFLAGS) $^ $(LIBS)
|
|
|
|
|
@rm *.lib 2>/dev/null || true
|
|
|
|
|
@rm $(addprefix $(OUTDIR),*.lib) 2>/dev/null || true
|
|
|
|
|
|
|
|
|
|
%.o: %.c
|
|
|
|
|
uefi/%.o: uefi/%.c
|
|
|
|
|
$(CC) $(CFLAGS) -c $< -o $@
|
|
|
|
|
|
|
|
|
|
%.o: %.c
|
|
|
|
|
$(CC) $(CFLAGS) -c $< -o $(addprefix $(OUTDIR),$@)
|
|
|
|
|
|
|
|
|
|
%.o: %.S
|
|
|
|
|
$(CC) $(CFLAGS) -c $< -o $@
|
|
|
|
|
$(CC) $(CFLAGS) -c $< -o $(addprefix $(OUTDIR),$@)
|
|
|
|
|
|
|
|
|
|
build:
|
|
|
|
|
buildlib:
|
|
|
|
|
@mkdir ../build ../build/uefi 2>/dev/null || true
|
|
|
|
|
@cp crt_$(ARCH).o ../build/uefi/crt0.o
|
|
|
|
|
@cp elf_$(ARCH)_efi.lds ../build/uefi/link.ld
|
|
|
|
|
@cp libuefi.a uefi.h ../build/uefi
|
|
|
|
|
|
|
|
|
|
clean:
|
|
|
|
|
@rm $(TARGET) *.o *.a *.lib *.elf $(LIBOBJS) 2>/dev/null || true
|
|
|
|
|
@rm $(addprefix $(OUTDIR),$(TARGET)) *.o *.a *.lib *.elf $(LIBOBJS) 2>/dev/null || true
|
|
|
|
|
ifneq ($(OUTDIR),)
|
|
|
|
|
@rm -rf $(OUTDIR)
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
distclean: clean
|
|
|
|
|
ifeq ($(wildcard uefi/Makefile),)
|
|
|
|
|