This repository has been archived by the owner on Apr 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
105 lines (75 loc) · 1.96 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
# 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
NAME=rvvm
CC?=gcc
CXX?=g++
ifeq ($(CLANG), 1)
CC=clang
CXX=clang++
endif
ifeq ($(TCC), 1)
CC=tcc
endif
OPT_CFLAGS = -O2 -funroll-loops -fno-omit-frame-pointer
BASE_CFLAGS = -std=gnu11 -DVERSION=\"$(VERSION)\" -DARCH=\"$(ARCH)\" -Wall -Wextra -fcommon -fPIC -fstack-protector-all
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 -fsanitize=thread
else
BUILD_TYPE = release
BUILD_TYPE_CFLAGS = -DNDEBUG
DEBUG=0
endif
VERSION := $(COMMIT)-$(BUILD_TYPE)
OBJDIR=$(BUILD_TYPE).$(OS).$(ARCH)
CFLAGS = $(BUILD_TYPE_CFLAGS) $(BASE_CFLAGS) $(OPT_CFLAGS) $(ARCH_CFLAGS)
INCLUDE=-I. -I$(SRCDIR)
LDFLAGS += -ldl -flto
DO_CC=$(CC) $(CFLAGS) $(INCLUDE) -o $@ -c $<
DO_CXX=$(CXX) $(CFLAGS) $(INCLUDE) -o $@ -c $<
$(OBJDIR)/%.o: $(SRCDIR)/%.c
$(DO_CC)
SRC = $(wildcard src/*.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 $(OBJDIR)/*.so
-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