-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathmakefile
182 lines (154 loc) · 3.36 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#
# libconcurrent
# Copyright (C) 2010-2016 sharow
#
CC?=gcc
LD?=ld
NASM=nasm
UNAME=uname
.SUFFIXES: .c .a .o .h .asm
.PHONY: clean help
.PHONY: examples example sample test
.PHONY: install uninstall
.VPATH: ./ ./src ./src/arch/i386 ./src/arch/x86_64 ./src/arch/arm64 ./src/arch/aarch64
VERSION=0.4.2
ifeq ($(ARCH),)
ARCH=$(shell $(UNAME) -m)
endif
ifeq ($(SYSTEM),)
SYSNAME=$(shell $(UNAME) -a)
ifeq ($(findstring Darwin, $(SYSNAME)), Darwin)
SYSTEM=Darwin
else
SYSTEM=$(shell $(UNAME) -o)
endif
endif
NASM_FLAGS=
ifeq ($(findstring true, $(eq $(SYSTEM),Cygwin), $(eq $(SYSTEM),MSys)), true)
NASM_FLAGS+=-f win$(ARCH_BITS)
ifeq ($(ARCH),i686)
NASM_FLAGS+=--prefix _
endif
else ifeq ($(SYSTEM),GNU/Linux)
NASM_FLAGS+=-f elf$(ARCH_BITS)
else ifeq ($(SYSTEM),Darwin)
NASM_FLAGS+=-f macho$(ARCH_BITS) --prefix _
else
NASM_FLAGS+=-f elf$(ARCH_BITS)
endif
AS=$(NASM)
ASFLAGS=$(NASM_FLAGS)
ifeq ($(ARCH),i686)
ARCH_BITS=32
else ifeq ($(ARCH),x86_64)
ARCH_BITS=64
else ifeq ($(ARCH),armv6l)
ARCH=arm
ARCH_BITS=32
AS=as
ASFLAGS=
else ifeq ($(ARCH),armv7l)
ARCH=arm
ARCH_BITS=32
AS=as
ASFLAGS=
else ifeq ($(ARCH),arm64) # MacOS, iOS, etc
ifeq ($(SYSTEM), Darwin) # only target MacOS
ARCH=arm64
ARCH_BITS=64
AS=as
ASFLAGS=
else ifeq ($(SYSTEM), FreeBSD)
ARCH=aarch64
ARCH_BITS=64
AS=as
ASFLAGS=
endif
else ifeq ($(ARCH), aarch64) # Linux
ARCH=aarch64
ARCH_BITS=64
AS=as
ASFLAGS=
else
ARCH_BITS=32
endif
# FreeBSD has its own uname -m style
ifeq ($(SYSTEM),FreeBSD)
DESTDIR?=/usr/local
ifeq ($(ARCH),amd64)
ARCH=x86_64
ARCH_BITS=64
else ifeq ($(ARCH),i386)
ARCH=i686
ARCH_BITS=32
else ifeq ($(ARCH),arm) # arm not tested, just a guess
ARCH_BITS=32
AS=as
ASFLAGS=
endif
else ifeq ($(ARCH),arm64)
ARCH_BITS=64
AS=as
ASFLAGS=
else ifeq ($(ARCH),aarch64)
ARCH_BITS=64
AS=as
ASFLAGS=
else
DESTDIR?=/usr
endif
CFLAGS+=-Wall
CFLAGS+=-std=c11
CFLAGS+=-Wstrict-aliasing
CFLAGS+=-fno-stack-protector # for Ubuntu gcc patch
ifeq ($(DEBUG),yes)
CFLAGS+=-DCONCURRENT_DEBUG
CFLAGS+=-g -ggdb
else ifneq ($(SYSTEM),FreeBSD)
CFLAGS+=-O2
endif
TARGET=libconcurrent.a
INCDIR+=-I.
INCDIR+=-I./include
INCDIR+=-I./src
SOURCE_ARCH=src/arch/$(ARCH)/concurrent_arch.asm
OBJECT_ARCH=src/arch/$(ARCH)/concurrent_arch.o
SOURCE+=src/concurrent.c
OBJECT+=$(subst .c,.o, $(SOURCE))
OBJECT+=$(OBJECT_ARCH)
all: $(TARGET)
example: examples
sample: examples
examples: $(TARGET)
$(MAKE) -C examples
test: $(TARGET)
$(MAKE) -C test
$(TARGET): $(OBJECT)
$(AR) crv $(TARGET) $(OBJECT)
help:
@echo "make [clean|help|examples|test|install|uninstall]"
install: $(TARGET)
install -Dm644 libconcurrent.a $(DESTDIR)/lib/libconcurrent.a
mkdir -p $(DESTDIR)/include/concurrent
install -Dm644 include/concurrent/concurrent.h $(DESTDIR)/include/concurrent/concurrent.h
install -Dm644 include/concurrent/shortname.h $(DESTDIR)/include/concurrent/shortname.h
uninstall:
rm $(DESTDIR)/lib/libconcurrent.a
rm $(DESTDIR)/include/concurrent/concurrent.h
rm $(DESTDIR)/include/concurrent/shortname.h
rmdir $(DESTDIR)/include/concurrent
clean:
@$(MAKE) -C examples clean
@$(MAKE) -C test clean
@rm -f $(OBJECT)
@rm -f $(TARGET)
# suffix rule
.c.o:
$(CC) $(CFLAGS) $(DEFS) $(INCDIR) -c $< -o $@
.asm.o:
$(AS) $(ASFLAGS) $< -o $@
depend:
$(RM) -f depend.inc
$(CC) $(CFLAGS) $(INCDIR) -MM $(SOURCE) > depend.inc
concurrent_arch.o: concurrent_arch.asm
include depend.inc