-
Notifications
You must be signed in to change notification settings - Fork 49
/
Makefile
73 lines (57 loc) · 1.71 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
-include config.mk
PLATFORM?= $(shell uname)
CC?=gcc
AR?=ar
LAC=lautoc.c
LAC_OBJ=lautoc.o
LAC_CPPFLAGS= -I./include $(LUA_INCLUDE_DIR)
LAC_CFLAGS= -std=gnu99 -Wall -Werror -Wno-unused -O3 -g
LAC_LDFLAGS= $(LUA_LIBRARY_DIR)
LAC_LIBS= $(LUA_LIBRARY)
EXAMPLES_SRC= $(wildcard examples/*.c)
EXAMPLES_OUT= $(EXAMPLES_SRC:%.c=%$(EXE_SUFFIX))
SHARED_LIB= $(SHARED_LIB_PREFIX)lautoc$(SHARED_LIB_SUFFIX)
STATIC_LIB= $(STATIC_LIB_PREFIX)lautoc$(STATIC_LIB_SUFFIX)
ifeq ($(findstring Linux,$(PLATFORM)),Linux)
LUA_INCLUDE_DIR?= -I/usr/include/lua5.2/
LUA_LIBRARY?= -llua5.2
LAC_CFLAGS+= -fPIC
LAC_LDFLAGS+= -fPIC
SHARED_LIB_PREFIX:=lib
SHARED_LIB_SUFFIX:=.so
STATIC_LIB_PREFIX:=lib
STATIC_LIB_SUFFIX:=.a
EXE_SUFFIX:=
else ifeq ($(findstring Darwin,$(PLATFORM)),Darwin)
LUA_INCLUDE_DIR?= -I/usr/include/lua5.2/
LUA_LIBRARY?= -llua5.2
LAC_CFLAGS+= -fPIC
LAC_LDFLAGS+= -fPIC
SHARED_LIB_PREFIX:=lib
SHARED_LIB_SUFFIX:=.so
STATIC_LIB_PREFIX:=lib
STATIC_LIB_SUFFIX:=.a
EXE_SUFFIX:=
else ifeq ($(findstring MINGW,$(PLATFORM)),MINGW)
LUA_LIBRARY?= -llua
LAC_LIBS+= -lmingw32
SHARED_LIB_PREFIX:=
SHARED_LIB_SUFFIX:=.dll
STATIC_LIB_PREFIX:=
STATIC_LIB_SUFFIX:=.lib
EXE_SUFFIX:=.exe
endif
# Library
all: $(SHARED_LIB) $(STATIC_LIB)
$(SHARED_LIB): $(LAC)
$(CC) $^ $(CFLAGS) $(LAC_CFLAGS) $(LAC_CPPFLAGS) $(LDFLAGS) $(LAC_LDFLAGS) $(LAC_LIBS) -shared -o $@
$(STATIC_LIB): $(LAC)
$(CC) $^ $(CFLAGS) $(LAC_CFLAGS) $(LAC_CPPFLAGS) -c
$(AR) rcs $@ $(LAC_OBJ)
# Examples
examples: $(EXAMPLES_OUT)
examples/example_%$(EXE_SUFFIX): examples/example_%.c $(LAC)
$(CC) $^ $(CFLAGS) $(LAC_CFLAGS) $(LAC_CPPFLAGS) $(LDFLAGS) $(LAC_LDFLAGS) $(LAC_LIBS) -o $@
# Clean
clean:
$(RM) $(LAC_OBJ) $(EXAMPLES_OUT) $(SHARED_LIB) $(STATIC_LIB)