summaryrefslogtreecommitdiff
path: root/common.mk
blob: d43a010cf043cce029f06bf135ecd2d91100f6a7 (plain)
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
ifeq ($(SYSTEM),)
    SYSTEM := $(shell uname | cut -f 1 -d_)
endif

TRUESYSTEM := $(shell uname)
MACHINE := $(shell uname -m)
DISTRIB := $(shell cat /etc/issue | cut -f 1 -d\  | head -1)

CC = gcc
CXX = g++
LD = g++
AS = gcc -c
AR = ar rcs

BINEXT = bin

CPPFLAGS += -fno-strict-aliasing

ifeq ($(SYSTEM),Darwin)
    CC = clang
    CXX = clang++
    CPPFLAGS += -fPIC
    LDFLAGS += -fPIC
    ARCH_FLAGS =
    LD = clang++
    STRIP = strip -x
endif

ifeq ($(SYSTEM),Linux)
    CPPFLAGS += -fPIC
    LDFLAGS += -fPIC -rdynamic
    ARCH_FLAGS =
    ASFLAGS =
    STRIP = strip --strip-unneeded

    GCC_VERSION := $(shell g++ --version | head -1 | sed "s/.*\([0-9]\.[0-9]\.[0-9]\).*/\1/")
    GCC_VERSION_4 := $(shell expr `echo $(GCC_VERSION) | cut -f1 -d.` \>= 4)
    GCC_VERSION_x_7 := $(shell expr `echo $(GCC_VERSION) | cut -f2 -d.` \>= 7)
    GCC_VERSION_x_8 := $(shell expr `echo $(GCC_VERSION) | cut -f2 -d.` \>= 8)
    GCC_VERSION_x_x_2 := $(shell expr `echo $(GCC_VERSION) | cut -f3 -d.` \>= 2)
    CLANG_VERSION := $(shell clang --version | head -1 | sed "s/.*\([0-9]\.[0-9]\).*/\1/")
    CLANG_VERSION_3 := $(shell expr `echo $(CLANG_VERSION) | cut -f1 -d.` \>= 3)
    CLANG_VERSION_x_1 := $(shell expr `echo $(CLANG_VERSION) | cut -f2 -d.` \>= 1)

    ifneq ($(GCC_VERSION_4),1)
        USE_CLANG = true
    else
        ifneq ($(GCC_VERSION_x_7),1)
            USE_CLANG = true
        else
            ifneq ($(GCC_VERSION_x_8),1)
                ifneq ($(GCC_VERSION_x_x_2),1)
                    USE_CLANG = true
                endif
            endif
        endif
    endif

    ifeq ($(USE_CLANG),true)
        CC = clang
        CXX = clang++
        LD = clang++
    endif
endif

CXXFLAGS += -Wno-deprecated -std=c++11