-
Notifications
You must be signed in to change notification settings - Fork 16
/
Makefile
155 lines (132 loc) · 4.25 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
PREFIX = /usr/local
CC = gcc
CPP = g++
AR = ar
LIBPREFIX = lib
LIBEXT = .a
ifeq ($(OS),Windows_NT)
BINEXT = .exe
SOEXT = .dll
else ifeq ($(OS),Darwin)
BINEXT =
SOEXT = .dylib
else
BINEXT =
SOEXT = .so
endif
INCS = -Iinclude -Isrc
CFLAGS = $(INCS) -Os
CPPFLAGS = $(INCS) -Os
ifeq ($(OS),)
OS = $(shell uname -s)
ifneq ($(findstring Windows,$(OS))$(findstring MINGW32,$(OS))$(findstring MSYS,$(OS)),)
OS = Windows_NT
endif
endif
PLATFORMNAME = $(OS)
ifeq ($(PLATFORMNAME),Windows_NT)
ifneq ($(findstring x86_64,$(shell $(CC) --version)),)
PLATFORMNAME = win64
else ifneq ($(findstring i686,$(shell $(CC) --version)),)
PLATFORMNAME = win32
endif
endif
ifeq ($(OS),Windows_NT)
# detect if asprintf exists (needed for recent MinGW-w64 versions)
CHECK_ASPRINTF=$(shell echo -e "#define _GNU_SOURCE\n#include <stdio.h>\nint main() {\n char* p;\n asprintf(&p, \".\");\n return 0;\n}\n"|gcc -xc - -ocheck_asprintf.exe -Wall && rm -f check_asprintf.exe && echo OK)
ifeq ($(CHECK_ASPRINTF),OK)
CFLAGS += -DHAVE_VASPRINTF -DHAVE_ASPRINTF
CXXFLAGS += -DHAVE_VASPRINTF -DHAVE_ASPRINTF
endif
endif
STATIC_CFLAGS = -DBUILD_PROXYSOCKET_STATIC
SHARED_CFLAGS = -DBUILD_PROXYSOCKET_DLL
LIBS =
LDFLAGS =
ifeq ($(OS),Darwin)
CFLAGS += -I/opt/local/include -I/opt/local/lib/libzip/include
LDFLAGS += -L/opt/local/lib
#CFLAGS += -arch i386 -arch x86_64
#LDFLAGS += -arch i386 -arch x86_64
STRIPFLAG =
else
STRIPFLAG = -s
endif
MKDIR = mkdir -p
RM = rm -f
RMDIR = rm -rf
CP = cp -f
CPDIR = cp -rf
DOXYGEN := $(shell which doxygen)
PROXYSOCKET_OBJ = src/proxysocket.o
PROXYSOCKET_LDFLAGS =
PROXYSOCKET_SHARED_LDFLAGS =
ifneq ($(OS),Windows_NT)
SHARED_CFLAGS += -fPIC
endif
ifeq ($(OS),Windows_NT)
PROXYSOCKET_SHARED_LDFLAGS += -Wl,--out-implib,$@$(LIBEXT) -lws2_32
PROXYSOCKET_LDFLAGS += -lws2_32
endif
ifeq ($(OS),Darwin)
OS_LINK_FLAGS = -dynamiclib -o $@
else
OS_LINK_FLAGS = -shared -Wl,-soname,$@ $(STRIPFLAG)
endif
TOOLS_BIN = ipify$(BINEXT)
EXAMPLES_BIN = proxysocket_test$(BINEXT)
COMMON_PACKAGE_FILES = README.md LICENSE.txt Changelog.txt
SOURCE_PACKAGE_FILES = $(COMMON_PACKAGE_FILES) Makefile doc/Doxyfile src/*.h src/*.c examples/*.c build/*.cbp
default: all
all: static-lib shared-lib tools
%.o: %.c
$(CC) -c -o $@ $< $(CFLAGS)
%.static.o: %.c
$(CC) -c -o $@ $< $(STATIC_CFLAGS) $(CFLAGS)
%.shared.o: %.c
$(CC) -c -o $@ $< $(SHARED_CFLAGS) $(CFLAGS)
static-lib: $(LIBPREFIX)proxysocket$(LIBEXT)
shared-lib: $(LIBPREFIX)proxysocket$(SOEXT)
$(LIBPREFIX)proxysocket$(LIBEXT): $(PROXYSOCKET_OBJ:%.o=%.static.o)
$(AR) cr $@ $^
$(LIBPREFIX)proxysocket$(SOEXT): $(PROXYSOCKET_OBJ:%.o=%.shared.o)
$(CC) -o $@ $(OS_LINK_FLAGS) $^ $(PROXYSOCKET_SHARED_LDFLAGS) $(PROXYSOCKET_LDFLAGS) $(LDFLAGS) $(LIBS)
examples: $(EXAMPLES_BIN)
%$(BINEXT): examples/%.static.o $(LIBPREFIX)proxysocket$(LIBEXT)
$(CC) -o $@ examples/$(@:%$(BINEXT)=%.static.o) $(LIBPREFIX)proxysocket$(LIBEXT) $(PROXYSOCKET_LDFLAGS) $(LDFLAGS)
#%$(BINEXT): examples/%.shared.o $(LIBPREFIX)proxysocket$(LIBEXT)
# $(CC) -o $@ examples/$(@:%$(BINEXT)=%.shared.o) $(LIBPREFIX)proxysocket$(LIBEXT) $(PROXYSOCKET_LDFLAGS) $(LDFLAGS)
tools: $(TOOLS_BIN)
.PHONY: doc
doc:
ifdef DOXYGEN
$(DOXYGEN) doc/Doxyfile
endif
install: all doc
$(MKDIR) $(PREFIX)/include $(PREFIX)/lib $(PREFIX)/bin
$(CP) src/*.h $(PREFIX)/include/
$(CP) *$(LIBEXT) $(PREFIX)/lib/
ifeq ($(OS),Windows_NT)
$(CP) *$(SOEXT) $(PREFIX)/bin/
else
$(CP) *$(SOEXT) $(PREFIX)/lib/
endif
$(CP) $(TOOLS_BIN) $(PREFIX)/bin/
ifdef DOXYGEN
$(CPDIR) doc/man $(PREFIX)/
endif
.PHONY: version
version:
sed -ne "s/^#define\s*PROXYSOCKET_VERSION_[A-Z]*\s*\([0-9]*\)\s*$$/\1./p" src/proxysocket.h | tr -d "\n" | sed -e "s/\.$$//" > version
.PHONY: package
package: version
tar cfJ proxysocket-$(shell cat version).tar.xz --transform="s?^?proxysocket-$(shell cat version)/?" $(SOURCE_PACKAGE_FILES)
.PHONY: package
binarypackage: version
$(MAKE) PREFIX=binarypackage_temp install
tar cfJ "proxysocket-$(shell cat version)-$(PLATFORMNAME).tar.xz" --transform="s?^binarypackage_temp/??" $(COMMON_PACKAGE_FILES) binarypackage_temp/*
rm -rf binarypackage_temp
.PHONY: clean
clean:
$(RM) src/*.o examples/*.o *$(LIBEXT) *$(SOEXT) $(TOOLS_BIN) $(EXAMPLES_BIN) version proxysocket-*.tar.xz doc/doxygen_sqlite3.db
$(RMDIR) doc/html doc/man