forked from brechtsanders/xlsxio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
236 lines (197 loc) · 7.59 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# parameters:
# PREFIX=<path> Path were install places files (defaults to /usr/local)
# WITH_LIBZIP=1 Use libzip instead of minizip
# WIDE=1 Also build UTF-16 library (xlsxio_readw) - experimental, only tested on Windows
# STATICDLL=1 Build a static DLL (= doesn't depend on any other DLLs) - only supported on Windows
ifeq ($(OS),)
OS = $(shell uname -s)
endif
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 -Ilib
CFLAGS = $(INCS) -Os
CPPFLAGS = $(INCS) -Os
STATIC_CFLAGS = -DBUILD_XLSXIO_STATIC
SHARED_CFLAGS = -DBUILD_XLSXIO_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)
OSALIAS := $(OS)
ifeq ($(OS),Windows_NT)
ifneq (,$(findstring x86_64,$(shell gcc --version)))
OSALIAS := win64
else
OSALIAS := win32
endif
endif
ifdef WITH_LIBZIP
ZIPLIB_LDFLAGS = -lzip
ZIPLIB_DEPS_LDFLAGS = -Wl,--as-needed -lz -lbz2 -lcrypto -lgdi32
CFLAGS += -DUSE_LIBZIP
else
ZIPLIB_LDFLAGS = -lminizip
ZIPLIB_DEPS_LDFLAGS = -Wl,--as-needed -lz
CFLAGS += -DUSE_MINIZIP
endif
XLSXIOREAD_OBJ = lib/xlsxio_read.o lib/xlsxio_read_sharedstrings.o
XLSXIOREAD_LDFLAGS = $(ZIPLIB_LDFLAGS) -lexpat
XLSXIOREADW_LDFLAGS = $(ZIPLIB_LDFLAGS) -lexpatw
XLSXIOREAD_SHARED_LDFLAGS =
XLSXIOWRITE_OBJ = lib/xlsxio_write.o
XLSXIOWRITE_LDFLAGS = $(ZIPLIB_LDFLAGS)
XLSXIOWRITE_SHARED_LDFLAGS =
ifneq ($(OS),Windows_NT)
SHARED_CFLAGS += -fPIC
endif
ifeq ($(OS),Windows_NT)
XLSXIOREAD_SHARED_LDFLAGS += -Wl,--out-implib,$@$(LIBEXT) -Wl,--compat-implib -Wl,--output-def,$(@:%.dll=%.def)
XLSXIOWRITE_SHARED_LDFLAGS += -Wl,--out-implib,$@$(LIBEXT) -Wl,--compat-implib -Wl,--output-def,$(@:%.dll=%.def)
else ifeq ($(OS),Darwin)
else
XLSXIOWRITE_LDFLAGS += -pthread
endif
ifeq ($(OS),Darwin)
OS_LINK_FLAGS = -dynamiclib -o $@
else
OS_LINK_FLAGS = -shared -Wl,-soname,$@ $(STRIPFLAG)
endif
ifdef STATICDLL
ifeq ($(OS),Windows_NT)
# lines below to compile Windows DLLs with no dependancies
ifdef WITH_LIBZIP
CFLAGS += -DZIP_STATIC
endif
XLSXIOREAD_LDFLAGS += -static $(ZIPLIB_DEPS_LDFLAGS)
XLSXIOREADW_LDFLAGS += -static $(ZIPLIB_DEPS_LDFLAGS)
XLSXIOWRITE_LDFLAGS += -static $(ZIPLIB_DEPS_LDFLAGS)
endif
endif
LIBLIST = xlsxio_read xlsxio_write
TOOLS_BIN = xlsxio_xlsx2csv$(BINEXT) xlsxio_csv2xlsx$(BINEXT)
EXAMPLES_BIN = example_xlsxio_write_getversion$(BINEXT) example_xlsxio_write$(BINEXT) example_xlsxio_read$(BINEXT) example_xlsxio_read_advanced$(BINEXT)
ifdef WIDE
CFLAGS_W = $(CFLAGS) -DXML_UNICODE
LIBLIST += xlsxio_readw
EXAMPLES_BIN += example_xlsxio_readw$(BINEXT)
endif
COMMON_PACKAGE_FILES = README.md LICENSE.txt Changelog.txt
SOURCE_PACKAGE_FILES = $(COMMON_PACKAGE_FILES) Makefile CMakeLists.txt CMake/ *.in doc/Doxyfile include/*.h lib/*.c lib/*.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: $(LIBLIST:%=$(LIBPREFIX)%$(LIBEXT))
shared-lib: $(LIBLIST:%=$(LIBPREFIX)%$(SOEXT))
$(LIBPREFIX)xlsxio_read$(LIBEXT): $(XLSXIOREAD_OBJ:%.o=%.static.o)
$(AR) cr $@ $^
$(LIBPREFIX)xlsxio_read$(SOEXT): $(XLSXIOREAD_OBJ:%.o=%.shared.o)
$(CC) -o $@ $(OS_LINK_FLAGS) $^ $(XLSXIOREAD_SHARED_LDFLAGS) $(XLSXIOREAD_LDFLAGS) $(LDFLAGS) $(LIBS)
$(LIBPREFIX)xlsxio_write$(LIBEXT): $(XLSXIOWRITE_OBJ:%.o=%.static.o)
$(AR) cr $@ $^
$(LIBPREFIX)xlsxio_write$(SOEXT): $(XLSXIOWRITE_OBJ:%.o=%.shared.o)
$(CC) -o $@ $(OS_LINK_FLAGS) $^ $(XLSXIOWRITE_SHARED_LDFLAGS) $(XLSXIOWRITE_LDFLAGS) $(LDFLAGS) $(LIBS)
ifdef WIDE
%.wstatic.o: %.c
$(CC) -c -o $@ $< $(STATIC_CFLAGS) $(CFLAGS_W)
%.wshared.o: %.c
$(CC) -c -o $@ $< $(SHARED_CFLAGS) $(CFLAGS_W)
$(LIBPREFIX)xlsxio_readw$(LIBEXT): $(XLSXIOREAD_OBJ:%.o=%.wstatic.o)
$(AR) cr $@ $^
$(LIBPREFIX)xlsxio_readw$(SOEXT): $(XLSXIOREAD_OBJ:%.o=%.wshared.o)
$(CC) -o $@ $(OS_LINK_FLAGS) $^ $(XLSXIOREAD_SHARED_LDFLAGS) $(XLSXIOREADW_LDFLAGS) $(LIBS)
endif
examples: $(EXAMPLES_BIN)
example_xlsxio_write_getversion$(BINEXT): examples/example_xlsxio_write_getversion.static.o $(LIBPREFIX)xlsxio_write$(LIBEXT)
$(CC) -o $@ examples/$(@:%$(BINEXT)=%.static.o) $(LIBPREFIX)xlsxio_write$(LIBEXT) $(XLSXIOWRITE_LDFLAGS) $(LDFLAGS)
example_xlsxio_write$(BINEXT): examples/example_xlsxio_write.static.o $(LIBPREFIX)xlsxio_write$(LIBEXT)
$(CC) -o $@ examples/$(@:%$(BINEXT)=%.static.o) $(LIBPREFIX)xlsxio_write$(LIBEXT) $(XLSXIOWRITE_LDFLAGS) $(LDFLAGS)
example_xlsxio_read$(BINEXT): examples/example_xlsxio_read.static.o $(LIBPREFIX)xlsxio_read$(LIBEXT)
$(CC) -o $@ examples/$(@:%$(BINEXT)=%.static.o) $(LIBPREFIX)xlsxio_read$(LIBEXT) $(XLSXIOREAD_LDFLAGS) $(LDFLAGS)
example_xlsxio_read_advanced$(BINEXT): examples/example_xlsxio_read_advanced.static.o $(LIBPREFIX)xlsxio_read$(LIBEXT)
$(CC) -o $@ examples/$(@:%$(BINEXT)=%.static.o) $(LIBPREFIX)xlsxio_read$(LIBEXT) $(XLSXIOREAD_LDFLAGS) $(LDFLAGS)
ifdef WIDE
example_xlsxio_readw$(BINEXT): examples/example_xlsxio_read.wstatic.o $(LIBPREFIX)xlsxio_readw$(LIBEXT)
$(CC) -o $@ examples/$(@:%w$(BINEXT)=%.wstatic.o) $(LIBPREFIX)xlsxio_readw$(LIBEXT) $(XLSXIOREADW_LDFLAGS) $(LDFLAGS)
endif
tools: $(TOOLS_BIN)
xlsxio_xlsx2csv$(BINEXT): src/xlsxio_xlsx2csv.static.o $(LIBPREFIX)xlsxio_read$(LIBEXT)
$(CC) -o $@ $< $(LIBPREFIX)xlsxio_read$(LIBEXT) $(XLSXIOREAD_LDFLAGS) $(LDFLAGS)
xlsxio_csv2xlsx$(BINEXT): src/xlsxio_csv2xlsx.static.o $(LIBPREFIX)xlsxio_write$(LIBEXT)
$(CC) -o $@ $< $(LIBPREFIX)xlsxio_write$(LIBEXT) $(XLSXIOWRITE_LDFLAGS) $(LDFLAGS)
.PHONY: doc
doc:
ifdef DOXYGEN
$(DOXYGEN) doc/Doxyfile
endif
install: all doc
$(MKDIR) $(PREFIX)/include $(PREFIX)/lib $(PREFIX)/bin
$(CP) include/*.h $(PREFIX)/include/
$(CP) *$(LIBEXT) $(PREFIX)/lib/
ifeq ($(OS),Windows_NT)
$(CP) *.def $(PREFIX)/lib/
$(CP) *$(SOEXT) $(PREFIX)/bin/
else
$(CP) *$(SOEXT) $(PREFIX)/lib/
endif
$(CP) $(TOOLS_BIN) $(PREFIX)/bin/
ifdef DOXYGEN
$(CPDIR) doc/man $(PREFIX)/
$(MKDIR) $(PREFIX)/share/xlsxio
$(CPDIR) doc/html $(PREFIX)/share/xlsxio/
endif
.PHONY: version
version:
sed -ne "s/^#define\s*XLSXIO_VERSION_[A-Z]*\s*\([0-9]*\)\s*$$/\1./p" include/xlsxio_version.h | tr -d "\n" | sed -e "s/\.$$//" > version
.PHONY: package
package: version
tar cfJ xlsxio-$(shell cat version).tar.xz --transform="s?^?xlsxio-$(shell cat version)/?" $(SOURCE_PACKAGE_FILES)
.PHONY: package
binarypackage: version
$(MAKE) PREFIX=binpkg_$(OSALIAS)_temp install STATICDLL=1 WIDE=1
ifneq ($(OS),Windows_NT)
tar cfJ "xlsxio-$(shell cat version)-$(OSALIAS).tar.xz" --transform="s?^binpkg_$(OSALIAS)_temp/??" $(COMMON_PACKAGE_FILES) binpkg_$(OSALIAS)_temp/*
else
rm -f xlsxio-$(shell cat version)-$(OSALIAS).zip
cp -f $(COMMON_PACKAGE_FILES) binpkg_$(OSALIAS)_temp/
cd binpkg_$(OSALIAS)_temp && zip -r -9 "../xlsxio-$(shell cat version)-binary-$(OSALIAS).zip" $(COMMON_PACKAGE_FILES) * && cd ..
endif
rm -rf binpkg_$(OSALIAS)_temp
.PHONY: clean
clean:
$(RM) lib/*.o examples/*.o src/*.o *$(LIBEXT) *$(SOEXT) $(TOOLS_BIN) $(EXAMPLES_BIN) version xlsxio-*.tar.xz doc/doxygen_sqlite3.db
ifeq ($(OS),Windows_NT)
$(RM) *.def
endif
$(RMDIR) doc/html doc/man