Skip to content

Commit

Permalink
Add Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
menezes- committed Dec 4, 2019
1 parent ec28e6b commit 5f8f0da
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 30 deletions.
5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 2 additions & 26 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,32 +1,8 @@
cmake_minimum_required(VERSION 3.15)
project(xxtea)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

add_executable(xxtea main.cpp xxtea.hpp)

target_compile_features(xxtea PRIVATE cxx_std_11)

add_library(xxtea-php SHARED xxtea-php.cpp)

target_compile_features(xxtea-php PRIVATE cxx_std_11)

find_library(PHP_CPP NAMES libphpcpp phpcpp)

target_link_libraries(xxtea-php PRIVATE ${PHP_CPP_LIBRARIES})
target_include_directories(xxtea-php PRIVATE ${PHP_CPP_INCLUDE_DIRS})

set_target_properties(xxtea-php PROPERTIES POSITION_INDEPENDENT_CODE ON)

target_compile_options(xxtea-php PRIVATE
-Wall -Wextra -Wno-unused-function
$<$<CONFIG:Debug>:-g -O0>
$<$<CONFIG:Release>:-O3 -s>
$<$<CONFIG:RelWithDebInfo>:-g -O3>
)

execute_process(
COMMAND php-config --extension-dir
OUTPUT_VARIABLE PHP_EXTENSION_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE
)

install(TARGETS xxtea-php DESTINATION ${PHP_EXTENSION_DIR})
131 changes: 131 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
#
# Makefile template
#
# This is an example Makefile that can be used by anyone who is building
# his or her own PHP extensions using the PHP-CPP library.
#
# In the top part of this file we have included variables that can be
# altered to fit your configuration, near the bottom the instructions and
# dependencies for the compiler are defined. The deeper you get into this
# file, the less likely it is that you will have to change anything in it.
#

#
# Name of your extension
#
# This is the name of your extension. Based on this extension name, the
# name of the library file (name.so) and the name of the config file (name.ini)
# are automatically generated
#

NAME = xxtea

#
# Php.ini directories
#
# In the past, PHP used a single php.ini configuration file. Today, most
# PHP installations use a conf.d directory that holds a set of config files,
# one for each extension. Use this variable to specify this directory.
#
# In Ubuntu 14.04 Apache 2.4 is used, which uses the mods-available directory
# instead of a conf.d directory. In 16.04 the directory changed yet again.
# This has to be checked.
#



INI_DIR = /usr/local/etc/php/conf.d/

#
# The extension dirs
#
# This is normally a directory like /usr/lib/php5/20121221 (based on the
# PHP version that you use. We make use of the command line 'php-config'
# instruction to find out what the extension directory is, you can override
# this with a different fixed directory
#

EXTENSION_DIR = $(shell php-config --extension-dir)

#
# The name of the extension and the name of the .ini file
#
# These two variables are based on the name of the extension. We simply add
# a certain extension to them (.so or .ini)
#

EXTENSION = ${NAME}.so
INI = ${NAME}.ini

#
# Compiler
#
# By default, the GNU C++ compiler is used. If you want to use a different
# compiler, you can change that here. You can change this for both the
# compiler (the program that turns the c++ files into object files) and for
# the linker (the program that links all object files into the single .so
# library file. By default, g++ (the GNU C++ compiler) is used for both.
#

COMPILER = c++
LINKER = c++

#
# Compiler and linker flags
#
# This variable holds the flags that are passed to the compiler. By default,
# we include the -O2 flag. This flag tells the compiler to optimize the code,
# but it makes debugging more difficult. So if you're debugging your application,
# you probably want to remove this -O2 flag. At the same time, you can then
# add the -g flag to instruct the compiler to include debug information in
# the library (but this will make the final libphpcpp.so file much bigger, so
# you want to leave that flag out on production servers).
#
# If your extension depends on other libraries (and it does at least depend on
# one: the PHP-CPP library), you should update the LINKER_DEPENDENCIES variable
# with a list of all flags that should be passed to the linker.
#

COMPILER_FLAGS = -Wall -c -O3 -fpic -o -Wall -Wextra -Wno-unused-function
LINKER_FLAGS = -shared
LINKER_DEPENDENCIES = -lphpcpp

#
# Command to remove files, copy files and create directories.
#
# I've never encountered a *nix environment in which these commands do not work.
# So you can probably leave this as it is
#

RM = rm -f
CP = cp -f
MKDIR = mkdir -p

#
# All source files are simply all *.cpp files found in the current directory
#
# A built-in Makefile macro is used to scan the current directory and find
# all source files. The object files are all compiled versions of the source
# file, with the .cpp extension being replaced by .o.
#

SOURCES = $(wildcard *.cpp)
OBJECTS = $(SOURCES:%.cpp=%.o)

#
# From here the build instructions start
#

all: ${OBJECTS} ${EXTENSION}

${EXTENSION}: ${OBJECTS}
${LINKER} ${LINKER_FLAGS} -o $@ ${OBJECTS} ${LINKER_DEPENDENCIES}

${OBJECTS}:
${COMPILER} ${COMPILER_FLAGS} $@ ${@:%.o=%.cpp}

install:
${CP} ${EXTENSION} ${EXTENSION_DIR}

clean:
${RM} ${EXTENSION} ${OBJECTS}
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ int main() {
There's also a PHP extension inside xxtea-php, you can compile it using CMake. To be able to compile it you must have [PHP-CPP](https://github.com/CopernicaMarketingSoftware/PHP-CPP) installed.
Once you have PHP-CPP installed build and install the PHP extension is very simple:
```bash
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release .. .
make
sudo make install
# enable it on your php installation eg:
Expand Down
2 changes: 1 addition & 1 deletion xxtea.ini
Original file line number Diff line number Diff line change
@@ -1 +1 @@
extension=libxxtea-php
extension=xxtea

0 comments on commit 5f8f0da

Please sign in to comment.