summaryrefslogtreecommitdiff
path: root/php/config/Make.rules
blob: 2975864fc63526fbd8cd737a154271202382ee4e (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
#
# Copyright (c) ZeroC, Inc. All rights reserved.
#

#
# Use specific PHP version
#
PHP_CONFIG      ?= php-config

#
# The extension is by default built with namespaces enabled
# it is possible to build the PHP extension with namespaces
# disabled by setting `USE_NAMESPACES` property to `no`
#
USE_NAMESPACES  ?= yes

# ----------------------------------------------------------------------
# Don't change anything below this line!
# ----------------------------------------------------------------------

ifneq ($(USE_NAMESPACES),yes)
slice2php_flags         = --no-namespace
endif

#
# $(call make-php-test-project,$1=testdir)
#
define make-php-test-project

$1/.depend/%.ice.d: | $1/.depend ;

$1/.depend:
	$(Q)$(MKDIR) -p $$@

.PRECIOUS: $1/.depend/%.ice.d

ifeq ($(filter %clean,$(MAKECMDGOALS)),)
    # Include the dependencies
    -include $(addprefix $1/.depend/,$(call source-to-dependency,$(wildcard $1/*.ice)))
endif

$1/%.php: $1/%.ice $1/.depend/%.ice.d $(slice2php_path)
	$(E) "Compiling $$<"
	$(Q)$(slice2php_path) $(slice2php_flags) -I$(slicedir) -I$1 --output-dir $1 $$($1_sliceflags) --depend $$< | \
		sed 's/\(.*: \\\)/$(subst /,\/,$2)\/$3\/\1/' > $1/.depend/$$(*F).ice.d
	$(Q)$(slice2php_path) $(slice2php_flags) -I$(slicedir) -I$1 --output-dir $1 $$($1_sliceflags) $$<

distclean clean::
	$(E) "Cleaning $1"
	$(Q)$(RM) -r $1/.depend
	$(Q)$(RM) $(patsubst $1/%.ice,$1/%.php,$(wildcard $1/*.ice))

tests generate-srcs srcs all:: $(patsubst $1/%.ice,$1/%.php,$(wildcard $1/*.ice))

endef

# Configuration for building IcePHP sources
ifeq ($(filter all php,$(ICE_BIN_DIST)),)

ifneq ($(shell type $(PHP_CONFIG) > /dev/null 2>&1 && echo 0),0)
$(error $(PHP_CONFIG) not found review your PHP installation and ensure $(PHP_CONFIG) is in your PATH)
endif

php_cppflags            = $(shell $(PHP_CONFIG) --includes)

ifeq ($(USE_NAMESPACES),yes)
php_cppflags            := $(php_cppflags) -DICEPHP_USE_NAMESPACES
endif

# PHP 5.3 does not compile with C++11 due to an issue with
# user defined literals. PHP 5.4 and up do not have this issue.
ifeq ($(shell [ $$($(PHP_CONFIG) --vernum) -lt 50400 ] && echo 0),0)
    php_cppflags        := -std=c++98 $(php_cppflags)
endif

ifeq ($(os),Darwin)
    php_cppflags        := $(php_cppflags) -Wno-unused-parameter -Wno-missing-field-initializers
    php_ldflags         := ${wl}-flat_namespace ${wl}-undefined ${wl}suppress
endif

ifeq ($(os),Linux)
   cppflags             := $(filter-out -Wshadow,$(cppflags))
   php_cppflags         := $(php_cppflags) -Wno-unused-parameter -Wno-missing-field-initializers
   allow-undefined-symbols    := yes
endif

#
# On the default platform, always write/install the module in the lib directory.
#
$(foreach p,$(supported-platforms),$(eval $$p_targetdir[IcePHP] := /$$p))
$(firstword $(supported-platforms))_targetdir[IcePHP] :=
$(firstword $(supported-platforms))_installdir[IcePHP] :=

#
# PHP installation directory
#
install_phpdir          ?= $(if $(usr_dir_install),$(prefix)/share/php,$(prefix)/php)
install_phplibdir       ?= $(if $(usr_dir_install),$(shell $(PHP_CONFIG) --extension-dir),$(prefix)/php)

#
# Rules to build a php module. We just compute the name of the php module
# and delegate to make-shared-module.
#
mkphpmodulename                 ?= $(patsubst lib%,%,$(call mkshlibname,$(1)))
make-shared-php-module          = $(call make-shared-module,$(call mkphpmodulename,$1),$2,$3,$4,$5,$6,$7,$8,$9)
get-shared-php-module-targets   = $(call get-shared-module-targets,$(call mkphpmodulename,$1),$2,$3,$4)
install-shared-php-module       = $(call install-shared-module,$(call mkphpmodulename,$1),$2,$3,$4,$5)

$(DESTDIR)$(install_phpdir):
	$(Q)$(MKDIR) -p $@
installdirs += $(install_phpdir)

#
# $(call make-php-package,$1=slicedir,$2=generateddir,$3=package,$4=sliceflags)
#
# Compile slice files from $(slicedir)/<package> to php/<package>.
#
define make-php-package

ifeq ($(filter all php, $(ICE_BIN_DIST)),)

$2/$3/.depend/%.ice.d: | $2/$3/.depend ;

$2/$3/.depend:
	$(Q)$(MKDIR) -p $$@

.PRECIOUS: $2/$3/.depend/%.ice.d

ifeq ($(filter %clean,$(MAKECMDGOALS)),)
    # Include the dependencies
    -include $(addprefix $2/$3/.depend/,$(call source-to-dependency,$(wildcard $1/$3/*.ice)))
endif

$2/$3/%.php: $1/$3/%.ice $2/$3/.depend/%.ice.d $(slice2php_path)
	$(E) "Compiling $$<"
	$(Q)$(slice2php_path) $(slice2php_flags) -I$1 --output-dir $2/$3 $4 --depend $$< | \
		sed 's/\(.*: \\\)/$(subst /,\/,$2)\/$3\/\1/' > $2/$3/.depend/$$(*F).ice.d
	$(Q)$(slice2php_path) $(slice2php_flags) -I$1 --output-dir $2/$3 $4 $$<

distclean clean::
	$(E) "Cleaning package $3"
	$(Q)$(RM) -r $2/$3/.depend
	$(Q)$(RM) $(patsubst $1/$3/%.ice,$2/$3/%.php,$(wildcard $1/$3/*.ice))

generate-srcs srcs all:: $(patsubst $1/$3/%.ice,$2/$3/%.php,$(wildcard $1/$3/*.ice))

$$(eval $$(call install-data-files,$(patsubst $1/$3/%.ice,$2/$3/%.php,$(wildcard $1/$3/*.ice)),$2,$(install_phpdir),install))

endif

endef

endif