summaryrefslogtreecommitdiffstats
path: root/efi_memtest/Makefile
blob: 487cba371d783d913f4dad366272b635c2a0e3b6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# TODO Autogen.obj
# Difference *.o *.obj



MAIN_FILE=MemtestEfi

CC=gcc

CFLAGS= -Werror -Wall -fno-builtin -fshort-wchar -fno-common -fno-strict-aliasing -g \
	-Wno-array-bounds -fno-stack-protector -Wno-address -mno-red-zone \
	-fpie -ffunction-sections -fdata-sections -flto -maccumulate-outgoing-args \
	-fno-asynchronous-unwind-tables -nostdlib -fPIC

LINKER=

M64=-m64 -mcmodel=small

M32=-m32

M=$(M64)

PREPROCESSOR=-DUEFI -DUSING_LTO -Os \
	-D DISABLE_NEW_DEPRECATED_INTERFACES "-DEFIAPI=__attribute__((ms_abi))"

OBJS=AutoGen.obj main.o display.o test.o smp.o config.o screen_buffer.o lib.o init.o controller.o \
	pci.o spd.o dmi.o reloc.o patn.o error.o vmem.o cpuid.o memsize.o \
	random.o MemtestEfi.obj logger.o memory_tables.o ApplicationEntryPoint.o UefiLib2.o \
	UefiRuntimeServicesTableLib.o UefiBootServicesTableLib.o UefiDebugLibStdErr.o \
	BaseDebugPrintErrorLevelLib.o BaseMemoryLib.o  BasePcdLibNull.o UefiDevicePathLib2.o \
	UefiMemoryAllocationLib.o

BaseMemoryLib_OBJS=CompareMemWrapper.o CopyMem.o CopyMemWrapper.o IsZeroBufferWrapper.o \
	MemLibGeneric.o MemLibGuid.o ScanMem16Wrapper.o ScanMem32Wrapper.o ScanMem64Wrapper.o \
	ScanMem8Wrapper.o SetMem.o SetMem16Wrapper.o SetMem32Wrapper.o SetMem64Wrapper.o \
	SetMemWrapper.o ZeroMemWrapper.o BasePrintLib.o

UefiDevicePathLib_OBJS=DevicePathFromText.o DevicePathToText.o DevicePathUtilities.o \
	DevicePathUtilitiesDxeSmm.o DevicePathUtilitiesStandaloneMm.o UefiDevicePathLib.o \
	UefiDevicePathLibOptionalDevicePathProtocol.o


LIBRARIES=OUTPUT/MemtestEfi.lib

all: clean MemtestEfi.efi move run 


$(MAIN_FILE).efi: $(MAIN_FILE).dll
	./memtest86+/efi/Include/GenFw -e UEFI_APPLICATION -o $(MAIN_FILE).efi $(MAIN_FILE).dll


$(MAIN_FILE).dll: $(MAIN_FILE).lib	
	$(CC) $(CFLAGS)	$(PREPROCESSOR) $(M) -o $(MAIN_FILE).dll \
	-nostdlib \
	-Wl,-n,-q,--gc-sections \
	-Wl,--entry,_ModuleEntryPoint \
	-Wl,-Map,$(MAIN_FILE).map,--whole-archive \
	-Wl,-melf_x86_64,--oformat=elf64-x86-64,-pie \
	-Wl,--defsym=PECOFF_HEADER_SIZE=0x228 \
	-Wl,--script=memtest86+/efi/Include/GccBase.lds \
	-z common-page-size=0x40 \
	-u _ModuleEntryPoint \
	-DSTRING_ARRAY_NAME=${MAIN_FILE}Strings \
	$(LIBRARIES)
	objcopy --strip-unneeded -R .eh_frame -v $(MAIN_FILE).dll $(MAIN_FILE).dll
	strip -R .strtab MemtestEfi.dll

$(MAIN_FILE).lib: $(OBJS)
	gcc-ar crv OUTPUT/$(MAIN_FILE).lib  $(OBJS)

$(MAIN_FILE).obj: $(MAIN_FILE).c
	$(CC) $(CFLAGS) $(PREPROCESSOR) $(M) -o $(MAIN_FILE).obj  \
	-MMD -MF OUTPUT/$(MAIN_FILE).obj.deps \
	-c \
	-include memtest86+/efi/Include/AutoGen.h \
	-DSTRING_ARRAY_NAME=${MAIN_FILE}Strings \
	-I . \
	-I"memtest86+"  \
	-I"memtest86+/efi/Include" \
	$(MAIN_FILE).c

AutoGen.obj: memtest86+/efi/Include/AutoGen.c
	$(CC) $(CFLAGS) $(PREPROCESSOR) $(M) -o AutoGen.obj \
	-c \
	-I"./" \
	-I"memtest86+/efi/Include/" \
	-I"memtest86+/efi/Include/Uefi" \
	-I"memtest86+/efi/Include/Library" \
	memtest86+/efi/Include/AutoGen.c

%.o: memtest86+/%.c
	$(CC) $(CFLAGS) $(PREPROCESSOR) $(M) -c -o $@ $< \
	-I"memtest86+/efi"

%.o: memtest86+/efi/Include/src/%.c
	$(CC) $(CFLAGS) $(PREPROCESSOR) $(M) -c -o $@ $< \
	-I"memtest86+/efi/Include" \
	-I"memtest86+/efi/Include/Library"

%.o: memtest86+/efi/Include/src/UefiLib/%.c
	$(CC) $(CFLAGS) $(PREPROCESSOR) $(M) -c -o $@ $< \
	-I"memtest86+/efi/Include" \
	-I"memtest86+/efi/Include/Protocol" \
	-I"memtest86+/efi/Include/Guid"

BasePcdLibNull.o: memtest86+/efi/Include/src/PcdLib.c
	$(CC) $(CFLAGS) $(PREPROCESSOR) $(M) -c -o $@ $< \
	-I"memtest86+/efi/Include"

UefiMemoryAllocationLib.o: memtest86+/efi/Include/src/MemoryAllocationLib.c
	$(CC) $(CFLAGS) $(PREPROCESSOR) $(M) -c -o $@ $< \
	-I"memtest86+/efi/Include"

UefiLib2.o: Acpi.o Console.o UefiDriverModel.o UefiLib.o UefiLibPrint.o UefiNotTiano.o
	ld -r Acpi.o Console.o UefiDriverModel.o UefiLib.o UefiLibPrint.o UefiNotTiano.o -o UefiLib2.o

%.o: memtest86+/efi/Include/src/UefiDebugLibStdErr/%.c
	$(CC) $(CFLAGS) $(PREPROCESSOR) $(M) -c -o $@ $< \
	-I"memtest86+/efi/Include"

UefiDebugLibStdErr.o: DebugLib.o DebugLibConstructor.o
	ld -r DebugLib.o DebugLibConstructor.o -o UefiDebugLibStdErr.o

%.o: memtest86+/efi/Include/src/BaseMemoryLib/%.c
	$(CC) $(CFLAGS) $(PREPROCESSOR) $(M) -c -o $@ $< \
	-I"memtest86+/efi/Include"

BaseMemoryLib.o: $(BaseMemoryLib_OBJS)
	ld -r $(BaseMemoryLib_OBJS) -o BaseMemoryLib.o

%.o: memtest86+/efi/Include/src/BasePrintLib/%.c
	$(CC) $(CFLAGS) $(PREPROCESSOR) $(M) -c -o $@ $< \
	-I"memtest86+/efi/Include"

BasePrintLib.o: PrintLib.o PrintLibInternal.o
	ld -r PrintLib.o PrintLibInternal.o -o BasePrintLib.o

%.o: memtest86+/efi/Include/src/UefiDevicePathLib/%.c
	$(CC) $(CFLAGS) $(PREPROCESSOR) $(M) -c -o $@ $< \
	-I"memtest86+/efi/Include"

UefiDevicePathLib2.o: $(UefiDevicePathLib_OBJS)
	ld -r $(UefiDevicePathLib_OBJS) -o UefiDevicePathLib2.o

%.o: memtest86+/efi/%.c
	$(CC) $(CFLAGS) $(PREPROCESSOR) $(M) -c -o $@ $< \
	-I"memtest86+" \
	-I"memtest86+/efi" \
	-I"memtest86+/efi/Include"

clean:
	rm -f OUTPUT/*
	rm -f memtest86+/*.o
	rm -f *.o
	rm -f MemtestEfi.obj
	rm -f MemtestEfi.map
	rm -f MemtestEfi.dll
	rm -f MemtestEfi.efi
	rm -f MemtestEfi.txt
	rm -f AutoGen.obj


move:
	cp MemtestEfi.efi ../test_code/hda-contents

run:
	sudo ./run.sh