forked from cirosantilli/x86-assembly-cheat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasm.makefile
63 lines (51 loc) · 1.1 KB
/
asm.makefile
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
.POSIX:
-include params.makefile
BITS ?= 32
CCC ?= gcc -ggdb3 -m$(BITS) -O0 -pedantic-errors -std=c89 -Wall
CCC_FLAGS ?=
GAS_EXT ?= .S
LIB_DIR ?= lib/
NASM ?= nasm -g -w+all -f elf$(BITS)
NASM_EXT ?= .asm
OBJ_EXT ?= .o
OUT_EXT ?= .out
RUN ?= main
TEST ?= test
export
OUTS := $(foreach IN_EXT,$(GAS_EXT) $(NASM_EXT),$(patsubst %$(IN_EXT),%$(OUT_EXT),$(wildcard *$(IN_EXT))))
.PRECIOUS: %$(OBJ_EXT)
.PHONY: all clean driver run
all: driver $(OUTS)
%$(OUT_EXT): %$(OBJ_EXT)
$(CCC) $(CCC_FLAGS) -o '$@' '$<' $(LIB_DIR)*$(OBJ_EXT)
%$(OBJ_EXT): %$(NASM_EXT)
$(NASM) -o '$@' '$<'
%$(OBJ_EXT): %$(GAS_EXT)
$(CCC) $(CCC_FLAGS) -c -o '$@' '$<'
clean:
rm -f *$(OBJ_EXT) *$(OUT_EXT)
$(MAKE) -C $(LIB_DIR) '$@'
driver:
$(MAKE) -C $(LIB_DIR)
run: all
./'$(RUN)$(OUT_EXT)'
test: all
@\
if [ -x $(TEST) ]; then \
./$(TEST) '$(OUT_EXT)' ;\
else\
fail=false ;\
for t in *"$(OUT_EXT)"; do\
if ! ./"$$t"; then \
fail=true ;\
break ;\
fi ;\
done ;\
if $$fail; then \
echo "TEST FAILED: $$t" ;\
exit 1 ;\
else \
echo 'ALL TESTS PASSED' ;\
exit 0 ;\
fi ;\
fi ;\