-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
126 lines (106 loc) · 2.91 KB
/
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
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
# extra / local unversioned includes, if present (e.g. debug CFLAGS)
EXTRAMKS := $(wildcard *.mk)
MAKEFILES := Makefile $(EXTRAMKS)
-include $(EXTRAMKS)
SRCDIR := src
ifeq ($(origin WINDOWS), undefined)
PROG := das
BUILDDIR := build
ifneq ($(origin LINUX_BUILD_32BIT), undefined)
# I run 64-bit but normally build 32-bit so the distributed binaries will
# work for more people.
CFLAGS += -m32
LDFLAGS += -m32
endif
else
PROG := das.exe
CROSS_COMPILE ?= i586-mingw32msvc-
BUILDDIR := win32_build
endif
ifneq ($(origin JAMZ), undefined)
$(info wibble)
endif
ifeq ($(origin CC), default)
CC = $(CROSS_COMPILE)gcc
endif
STRIP ?= $(CROSS_COMPILE)strip
OBJDIR := $(BUILDDIR)
DEPDIR := $(BUILDDIR)/dep
# quietness
ifneq (1,$(V))
override Q=@
else
override Q=
endif
CSRCS := y.tab.c lex.yy.c dasdefs.c das.c instruction.c symbol.c expression.c \
statement.c dat.c output.c
CSRCS:=$(addprefix $(SRCDIR)/, $(CSRCS))
#YACCIN := $(SRCDIR)/das.y
#YACCOUT := $(YACCIN:%.y=$(BUILDDIR)/lex.%.c)
#YACCSRC := $(YACCOUT:%.c=%.o)
#LEXIN := $(SRCDIR)/das.l
#LEXOUT := $(LEXIN:$(SRCDIR)/%.l
#CSRCS:=$(CSRCS) $(YACCSRC) $(LEXSRC)
SRCS:=$(CSRCS)
OBJS:=$(SRCS:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
DEPS:=$(SRCS:$(SRCDIR)/%.c=$(DEPDIR)/%.d)
EXTRA_CLEANS:=
-include $(DEPS)
CFLAGS += -Wall -g
.SUFFIXES:
#MAKEFLAGS += --no-builtin-rules
.DEFAULT_GOAL := $(PROG)
$(SRCDIR)/y.tab.c $(SRCDIR)/y.tab.h: $(SRCDIR)/das.y $(MAKEFILES)
ifeq (1,$(USE_YACC))
@echo " YACC $<"
$(Q)yacc $(YACCFLAGS) -d -o $@ $<
EXTRA_CLEANS += $(SRCDIR)/y.tab.c $(SRCDIR)/y.tab.h
else
@echo " KEEP $@ (USE_YACC not set)"
$(Q)touch $@
endif
$(SRCDIR)/lex.yy.c: $(SRCDIR)/das.l $(SRCDIR)/y.tab.h $(MAKEFILES)
ifeq (1,$(USE_LEX))
@echo " LEX $<"
$(Q)lex $(LEXFLAGS) -o$@ $<
EXTRA_CLEANS += $(SRCDIR)/lex.yy.c
else
@echo " KEEP $@ (USE_LEX not set)"
$(Q)touch $@
endif
$(PROG): $(OBJS) $(LINKERSCRIPT)
@echo " LINK $@"
$(Q)$(CC) $(LDFLAGS) $(OBJS) -o $@
$(OBJDIR)/%.o: $(SRCDIR)/%.c $(MAKEFILES)
@echo " CC $<"
@mkdir -p $(dir $@)
$(Q)$(CC) -c $(CFLAGS) -MD $< -o $@
# -MD creates both .d and .o in one pass. Now process the .d file
@mkdir -p $(dir $(DEPDIR)/$*); \
cp $(OBJDIR)/$*.d $(DEPDIR)/$*.d; \
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
-e '/^$$/ d' -e 's/$$/ :/' < $(OBJDIR)/$*.d >> $(DEPDIR)/$*.d; \
rm -f $(OBJDIR)/$*.d
.PHONY: clean
clean:
rm -rf $(PROG) $(BUILDDIR) $(EXTRA_CLEANS)
ifeq ($(origin WINDOWS), undefined)
.PHONY: install
install: $(PROG)
$(Q)$(STRIP) $(PROG)
@if [ -w /usr/bin ]; then \
echo "Installing to /usr/bin"; \
INSTALLDIR=/usr/bin; \
elif [ -w $$HOME/bin ]; then \
echo "/usr/bin not writable (need sudo?)"; \
echo "installing to $$HOME/bin"; \
INSTALLDIR=$$HOME/bin; \
else \
echo "Error: /usr/bin and $$HOME/bin not writable. Install where?"; \
false; \
fi && cp $(PROG) $$INSTALLDIR
endif
.PHONY: test
test: $(PROG)
@echo Run blackbox tests:
$(Q)cd tests && ./blackbox.pl