-
Notifications
You must be signed in to change notification settings - Fork 39
/
Makefile.nall
122 lines (109 loc) · 2.68 KB
/
Makefile.nall
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
# Makefile
# author: byuu
# license: public domain
[A-Z] = A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
[a-z] = a b c d e f g h i j k l m n o p q r s t u v w x y z
[0-9] = 0 1 2 3 4 5 6 7 8 9
[markup] = ` ~ ! @ \# $$ % ^ & * ( ) - _ = + [ { ] } \ | ; : ' " , < . > / ?
[all] = $([A-Z]) $([a-z]) $([0-9]) $([markup])
[space] :=
[space] +=
# platform detection
ifeq ($(platform),)
uname := $(shell uname -s)
ifeq ($(uname),)
platform := windows
delete = del $(subst /,\,$1)
else ifneq ($(findstring Windows,$(uname)),)
platform := windows
delete = del $(subst /,\,$1)
else ifneq ($(findstring CYGWIN,$(uname)),)
platform := windows
delete = del $(subst /,\,$1)
else ifneq ($(findstring Darwin,$(uname)),)
platform := macosx
delete = rm -f $1
else ifneq ($(findstring BSD,$(uname)),)
platform := bsd
delete = rm -f $1
else
platform := linux
delete = rm -f $1
endif
endif
# compiler detection
ifeq ($(compiler),)
ifeq ($(platform),windows)
compiler := g++
flags :=
link :=
else ifeq ($(platform),macosx)
compiler := clang++
flags := -w -stdlib=libc++
link := -lc++ -lobjc
else ifeq ($(platform),bsd)
compiler := clang++
flags := -w -I/usr/local/include
else
compiler := g++
flags :=
link :=
endif
cflags := -x c -std=c99
objcflags := -x objective-c -std=c99
cppflags := -x c++ -std=c++11
objcppflags := -x objective-c++ -std=c++11
endif
# cross-compilation support
ifeq ($(arch),x86)
flags := -m32 $(flags)
link := -m32 $(link)
endif
ifeq ($(prefix),)
prefix := /usr/local
endif
# function rwildcard(directory, pattern)
rwildcard = \
$(strip \
$(filter $(if $2,$2,%), \
$(foreach f, \
$(wildcard $1*), \
$(eval t = $(call rwildcard,$f/)) \
$(if $t,$t,$f) \
) \
) \
)
# function strtr(source, from, to)
strtr = \
$(eval __temp := $1) \
$(strip \
$(foreach c, \
$(join $(addsuffix :,$2),$3), \
$(eval __temp := \
$(subst $(word 1,$(subst :, ,$c)),$(word 2,$(subst :, ,$c)),$(__temp)) \
) \
) \
$(__temp) \
)
# function strupper(source)
strupper = $(call strtr,$1,$([a-z]),$([A-Z]))
# function strlower(source)
strlower = $(call strtr,$1,$([A-Z]),$([a-z]))
# function strlen(source)
strlen = \
$(eval __temp := $(subst $([space]),_,$1)) \
$(words \
$(strip \
$(foreach c, \
$([all]), \
$(eval __temp := \
$(subst $c,$c ,$(__temp)) \
) \
) \
$(__temp) \
) \
)
# function streq(source)
streq = $(if $(filter-out xx,x$(subst $1,,$2)$(subst $2,,$1)x),,1)
# function strne(source)
strne = $(if $(filter-out xx,x$(subst $1,,$2)$(subst $2,,$1)x),1,)