-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
102 lines (71 loc) · 1.86 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
# Makefile :)
OS_UNAME = $(shell uname -s)
ifeq ($(OS_UNAME), Linux)
OS=linux
PROGRAMEXT=
else
OS=windows
PROGRAMEXT=.exe
endif
ifeq ($(OS_UNAME), FreeBSD)
OS=freebsd
PROGRAMEXT=
endif
SRCDIR=src/vm
NAME=stonevm
DEVSTAGE = beta
CC?=gcc
CXX?=g++
ifeq ($(CLANG), 1)
CC=clang
CXX=clang++
endif
OPT_CFLAGS = -O2 -flto -fno-omit-frame-pointer -fPIC -Wall
BASE_CFLAGS = -D__USE_GNU -std=gnu11 -DVERSION=\"$(VERSION)\"
ARCH=$(shell uname -m)
COMMIT := $(firstword $(shell git rev-parse --short=6 HEAD) unknown)
ifeq ($(ARCH), i686)
ARCH_CFLAGS +=-msse3 -march=i686 -mtune=generic
else ifeq ($(ARCH), x86_64)
ARCH_CFLAGS +=-msse3 -mtune=generic
ifeq ($(TARGET_ARCH), i686)
ARCH = i686
ARCH_CFLAGS +=-m32 -msse3 -march=i686 -mtune=generic
endif
else ifeq ($(ARCH), aarch64)
ARCH_CFLAGS +=
else ifeq (, $(findstring arm,$(ARCH_UNAME)))
ARCH_CFLAGS +=
endif
ifeq ($(DEBUG),1)
BUILD_TYPE = debug
BUILD_TYPE_CFLAGS = -g -DDEBUG
#-fsanitize=undefined -fsanitize=address
else
BUILD_TYPE = release
BUILD_TYPE_CFLAGS = -DNDEBUG
endif
VERSION := $(COMMIT)-$(DEVSTAGE)-$(BUILD_TYPE)
OBJDIR=$(BUILD_TYPE).$(OS).$(ARCH)
CFLAGS = $(BUILD_TYPE_CFLAGS) $(BASE_CFLAGS) $(OPT_CFLAGS) $(ARCH_CFLAGS)
INCLUDE=-I. -I$(SRCDIR)
LDFLAGS=-L. -lm
DO_CC=$(CC) $(CFLAGS) $(INCLUDE) -o $@ -c $<
DO_CXX=$(CXX) $(CFLAGS) $(INCLUDE) -o $@ -c $<
$(OBJDIR)/%.o: $(SRCDIR)/%.c
$(DO_CC)
SRC = $(wildcard $(SRCDIR)/*.c)
OBJ := $(SRC:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
$(NAME)_$(ARCH)$(PROGRAMEXT) : neat depend $(OBJ)
$(CC) $(CFLAGS) $(OBJ) $(LDFLAGS) -o $(OBJDIR)/$@
neat:
@mkdir -p $(OBJDIR)
$(OBJDIR): neat
clean: depend
-rm -f $(OBJ)
-rm -f $(OBJDIR)/$(NAME)_$(ARCH)$(PROGRAMEXT)
-rm -f $(OBJDIR)/Rules.depend
depend: $(OBJDIR)/Rules.depend
$(OBJDIR)/Rules.depend: $(SRCFILES) $(OBJDIR)
$(CC) -MM $(INCLUDE) $(SRC) $(CFLAGS) | sed "s;\(^[^ ]*\):\(.*\);$(OBJDIR)/\1:\2;" > $@
include $(OBJDIR)/Rules.depend