This repository has been archived by the owner on Oct 13, 2020. It is now read-only.
forked from aegif/CmisSync
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMakefile.fatbuild
135 lines (113 loc) · 5.95 KB
/
Makefile.fatbuild
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
ifndef LIBDIR
$(error Set the directory where libraries will be installed)
endif
ifndef PACKAGE_TARGET
$(error Set the package target, either rpm-package or debian-package)
endif
##################################################################
# Hi, welcome to the try of doing fatbuilds, I'll be your guide ;-)
#
# - Guide, what's happening?
# Well lad, we got trouble making the fat binary here, because the
# DLL's still want to load some shared libraries.
#
# - But which kind of libraries are these?
# You know, when some DLLs from the C# world want to talk to the
# Unix world, they need something that allows interaction.
# These are the 'gluelibs'.
# With these, guys from C# can talk to actual native libraries.
# E.g. buddy gtk-sharp will use libgtksharpglue to talk to gtk
# folks.
#
# - Oh man, I guess our binary won't be really fat then?
# Clever boy. We need to deploy these gluelibs along with the fatbinary.
# We will put them here:
INCLIBDIR=lib
# - But how do we find out which glue libraries we need, do we have
# a tool for that?
# Oh no! That would be too nice. I found this out by my own with try
# and error:
GLUELIBS=libatksharpglue-2.so libgdksharpglue-2.so libglibsharpglue-2.so libgtksharpglue-2.so libpangosharpglue-2.so libMonoPosixHelper.so
#
# - But how will mono know where these are on the target system?
# We need some DllMaps to do this.
#
# - Oh cool, so we simply write some configuration and that's it?
# Hahaha, silly boy, don't be naive. The world isn't that easy.
#
# - So what do we need to do?
# We will copy all needed DLLs to a new location (also INCLIBDIR),
# copy there config files to that same location and modify it.
# This is the only way mkbundle will find and use it.
#
# - Sounds pretty complicated. Can we find out which DLLs?
# It is. Not, not automatically, I set up a list:
SHARPDLLS=4.5/Mono.Posix.dll atk-sharp.dll gdk-sharp.dll glib-sharp.dll gtk-sharp.dll pango-sharp.dll
# We will then explicitly name then when calling mkbundle with our program DLLs
I18NDLLS=I18N.Rare.dll I18N.Other.dll I18N.MidEast.dll I18N.dll I18N.West.dll I18N.CJK.dll
FATDLLS=CmisSync.Lib.dll DotCMIS.dll DBreeze.dll DataSpace.dll log4net.dll Newtonsoft.Json.dll $(I18NDLLS) $(addprefix ./$(INCLIBDIR)/, $(notdir $(SHARPDLLS)))
# - But how do we find the DLLs, configs and gluelibs on our system?
# Because they are on different locations on each system, this isn't easy.
# We will need to ask the package manager to find them for us
#rpm-package means we're using yum (and yum-utils)
ifeq ($(PACKAGE_TARGET), rpm-package)
# the stuff beginning form "awk" should make sure it takes the one from the GAC if multiple files are installed
define findinst
$(shell repoquery -l --installed --whatprovides "*$(strip $(1))" | grep -e "/$(strip $(1))$$" | awk '{ print length, $$0 }' | sort -rn | cut -d " " -f2- | head -n 1)
endef
EASYDEPS:=$(shell repoquery -l --installed --whatprovides "*-sharp.dll" | grep -E "/(notify|dbus)-sharp.dll$$" | xargs -L 1 dirname | paste -s -d ':' -)
# otherwise we use dpkg for debian/ubuntu
else
define findinst
$(shell dpkg -S $(1) | grep -e "/$(strip $(1))$$" | cut -f2 -d ' ')
endef
# For other DLLs without DLLImports we will only need there searchpath
EASYDEPS:=$(shell dpkg -S "\-sharp.dll" | grep -E "/(notify|dbus)-sharp.dll$$" | cut -f2 -d ' ' | xargs -L 1 dirname | paste -s -d ':' -)
endif
# Debault target: build fat binary
all: | fat clean
# Here is a target that simply finds and copies our gluelibs to our desired dir (INCLIBDIR)
$(GLUELIBS):
@echo "### Finding and copying $(@) which is required for the fatbuild to run"
mkdir -p ./$(INCLIBDIR)/;
cp $(call findinst, $@) ./$(INCLIBDIR)/
# This target will find the DLLs and the config files. If it doesn't find a config file (DllMap)
# it will simply create an empty one
$(SHARPDLLS):
@echo "### Copying related DLL $(@) to modify its DLL mapping to match the deployed libs"
mkdir -p ./$(INCLIBDIR)/;
cp $(call findinst, $@) ./$(INCLIBDIR)/;
conffile="$(strip $(call findinst, [email protected]))"; \
if [ -n "$$conffile" ]; then \
cp $$conffile ./$(INCLIBDIR)/; \
else \
echo "<configuration>\n</configuration>" > ./$(INCLIBDIR)/$(shell basename $@).config; \
fi
# No look at this beaury, it removes all existing mappings for the gluelibs from the copied
# config files.
# Then it will add new mappings to all config files. It won't hurt if some config
# files have mappings they don't need. The target files will need an absolute path,
# so it's important to use the absolute path of our target (not the one used here)
preparelibs: $(GLUELIBS) $(SHARPDLLS)
@echo "### Modifying the DLL mapping for all DLLs that need deployed libs"
sed -i '/<dllmap.*sharpglue.*/d' ./$(INCLIBDIR)/*.dll.config;
for curlib in $(GLUELIBS); do \
curlibname="$${curlib#lib}"; \
curlibname="$${curlibname%.*}"; \
sed -i "\$$i <dllmap dll=\"$${curlibname}\" target=\"$(subst /,\/,$(LIBDIR))\/$(INCLIBDIR)\/$${curlib}\"\/>" $(INCLIBDIR)/*.dll.config; \
done;
# Now we can build the fat binaries. mkbundle will now be able to find alle the copied and modified configurations/mappings, because
# we tell it explicitly to use our copied DLLs (included in $FATDLLs), instead of letting it find them.
# Also, we will copy the syste config file to make sure the mappings exist on the target machine
fat: preparelibs
@echo "### Generating fat binaries"
cp /etc/mono/config mono_config
sed -i "/MonoPosixHelper/d" mono_config ; \
export MONO_PATH="$(EASYDEPS)"; \
mkbundle --static --config ./mono_config -o DataSpaceSync DataSpaceSync.exe --deps $(FATDLLS) --machine-config /etc/mono/4.5/machine.config -z ; \
mkbundle --static --config ./mono_config -o DataSpaceSync.Console DataSpaceSync.Console.exe --deps $(FATDLLS) --machine-config /etc/mono/4.5/machine.config -z ; \
mkbundle --static --config ./mono_config -o DiagnoseTool DiagnoseTool.exe --deps $(FATDLLS) --machine-config /etc/mono/4.5/machine.config -z
clean:
rm -f $(INCLIBDIR)/*.dll
rm -f $(INCLIBDIR)/*.dll.config
rm -f ./mono_config