aboutsummaryrefslogtreecommitdiff
path: root/scripts/makefile
blob: fc293882107a33f54b0c1f82a5681c50921f3064 (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
# this could be done better
RELEASE		?= 0
OPTFLAGS	!= [ "$(RELEASE)" != "0" ] \
			&& echo "-O2" \
			|| echo "-O0"

LTO		?= 0
LTOFLAGS	!= [ "$(LTO)" != "0" ] \
			&& echo "-flto=auto"

DEBUG		?= 1
DEBUGFLAGS	!= [ "$(DEBUG)" != "0" ] \
			&& echo "-DDEBUG=1" \
			|| echo "-DNDEBUG=1"

ASSERT		?= 1
ASSERTFLAGS	!= [ "$(ASSERT)" != "0" ] \
			&& echo "-DASSERT=1" \
			|| echo

DEPFLAGS	= -MT $@ -MMD -MP -MF $@.d
LINTFLAGS	:= -fsyntax-only
PREPROCESS	:= -E

LLVM		?= 0
BUILD		:= build

all: calc

# default values, overwrite if/when needed
CROSS_COMPILE	:=

OBJCOPY		!= [ "$(LLVM)" != "0" ] \
			&& echo llvm-objcopy \
			|| echo $(CROSS_COMPILE)objcopy

COMPILER	!= [ -n "$(CROSS_COMPILE)" ]						\
			&& {								\
				[ "$(LLVM)" != "0" ]					\
					&& echo clang --target="$(CROSS_COMPILE)"	\
					|| echo $(CROSS_COMPILE)gcc			\
					;						\
			}								\
			|| echo $(CC)


OBFLAGS		:= -g
WARNFLAGS	:= -Wall -Wextra

COMPILE_FLAGS	:= $(CFLAGS) $(WARNFLAGS) $(OPTFLAGS) $(LTOFLAGS) \
		   $(OBFLAGS) $(ASSERTFLAGS) $(DEBUGFLAGS)

INCLUDE_FLAGS	:= -I include

COMPILE		= $(COMPILER) \
		  $(COMPILE_FLAGS) $(DEPFLAGS) $(INCLUDE_FLAGS)

LINT		= $(COMPILER) \
		  $(COMPILE_FLAGS) $(LINTFLAGS) $(INCLUDE_FLAGS)

COMPILE_CALC	= $(COMPILE) $(CALC_FLAGS)

-include deps.mk

calc: $(CALC_OBJS) deps/ejit/ejit.o
	$(COMPILE_CALC) $(CALC_OBJS) deps/ejit/ejit.o -o $@


# might lint some common things twice
.PHONY:
lint: $(EK_LINTS)