-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathMakefile.mingw
188 lines (148 loc) · 5.54 KB
/
Makefile.mingw
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
# $Id: Makefile.mingw,v 1.36 2024/01/04 01:29:56 nanard Exp $
# Miniupnp project.
# http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/
# (c) 2005-2024 Thomas Bernard
# This Makefile is made for MinGW
#
# To cross compile on a *nix machine :
# make -f Makefile.mingw DLLWRAP=mingw32-dllwrap CC=mingw32-gcc AR=mingw32-ar WINDRES=mingw32-windres
#
SRCDIR = src
INCDIR = include
CC ?= gcc
SETUP_COMPILER_FLAG?=
DLLWRAP = dllwrap
WINDRES = windres
SH = /bin/sh
ZIP = zip
ifeq ($(OS),Windows_NT)
RM = del
else
RM = rm -f
endif
CFLAGS ?= -Os
CFLAGS += -Wall
CFLAGS += -W -Wstrict-prototypes
CPPFLAGS += -DNDEBUG -D_WIN32_WINNT=0x501
CPPFLAGS += -Iinclude
CPPFLAGS += -I.
# -liphlpapi is needed for GetBestRoute() and GetIpAddrTable()
LDLIBS = -lws2_32 -liphlpapi
PYTHON=\utils\python25\python
OBJS=miniwget.o minixml.o igd_desc_parse.o minisoap.o \
minissdpc.o \
miniupnpc.o upnpreplyparse.o upnpcommands.o upnperrors.o \
connecthostport.o portlistingparse.o receivedata.o \
upnpdev.o addr_is_reserved.o
OBJSDLL=$(addprefix dll-, $(OBJS)) winres.o
BINARIES=upnpc-static.exe upnpc-shared.exe \
upnp-listdevices-static.exe upnp-listdevices-shared.exe \
miniupnpc.dll libminiupnpc.a \
testminixml.exe
ifneq ($(GITHUB_SHA),)
COMMITREF=$(GITHUB_SHA)
else
ifneq ($(CI_COMMIT_SHORT_SHA),)
COMMITREF=$(CI_COMMIT_SHORT_SHA)
else
COMMITREF=$(shell git rev-parse --short HEAD)
endif
endif
DISTFILE:=$(shell echo "miniupnpc-bin-win32-`cat VERSION`-$(COMMITREF).zip")
LIBDIR ?= lib
# install directories
ifeq ($(strip $(PREFIX)),)
INSTALLPREFIX ?= /usr
else
INSTALLPREFIX ?= $(PREFIX)
endif
.PHONY: all dist clean
all: $(BINARIES)
dist: $(DISTFILE)
clean:
$(RM) miniupnpcstrings.h
$(RM) *.o
$(RM) *.exe
$(RM) miniupnpc.dll miniupnpc.lib miniupnpc.dll.def
$(RM) libminiupnpc.a
$(RM) $(DISTFILE)
$(DISTFILE): $(BINARIES)
$(ZIP) $@ *.exe *.dll *.lib *.def *.a LICENSE README Changelog.txt
libminiupnpc.a: $(OBJS)
$(AR) cr $@ $?
pythonmodule: libminiupnpc.a
$(PYTHON) setupmingw32.py build $(SETUP_COMPILER_FLAG)
$(PYTHON) setupmingw32.py install --skip-build
$(PYTHON) setupmingw32.py sdist
$(PYTHON) setupmingw32.py bdist_wheel --skip-build
miniupnpc.dll: miniupnpc.def $(OBJSDLL)
$(DLLWRAP) -k --driver-name $(CC) \
--def miniupnpc.def \
--output-def miniupnpc.dll.def \
--implib miniupnpc.lib -o $@ \
$(OBJSDLL) $(LDLIBS)
miniupnpc.lib: miniupnpc.dll
%.o: $(SRCDIR)/%.c
$(CC) $(CFLAGS) $(CPPFLAGS) -DMINIUPNP_STATICLIB -c -o $@ $<
dll-%.o: $(SRCDIR)/%.c
$(CC) $(CFLAGS) $(CPPFLAGS) -DMINIUPNP_EXPORTS -c -o $@ $<
%-shared.o: $(SRCDIR)/%.c
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
# --enable-stdcall-fixup
%-static.exe: %.o libminiupnpc.a
$(CC) -static -o $@ $^ $(LDLIBS)
%-shared.exe: %-shared.o miniupnpc.lib
$(CC) -o $@ $^ $(LDLIBS)
upnp-listdevices-static.exe: listdevices.o libminiupnpc.a
$(CC) -static -o $@ $^ $(LDLIBS)
upnp-listdevices-shared.exe: listdevices-shared.o miniupnpc.lib
$(CC) -o $@ $^ $(LDLIBS)
# To make miniupnpcstrings.h from miniupnpcstrings.h.in we either
# use a custom executable (if running make under windows) or use
# sed (if cross compiling from another platform).
ifeq ($(OS),Windows_NT)
wingenminiupnpcstrings.exe: wingenminiupnpcstrings.c
$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $^
miniupnpcstrings.h: miniupnpcstrings.h.in wingenminiupnpcstrings.exe VERSION
.\wingenminiupnpcstrings.exe $< $@ rc_version.h
rc_version.h: miniupnpcstrings.h
else
miniupnpcstrings.h: miniupnpcstrings.h.in VERSION
sed 's|OS_STRING ".*"|OS_STRING "Windows/Mingw32"|' $< | \
sed 's|MINIUPNPC_VERSION_STRING ".*"|MINIUPNPC_VERSION_STRING "$(shell cat VERSION)"|' > $@
rc_version.h: VERSION
echo "#define LIBMINIUPNPC_DOTTED_VERSION \"$(shell cat VERSION)\"" > [email protected]
echo "#define LIBMINIUPNPC_MAJOR_VERSION $(shell cat VERSION|cut -d. -f1)" >> [email protected]
echo "#define LIBMINIUPNPC_MINOR_VERSION $(shell cat VERSION|cut -d. -f2)" >> [email protected]
echo "#define LIBMINIUPNPC_MICRO_VERSION $(shell cat VERSION|cut -d. -f3)" >> [email protected]
mv [email protected] $@
endif
miniupnpc.pc: VERSION
$(RM) $@
echo "prefix=$(INSTALLPREFIX)" >> $@
echo "exec_prefix=\$${prefix}" >> $@
echo "libdir=\$${exec_prefix}/$(LIBDIR)" >> $@
echo "includedir=\$${prefix}/include" >> $@
echo "" >> $@
echo "Name: miniUPnPc" >> $@
echo "Description: UPnP IGD client lightweight library" >> $@
echo "Version: $(shell cat VERSION)" >> $@
echo "Libs: -L\$${libdir} -lminiupnpc" >> $@
echo "Cflags: -I\$${includedir}" >> $@
winres.o: miniupnpc.rc rc_version.h
$(WINDRES) -D INTERNAL_NAME=\\\"miniupnpc.dll\\0\\\" -i $< -o $@
testminixml.exe: testminixml.o minixml.o igd_desc_parse.o
$(CC) -static -o $@ $^
minixml.o: $(SRCDIR)/minixml.c $(SRCDIR)/minixml.h
upnpc.o: include/miniwget.h $(SRCDIR)/minisoap.h include/miniupnpc.h include/igd_desc_parse.h
upnpc.o: include/upnpreplyparse.h include/upnpcommands.h include/upnperrors.h miniupnpcstrings.h
miniwget.o: $(SRCDIR)/miniwget.c include/miniwget.h miniupnpcstrings.h $(SRCDIR)/connecthostport.h
minisoap.o: $(SRCDIR)/minisoap.c $(SRCDIR)/minisoap.h miniupnpcstrings.h
miniupnpc.o: $(SRCDIR)/miniupnpc.c include/miniupnpc.h $(SRCDIR)/minisoap.h \
include/miniwget.h $(SRCDIR)/minixml.h $(SRCDIR)/addr_is_reserved.h
igd_desc_parse.o: $(SRCDIR)/igd_desc_parse.c include/igd_desc_parse.h
upnpreplyparse.o: $(SRCDIR)/upnpreplyparse.c include/upnpreplyparse.h $(SRCDIR)/minixml.h
upnpcommands.o: $(SRCDIR)/upnpcommands.c include/upnpcommands.h include/upnpreplyparse.h \
include/miniupnpc.h include/portlistingparse.h
minissdpc.o: $(SRCDIR)/minissdpc.c $(SRCDIR)/minissdpc.h $(SRCDIR)/receivedata.h
upnpdev.o: $(SRCDIR)/upnpdev.c include/upnpdev.h