summaryrefslogtreecommitdiff
path: root/solenv/gbuild/DotnetLibrary.mk
blob: 9d20638f07380465729385fb2808255478403779 (plain)
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
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

##############################
# DotnetLibrary Target Class #
##############################

####### Constant Strings #########

gb_DotnetLibrary__CONFIG_RELEASE := -c Release
gb_DotnetLibrary__CONFIG_DEBUG := -c Debug

####### Helper Functions #########

define gb_DotnetLibrary__get_build_config
$(if $(or \
		$(filter TRUE,$(strip $(debug))), \
		$(filter TRUE,$(strip $(ENABLE_DBGUTIL))) \
	), \
	$(gb_DotnetLibrary__CONFIG_DEBUG), \
	$(gb_DotnetLibrary__CONFIG_RELEASE))

endef

define gb_DotnetLibrary__escape_quotes
$(strip $(subst ",\",$(1)))

endef

####### Build and Clean Targets #########

.PHONY : $(call gb_DotnetLibrary_get_clean_target,%)
$(call gb_DotnetLibrary_get_clean_target,%) :
	$(call gb_Output_announce,$*,$(false),NET,4)
	$(call gb_Helper_abbreviate_dirs,\
		rm -rf $(call gb_DotnetLibrary_get_target,$*))

$(call gb_DotnetLibrary_get_target,%) :
	$(call gb_Output_announce,$*,$(true),NET,4)
	$(call gb_Trace_StartRange,$*,NET)
	$(call gb_Helper_abbreviate_dirs,\
		mkdir -p $(call gb_DotnetLibrary_get_workdir,$*) && \
		P=$(DOTNET_PROJECT_FILE) && \
		echo "<Project Sdk=\"Microsoft.NET.Sdk\">" > $$P && \
		echo "<PropertyGroup>" >> $$P && \
		echo "$(DOTNET_PROPERTY_ELEMENTS)" >> $$P && \
		echo "</PropertyGroup>" >> $$P && \
		echo "<ItemGroup>" >> $$P && \
		echo "$(DOTNET_ITEM_ELEMENTS)" >> $$P && \
		echo "</ItemGroup>" >> $$P && \
		echo "</Project>" >> $$P && \
		dotnet build $$P $(DOTNET_BUILD_FLAGS) \
			-o $(call gb_DotnetLibrary_get_workdir,$*) \
			> $@.log 2>&1 || \
			(echo \
				&& cat $@.log \
				&& echo \
				&& echo "A library failed to build. To retry the build, use:" \
				&& echo "    make DotnetLibrary_$*" \
				&& echo "cd into the module directory to run the build faster" \
				&& echo \
				&& false) && \
		touch $@)
	$(call gb_Trace_EndRange,$*,NET)

####### Library Target Constructors #########

define gb_DotnetLibrary__common_ctor
$(call gb_DotnetLibrary_get_target,$(1)) : DOTNET_BUILD_FLAGS := $(strip $(call gb_DotnetLibrary__get_build_config))
$(call gb_DotnetLibrary_get_target,$(1)) : DOTNET_PROPERTY_ELEMENTS := <TargetFramework>netstandard20</TargetFramework>
$(call gb_DotnetLibrary_get_target,$(1)) : DOTNET_ITEM_ELEMENTS :=
$(call gb_DotnetLibrary_get_target,$(1)) : DOTNET_PROJECT_FILE := $(call gb_DotnetLibrary_get_workdir,$(1))/$(1).$(2)

$(eval $(call gb_Module_register_target, \
	$(call gb_DotnetLibrary_get_target,$(1)), \
	$(call gb_DotnetLibrary_get_clean_target,$(1))))
$(call gb_Helper_make_userfriendly_targets,$(1),DotnetLibrary)

endef

# Generates one csproj file from given inputs and builds it
# call gb_DotnetLibrary_CsLibrary,targetname
define gb_DotnetLibrary_CsLibrary
$(call gb_DotnetLibrary__common_ctor,$(1),csproj)

endef

# Generates one fsproj file from given inputs and builds it
# call gb_DotnetLibrary_FsLibrary,targetname
define gb_DotnetLibrary_FsLibrary
$(call gb_DotnetLibrary__common_ctor,$(1),fsproj)

endef

# Generates one vbproj file from given inputs and builds it
# call gb_DotnetLibrary_VbLibrary,targetname
define gb_DotnetLibrary_VbLibrary
$(call gb_DotnetLibrary__common_ctor,$(1),vbproj)

endef

####### Target Property Setters #########

# Add flags used for compilation
# call gb_DotnetLibrary_add_build_flags,target,flags
define gb_DotnetLibrary_add_build_flags
$(call gb_DotnetLibrary_get_target,$(1)) : DOTNET_BUILD_FLAGS += $(2)

endef

# Add <PropertyGroup> elements to the project file
# call gb_DotnetLibrary_add_properties,target,properties
define gb_DotnetLibrary_add_properties
$(call gb_DotnetLibrary_get_target,$(1)) : DOTNET_PROPERTY_ELEMENTS += $(strip $(call gb_DotnetLibrary__escape_quotes,$(2)))

endef

# Add <ItemGroup> elements to the project file
# call gb_DotnetLibrary_add_items,target,items
define gb_DotnetLibrary_add_items
$(call gb_DotnetLibrary_get_target,$(1)) : DOTNET_ITEM_ELEMENTS += $(strip $(call gb_DotnetLibrary__escape_quotes,$(2)))

endef

# Add one source file to the project file
# This adds it to the project, and makes it a build dependency
# so the library is rebuilt if the source changes
# call gb_DotnetLibrary_add_source,target,basedir,source
define gb_DotnetLibrary_add_source
$(call gb_DotnetLibrary_get_target,$(1)) : $(strip $(2))/$(strip $(3))
$(call gb_DotnetLibrary_add_items,$(1),<Compile Include="$(strip $(2))/$(strip $(3))"/>)

endef

# Add source files to the project file
# This adds them to the project, and makes it them build dependency
# so the library is rebuilt if the sources change
# call gb_DotnetLibrary_add_sources,target,basedir,sources
define gb_DotnetLibrary_add_sources
$(foreach source,$(3),$(call gb_DotnetLibrary_add_source,$(1),$(2),$(source)))

endef

# Add one generated source file to the project file,
# This is not marked as makefile build dependency,
# so the library is NOT rebuilt if this source changes
# Useful for things like source globs supported by .net projects
# call gb_DotnetLibrary_add_generated_source,target,basedir,source
define gb_DotnetLibrary_add_generated_source
$(call gb_DotnetLibrary_add_items,$(1),<Compile Include="$(strip $(2))/$(strip $(3))"/>)

endef

# Add generated source files to the project file,
# These are not marked as makefile build dependencies,
# so the library is NOT rebuilt if these sources change
# Useful for things like source globs supported by .net projects
# call gb_DotnetLibrary_add_generated_sources,target,basedir,sources
define gb_DotnetLibrary_add_generated_sources
$(foreach source,$(3),$(call gb_DotnetLibrary_add_generated_source,$(1),$(2),$(source)))

endef

# Link to a DotnetLibrary_CsLibrary target
# call gb_DotnetLibrary_link_cs_library,target,library
define gb_DotnetLibrary_link_cs_library
$(call gb_DotnetLibrary_get_target,$(1)) : $(call gb_DotnetLibrary_get_target,$(strip $(2)))
$(call gb_DotnetLibrary_add_items,$(1),<ProjectReference Include="$(call gb_DotnetLibrary_get_workdir,$(strip $(2)))/$(strip $(2)).csproj"/>)

endef

# Link to a DotnetLibrary_FsLibrary target
# call gb_DotnetLibrary_link_fs_library,target,library
define gb_DotnetLibrary_link_fs_library
$(call gb_DotnetLibrary_get_target,$(1)) : $(call gb_DotnetLibrary_get_target,$(strip $(2)))
$(call gb_DotnetLibrary_add_items,$(1),<ProjectReference Include="$(call gb_DotnetLibrary_get_workdir,$(strip $(2)))/$(strip $(2)).fsproj"/>)

endef

# Link to a DotnetLibrary_VbLibrary target
# call gb_DotnetLibrary_link_vb_library,target,library
define gb_DotnetLibrary_link_vb_library
$(call gb_DotnetLibrary_get_target,$(1)) : $(call gb_DotnetLibrary_get_target,$(strip $(2)))
$(call gb_DotnetLibrary_add_items,$(1),<ProjectReference Include="$(call gb_DotnetLibrary_get_workdir,$(strip $(2)))/$(strip $(2)).vbproj"/>)

endef

# vim: set noet sw=4 ts=4: