Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build multiple php versions #525

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 39 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,24 @@
# libraries and the path to the binary file. If your php-config is not
# installed in the default directory, you can change that here.
#
# If you use environment with multiple PHP versions (e.g. debian), you need
# to specify name or path of php-config utility that matches targeted php
# version. If you want to build for multiple PHP versions, then also consider
# changing BUILD_DIR variable, so that builds for each version are separated
#

PHP_CONFIG = php-config
BUILD_DIR = build
UNAME := $(shell uname)

#
# If you do not want to run LDCONFIG, then set LDCONFIG to empty string.
# alternatively you can provide another command to register libraries
# after installation.
#

LDCONFIG = $(shell which ldconfig 2>/dev/null)

#
# Installation directory
#
Expand Down Expand Up @@ -61,8 +75,10 @@ VERSION = 2.4.3
# you can change that here.
#

PHP_SHARED_LIBRARY = libphpcpp.so.$(VERSION)
PHP_STATIC_LIBRARY = libphpcpp.a.$(VERSION)
LIBRARY_NAME = libphpcpp

PHP_SHARED_LIBRARY = ${LIBRARY_NAME}.so.$(VERSION)
PHP_STATIC_LIBRARY = ${LIBRARY_NAME}.a.$(VERSION)


#
Expand Down Expand Up @@ -157,14 +173,14 @@ PHP_SOURCES = $(wildcard zend/*.cpp)
# library. We also use a Makefile function here that takes all source files.
#

COMMON_OBJECTS = $(COMMON_SOURCES:%.cpp=build/%.o)
PHP_OBJECTS = $(PHP_SOURCES:%.cpp=build/%.o)
COMMON_OBJECTS = $(COMMON_SOURCES:%.cpp=${BUILD_DIR}/%.o)
PHP_OBJECTS = $(PHP_SOURCES:%.cpp=${BUILD_DIR}/%.o)

#
# Dependencies
#

DEPENDENCIES = $(wildcard build/common/*.d) $(wildcard build/zend/*.d)
DEPENDENCIES = $(wildcard ${BUILD_DIR}/common/*.d) $(wildcard ${BUILD_DIR}/zend/*.d)

#
# End of the variables section. Here starts the list of instructions and
Expand All @@ -181,30 +197,30 @@ release: COMPILER_FLAGS += -O2
release: LINKER_FLAGS += -O2
release: phpcpp

phpcpp: ${PHP_SHARED_LIBRARY} ${PHP_STATIC_LIBRARY}
phpcpp: ${BUILD_DIR}/${PHP_SHARED_LIBRARY} ${BUILD_DIR}/${PHP_STATIC_LIBRARY}
@echo
@echo "Build complete."

${PHP_SHARED_LIBRARY}: build_directories ${COMMON_OBJECTS} ${PHP_OBJECTS}
${LINKER} ${PHP_LINKER_FLAGS} -Wl,${LINKER_SONAME_OPTION},libphpcpp.so.$(SONAME) -o $@ ${COMMON_OBJECTS} ${PHP_OBJECTS}
${BUILD_DIR}/${PHP_SHARED_LIBRARY}: build_directories ${COMMON_OBJECTS} ${PHP_OBJECTS}
${LINKER} ${PHP_LINKER_FLAGS} -Wl,${LINKER_SONAME_OPTION},${LIBRARY_NAME}.so.$(SONAME) -o $@ ${COMMON_OBJECTS} ${PHP_OBJECTS}

${PHP_STATIC_LIBRARY}: build_directories ${COMMON_OBJECTS} ${PHP_OBJECTS}
${BUILD_DIR}/${PHP_STATIC_LIBRARY}: build_directories ${COMMON_OBJECTS} ${PHP_OBJECTS}
${ARCHIVER} $@ ${COMMON_OBJECTS} ${PHP_OBJECTS}

build_directories:
${MKDIR} build/common
${MKDIR} build/zend
${MKDIR} ${BUILD_DIR}/common
${MKDIR} ${BUILD_DIR}/zend

clean:
${RM} build ${PHP_SHARED_LIBRARY} ${PHP_STATIC_LIBRARY}
${RM} ${BUILD_DIR}
find -name *.o | xargs ${RM}
find -name *.d | xargs ${RM}

${COMMON_OBJECTS}:
${COMPILER} ${COMPILER_FLAGS} -o $@ ${@:build/%.o=%.cpp}
${COMPILER} ${COMPILER_FLAGS} -o $@ ${@:${BUILD_DIR}/%.o=%.cpp}

${PHP_OBJECTS}:
${COMPILER} ${COMPILER_FLAGS} -o $@ ${@:build/%.o=%.cpp}
${COMPILER} ${COMPILER_FLAGS} -o $@ ${@:${BUILD_DIR}/%.o=%.cpp}


# The if statements below must be seen as single line by make
Expand All @@ -214,19 +230,18 @@ install:
${MKDIR} ${INSTALL_LIB}
${CP} phpcpp.h ${INSTALL_HEADERS}
${CP} include/*.h ${INSTALL_HEADERS}/phpcpp
if [ -e ${PHP_SHARED_LIBRARY} ]; then \
${CP} ${PHP_SHARED_LIBRARY} ${INSTALL_LIB}/; \
${LN} ${PHP_SHARED_LIBRARY} ${INSTALL_LIB}/libphpcpp.so.$(SONAME); \
${LN} ${PHP_SHARED_LIBRARY} ${INSTALL_LIB}/libphpcpp.so; \
fi
if [ -e ${PHP_STATIC_LIBRARY} ]; then ${CP} ${PHP_STATIC_LIBRARY} ${INSTALL_LIB}/; \
${LN} ${PHP_STATIC_LIBRARY} ${INSTALL_LIB}/libphpcpp.a; \
if [ -e ${BUILD_DIR}/${PHP_SHARED_LIBRARY} ]; then \
${CP} ${BUILD_DIR}/${PHP_SHARED_LIBRARY} ${INSTALL_LIB}/ && \
${LN} ${PHP_SHARED_LIBRARY} ${INSTALL_LIB}/${LIBRARY_NAME}.so.$(SONAME) && \
${LN} ${PHP_SHARED_LIBRARY} ${INSTALL_LIB}/${LIBRARY_NAME}.so; \
fi
if `which ldconfig`; then \
ldconfig; \
if [ -e ${BUILD_DIR}/${PHP_STATIC_LIBRARY} ]; then \
${CP} ${BUILD_DIR}/${PHP_STATIC_LIBRARY} ${INSTALL_LIB}/ && \
${LN} ${PHP_STATIC_LIBRARY} ${INSTALL_LIB}/${LIBRARY_NAME}.a; \
fi
${LDCONFIG}

uninstall:
${RM} ${INSTALL_HEADERS}/phpcpp*
${RM} ${INSTALL_LIB}/libphpcpp.*
${RM} ${INSTALL_LIB}/${LIBRARY_NAME}.*