summaryrefslogtreecommitdiff
path: root/source4/build/make/templates.mk
blob: c0ee017a65a535947ca9c5a6d4da60aca0349b35 (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
# Templates file for Samba 4
# This relies on GNU make.
#
# © 2008 Jelmer Vernooij <jelmer@samba.org>
#
###############################################################################
# Templates
###############################################################################

# Partially link
# Arguments: target object file, source object files
define partial_link_template 
$(1): $(2) ;
	@echo Partially linking $$@
	@mkdir -p $$(@D)
	$$(PARTLINK) -o $$@ $$^
endef

# Link a binary
# Arguments: target file, depends, flags
define binary_link_template
$(1): $(2) ;
	@echo Linking $$@
	@$$(BNLD) $$(BNLD_FLAGS) $$(INTERN_LDFLAGS) -o $$@ $$(INSTALL_LINK_FLAGS) $(3)

clean::
	@rm -f $(1)

binaries:: $(1)

endef

# Link a host-machine binary
# Arguments: target file, depends, flags
define host_binary_link_template
$(1): $(2) ;
	@echo Linking $$@
	@$$(HOSTLD) $$(HOSTLD_FLAGS) -L$${builddir}/bin/static -o $$@ $$(INSTALL_LINK_FLAGS) $(3)

clean::
	rm -f $(1)

binaries:: $(1)

endef

# Create a prototype header
# Arguments: header file, c files
define proto_header_template

proto:: $(1) ;

clean:: ;
	rm -f $(1)

$(1): $(2) ;
	@echo "Creating $$@"
	@$$(PERL) $$(srcdir)/script/mkproto.pl --srcdir=$$(srcdir) --builddir=$$(builddir) --public=/dev/null --private=$$@ $$^

endef

# Shared module
# Arguments: Target, dependencies, objects
define shared_module_template

$(1): $(2) ;
	@echo Linking $$@
	@mkdir -p $$(@D)
	@$$(MDLD) $$(LDFLAGS) $$(MDLD_FLAGS) $$(INTERN_LDFLAGS) -o $$@ $$(INSTALL_LINK_FLAGS) $(3)

endef

# Shared library
# Arguments: Target, dependencies, link flags, soname
define shared_library_template
$(1): $(2)
	@echo Linking $$@
	@mkdir -p $$(@D)
	@$$(SHLD) $$(LDFLAGS) $$(SHLD_FLAGS) $$(INTERN_LDFLAGS) -o $$@ $$(INSTALL_LINK_FLAGS) \
		$(3) \
		$$(if $$(SONAMEFLAG), $$(SONAMEFLAG)$(notdir $(4)))

ifneq ($(notdir $(1)),$(notdir $(4)))
$(4): $(1)
	@echo "Creating symbolic link for $$@"
	@ln -fs $$(<F) $$@
endif

ifneq ($(notdir $(1)),$(notdir $(5)))
$(5): $(1)
	@echo "Creating symbolic link for $$@"
	@ln -fs $$(<F) $$@
endif
endef

# Shared alias
# Arguments: Target, subsystem name, alias name
define shared_module_alias_template
bin/modules/$(2)/$(3).$$(SHLIBEXT): $(1)
	@ln -fs $$(<F) $$@

PLUGINS += bin/modules/$(2)/$(3).$$(SHLIBEXT)

uninstallplugins::
	@-rm $$(DESTDIR)$$(modulesdir)/$(2)/$(3).$$(SHLIBEXT)
installplugins::
	@ln -fs $(notdir $(1)) $$(DESTDIR)$$(modulesdir)/$(2)/$(3).$$(SHLIBEXT)

endef

define shared_module_install_template
installplugins:: bin/modules/$(1)/$(2)
	@echo Installing $(2) as $$(DESTDIR)$$(modulesdir)/$(1)/$(2)
	@mkdir -p $$(DESTDIR)$$(modulesdir)/$(1)/
	@cp bin/modules/$(1)/$(2) $$(DESTDIR)$$(modulesdir)/$(1)/$(2)
uninstallplugins::
	@echo Uninstalling $$(DESTDIR)$$(modulesdir)/$(1)/$(2)
	@-rm $$(DESTDIR)$$(modulesdir)/$(1)/$(2)

endef

# abspath for older makes
abspath = $(shell cd $(dir $(1)); pwd)/$(notdir $(1))

# Install a binary
# Arguments: path to binary to install
define binary_install_template
installbin:: $$(DESTDIR)$$(bindir)/$(notdir $(1))

uninstallbin::
	@echo "Removing $(notdir $(1))"
	@rm -f $$(DESTDIR)$$(bindir)/$(1)
endef

define sbinary_install_template
installsbin:: $$(DESTDIR)$$(sbindir)/$(notdir $(1)) installdirs

uninstallsbin::
	@echo "Removing $(notdir $(1))"
	@rm -f $$(DESTDIR)$$(sbindir)/$(1)
endef