-
Notifications
You must be signed in to change notification settings - Fork 1
/
linux.mk
57 lines (42 loc) · 1.57 KB
/
linux.mk
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
# get assemblies
dirs=_internal control parametric variable memory numeric
opcodes_paths=wasmpy/arch/x86/lib/opcodes.cpp wasmpy/arch/x86_64/lib/opcodes.cpp
x86_binaries=$(foreach i,$(dirs),$(foreach j,$(wildcard wasmpy/arch/x86/$(i)/*.s),$(patsubst %.s,%.bin,$(j))))
x86_64_binaries=$(foreach i,$(dirs),$(foreach j,$(wildcard wasmpy/arch/x86_64/$(i)/*.s),$(patsubst %.s,%.bin,$(j))))
binaries=$(x86_binaries) $(x86_64_binaries)
# set defaults
ifeq ($(origin LDFLAGS),undefined)
LDFLAGS=--oformat binary -e 0
endif
ifeq ($(origin X86_ASFLAGS),undefined)
X86_ASFLAGS=--32 $(ASFLAGS)
endif
ifeq ($(origin X86_LDFLAGS),undefined)
X86_LDFLAGS=-melf_i386 $(LDFLAGS)
endif
ifeq ($(origin X86_64_ASFLAGS),undefined)
X86_64_ASFLAGS=$(ASFLAGS)
endif
ifeq ($(origin X86_64_LDFLAGS),undefined)
X86_64_LDFLAGS=$(LDFLAGS)
endif
.PHONY: all clean x86 x86_64
# main commands
all: $(binaries)
clean:
rm -f wasmpy/arch/*/*/*.bin wasmpy/arch/*/*/*.o wasmpy/arch/*/lib/opcodes.cpp
x86: $(x86_binaries)
x86_64: $(x86_64_binaries)
# generate rules for assembly sources
define X86_BIN_FROM_SRC
$(1): $(patsubst %.bin,%.s,$(1))
$(AS) $(X86_ASFLAGS) -o $(patsubst %.bin,%.o,$(1)) $(patsubst %.bin,%.s,$(1))
$(LD) $(X86_LDFLAGS) -o $(1) $(patsubst %.bin,%.o,$(1))
endef
define X86_64_BIN_FROM_SRC
$(1): $(patsubst %.bin,%.s,$(1))
$(AS) $(X86_64_ASFLAGS) -o $(patsubst %.bin,%.o,$(1)) $(patsubst %.bin,%.s,$(1))
$(LD) $(X86_64_LDFLAGS) -o $(1) $(patsubst %.bin,%.o,$(1))
endef
$(eval $(foreach i,$(x86_binaries),$(call X86_BIN_FROM_SRC,$(i))))
$(eval $(foreach i,$(x86_64_binaries),$(call X86_64_BIN_FROM_SRC,$(i))))