-
Notifications
You must be signed in to change notification settings - Fork 56
/
Makefile-all
106 lines (84 loc) · 2.47 KB
/
Makefile-all
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
#This file can be called with `make -f Makefile-all`
#The windows build for this file uses mingw
THIS = Makefile-all
# Compiler
CC = _
CC_WIN32 = i686-w64-mingw32-gcc
CC_WIN64 = x86_64-w64-mingw32-gcc
CC_LINUX = gcc
CC_MACOS = gcc
MAKEDIR = @mkdir -p $(@D)
PLATFORMDIR = _
BUILDDIR = $(PLATFORMDIR)release/
NAME_LIB = libwjelement
CFLAGS += -Wall -Wextra -DWJE_DISTINGUISH_INTEGER_TYPE -Iinclude
release: export CFLAGS=-O3
release: all
debug: export CFLAGS=-g -DDEBUG
debug: all
HDRDIR = ./include/
SRCDIR = ./src/
OBJDIR = $(BUILDDIR)obj/
# Set platform-specific variables
ifeq ($(OS),Windows_NT)
OSFLAG := "WIN"
PLATFORMDIR = ./windows/
ifeq ($(PROCESSOR_ARCHITECTURE),x86)
CC := $(CC_WIN32)
endif
ifeq ($(PROCESSOR_ARCHITECTURE),AMD64)
CC := $(CC_WIN64)
endif
else
UNAME_S := $(shell uname -s)
PLATFORMDIR = ./unix/
ifeq ($(UNAME_S),Linux)
OSFLAG := "LINUX"
CC := $(CC_LINUX)
CFLAGS += -fPIC
endif
ifeq ($(UNAME_S),Darwin)
OSFLAG := "MACOS"
CC := $(CC_MACOS)
endif
endif
SRCS = lib/xpl.c \
wjelement/element.c \
wjelement/schema.c \
wjelement/hash.c \
wjelement/search.c \
wjelement/types.c \
wjreader/wjreader.c \
wjwriter/wjwriter.c
OBJS = ${SRCS:%.c=$(OBJDIR)%.o}
all: $(NAME_LIB)_static $(NAME_LIB)_dynamic
# This rule compiles object files from source files
$(OBJDIR)%.o : $(SRCDIR)%.c
@$(MAKEDIR)
@printf "Compiling file: "$@" -> "
@$(CC) $(CFLAGS) -c $< -o $@ -I$(HDRDIR)
@printf $(GREEN)"OK!"$(RESET)"\n"
#This rule compiles the static version of libwjelement
$(BUILDDIR)$(NAME_LIB).a: $(OBJS)
@ar rs $@ $(OBJS)
#This rule compiles the static version of libwjelement
$(NAME_LIB)_static: $(BUILDDIR)$(NAME_LIB).a
#This rule compiles the platform-specific dynamic version of libwjelement
$(NAME_LIB)_dynamic: $(OBJS)
@if [ $(OSFLAG) = "WIN" ]; then printf \
"Compiling DLL: "$(BUILDDIR)$(NAME_LIB).dll" -> " ; \
$(CC) -shared -o $(BUILDDIR)$(NAME_LIB).dll $(CFLAGS) $(OBJS) \
-Wl,--output-def,$(BUILDDIR)$(NAME_LIB).def \
-Wl,--out-implib,$(BUILDDIR)$(NAME_LIB).lib \
-Wl,--export-all-symbols ; \
elif [ $(OSFLAG) = "MACOS" ]; then printf \
"Compiling dylib: "$(BUILDDIR)$(NAME_LIB).dylib" -> " ; \
$(CC) -shared -o $(BUILDDIR)$(NAME_LIB).dylib $(CFLAGS) $(OBJS) ; \
elif [ $(OSFLAG) = "LINUX" ]; then \
printf "Compiling so: "$(BUILDDIR)$(NAME_LIB).so" -> " ; \
$(CC) -shared -o $(BUILDDIR)$(NAME_LIB).so $(CFLAGS) $(OBJS) ; \
fi
@printf $(GREEN)"OK!"$(RESET)"\n"
clean:
@rm -rf $(BUILDDIR)*
re: clean all