Add build/packaging system
authorDariusz Michaluk <d.michaluk@samsung.com>
Thu, 31 Mar 2016 09:45:10 +0000 (11:45 +0200)
committerMateusz Kulikowski <m.kulikowski@samsung.com>
Thu, 7 Apr 2016 09:23:31 +0000 (11:23 +0200)
Change-Id: I218be0c159121689213dbfb3b8a1407a9405890e
Signed-off-by: Mateusz Kulikowski <m.kulikowski@samsung.com>
CMakeLists.txt [new file with mode: 0644]
Makefile [deleted file]
api/crypto/crypto.h
packaging/owl.spec [new file with mode: 0644]
src/CMakeLists.txt [new file with mode: 0644]
src/Makefile [deleted file]
src/owl.pc.in [new file with mode: 0644]

diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644 (file)
index 0000000..66c9c73
--- /dev/null
@@ -0,0 +1,89 @@
+#
+#  Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+#
+#  Contact: Krzysztof Jackiewicz <k.jackiewicz@samsung.com>
+#
+#  Licensed under the Apache License, Version 2.0 (the "License");
+#  you may not use this file except in compliance with the License.
+#  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License
+#
+#
+# @file CMakeLists.txt
+# @author Dariusz Michaluk (d.michaluk@samsung.com)
+#
+
+CMAKE_MINIMUM_REQUIRED (VERSION 2.6.2)
+
+PROJECT(owl)
+SET(VERSION "0.0.1")
+
+## pkgconfig ###################################################################
+INCLUDE(FindPkgConfig)
+
+## default CMAKE_INSTALL_* variables ###########################################
+INCLUDE(GNUInstallDirs)
+
+## Color output if it's possible:
+IF (( "${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" AND NOT (CMAKE_C_COMPILER_VERSION VERSION_LESS 4.9))
+      OR ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" ))
+
+    IF (OWL_BUILD_FORCE_COMPILER_COLORS)
+        SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fdiagnostics-color=always")
+    ENDIF()
+ENDIF()
+
+## Compiler flags, depending on the build type #################################
+IF(NOT CMAKE_BUILD_TYPE)
+    SET(CMAKE_BUILD_TYPE "DEBUG")
+ENDIF(NOT CMAKE_BUILD_TYPE)
+
+## Print build information #####################################################
+MESSAGE(STATUS "-------------------------------------------------")
+MESSAGE(STATUS "Compiler:          " ${CMAKE_C_COMPILER_ID})
+MESSAGE(STATUS "Compiler version:  " ${CMAKE_C_COMPILER_VERSION})
+MESSAGE(STATUS "Build type:        " ${CMAKE_BUILD_TYPE})
+MESSAGE(STATUS "-------------------------------------------------")
+
+SET(CMAKE_C_FLAGS_DEBUG        "-std=c99 -O0 -ggdb -Wp,-U_FORTIFY_SOURCE")
+SET(CMAKE_C_FLAGS_RELEASE      "-std=c99 -O2 -DNDEBUG")
+
+ADD_DEFINITIONS("-fPIC")   # Position Independent Code
+ADD_DEFINITIONS("-Werror") # Make all warnings into errors
+ADD_DEFINITIONS("-Wall")   # Generate all warnings
+#ADD_DEFINITIONS("-Wextra") # Generate even more extra warnings
+#ADD_DEFINITIONS("-pedantic") # Be pedantic
+#ADD_DEFINITIONS("-pedantic-errors") # Make pedantic warnings into errors
+ADD_DEFINITIONS(-DPROJECT_SOURCE_DIR="${PROJECT_SOURCE_DIR}")
+
+IF("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
+    # Warn about documentation problems
+    SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wdocumentation")
+    # Enable all diagnostics
+    #SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Weverything")
+ENDIF()
+
+## Subdirectories ##############################################################
+SET(API_FOLDER ${PROJECT_SOURCE_DIR}/api)
+SET(EXAMPLES_FOLDER ${PROJECT_SOURCE_DIR}/examples)
+SET(SRC_FOLDER ${PROJECT_SOURCE_DIR}/src)
+SET(TEST_FOLDER ${PROJECT_SOURCE_DIR}/test)
+
+IF(NOT DEFINED LIB_INSTALL_DIR)
+    SET(LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
+ENDIF(NOT DEFINED LIB_INSTALL_DIR)
+
+IF(NOT DEFINED INCLUDE_INSTALL_DIR)
+    SET(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}")
+ENDIF(NOT DEFINED INCLUDE_INSTALL_DIR)
+
+ADD_SUBDIRECTORY(${SRC_FOLDER})
+#ADD_SUBDIRECTORY(${TEST_FOLDER})
+#ADD_SUBDIRECTORY(${EXAMPLES_FOLDER})
diff --git a/Makefile b/Makefile
deleted file mode 100644 (file)
index 697bcbc..0000000
--- a/Makefile
+++ /dev/null
@@ -1,10 +0,0 @@
-.PHONY: all build clean
-all: build
-
-build:
-       make -C src
-       make -C examples
-
-clean:
-       make -C src clean
-       make -C examples clean
index 3929ddc..32f88b4 100644 (file)
@@ -167,7 +167,7 @@ int owl_get_output_length(const owl_ctx_h ctx, size_t input_len);
  *
  * @param[in] algo  Encryption algorithm.
  * @param[in] bcm   Chain mode.
- * @param[in] len   Key length (@see owl_key_len_e).
+ * @param[in] key_len   Key length (@see crypto_key_len_e).
  *
  * @return negative on error (@see error.h) or the IV length.
  */
diff --git a/packaging/owl.spec b/packaging/owl.spec
new file mode 100644 (file)
index 0000000..fa9db8d
--- /dev/null
@@ -0,0 +1,53 @@
+Name:               owl
+Version:            0.0.1
+Release:            0
+Source0:            %{name}-%{version}.tar.gz
+License:            Apache-2.0
+Group:              Security/Other
+Summary:            Openssl wrapper layer
+BuildRequires:      cmake
+BuildRequires:      pkgconfig(openssl)
+Requires(post):     /sbin/ldconfig
+Requires(postun):   /sbin/ldconfig
+
+%description
+The package provides Openssl wrapper layer.
+
+%files
+%defattr(644,root,root,755)
+%{_libdir}/libowl.so.0
+%attr(755,root,root) %{_libdir}/libowl.so.%{version}
+
+%prep
+%setup -q
+
+%build
+%{!?build_type:%define build_type "RELEASE"}
+
+%cmake . -DCMAKE_BUILD_TYPE=%{build_type}
+make -k %{?jobs:-j%jobs}
+
+%install
+%make_install
+
+%clean
+rm -rf %{buildroot}
+
+%post -n owl -p /sbin/ldconfig
+
+%postun -n owl -p /sbin/ldconfig
+
+## Devel Package ###############################################################
+%package devel
+Summary:        Development Openssl wrapper layer
+Group:          Security/Other
+Requires:       owl = %{version}-%{release}
+
+%description devel
+The package provides Openssl wrapper development layer.
+
+%files devel
+%defattr(644,root,root,755)
+%{_libdir}/libowl.so
+%{_includedir}/owl
+%{_libdir}/pkgconfig/owl.pc
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644 (file)
index 0000000..ce8dfd8
--- /dev/null
@@ -0,0 +1,67 @@
+#
+#  Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+#
+#  Contact: Krzysztof Jackiewicz <k.jackiewicz@samsung.com>
+#
+#  Licensed under the Apache License, Version 2.0 (the "License");
+#  you may not use this file except in compliance with the License.
+#  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License
+#
+#
+# @file CMakeLists.txt
+# @author Dariusz Michaluk (d.michaluk@samsung.com)
+#
+
+PROJECT(owl)
+
+MESSAGE(STATUS "")
+MESSAGE(STATUS "Generating makefile for the owl...")
+
+FILE(GLOB HEADERS   ${API_FOLDER}/crypto/*.h)
+FILE(GLOB SRCS      *.c *.h)
+
+SET(_LIB_VERSION_ "${VERSION}")
+SET(_LIB_SOVERSION_ "0")
+SET(PC_FILE "${PROJECT_NAME}.pc")
+
+## Set the default ELF image symbol visibility to hidden. Using this feature
+## can very substantially improve linking and load times of shared object
+## libraries, produce more optimized code, provide near-perfect API export
+## and prevent symbol clashes
+ADD_DEFINITIONS(-fvisibility=hidden)
+
+## Setup target ################################################################
+ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS} ${HEADERS})
+SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES
+    SOVERSION   ${_LIB_SOVERSION_}
+    VERSION     ${_LIB_VERSION_}
+)
+
+## Link libraries ##############################################################
+PKG_CHECK_MODULES(OWL_DEPS REQUIRED openssl)
+
+INCLUDE_DIRECTORIES(${API_FOLDER})
+INCLUDE_DIRECTORIES(SYSTEM ${OWL_DEPS_INCLUDE_DIRS})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${OWL_DEPS_LIBRARIES})
+
+## Generate the pc file ########################################################
+CONFIGURE_FILE(${PC_FILE}.in ${CMAKE_CURRENT_BINARY_DIR}/${PC_FILE} @ONLY)
+
+## Install #####################################################################
+INSTALL(FILES       ${CMAKE_CURRENT_BINARY_DIR}/${PC_FILE}
+        DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
+
+INSTALL(TARGETS     ${PROJECT_NAME}
+        DESTINATION ${LIB_INSTALL_DIR}
+        COMPONENT   RuntimeLibraries)
+
+INSTALL(FILES       ${HEADERS}
+        DESTINATION ${INCLUDE_INSTALL_DIR}/owl)
diff --git a/src/Makefile b/src/Makefile
deleted file mode 100644 (file)
index 43b76d0..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-# Sample makefile - for now it only checks if sources compile
-files := $(basename $(wildcard *.c))
-objs := $(addsuffix .o, $(files))
-deps := $(addsuffix .d, $(files))
-
-libs := libCryptoAPI.so libCryptoAPI.a
-
-LIBS := $(shell pkg-config --libs openssl)
-CFLAGS := $(shell pkg-config --cflags openssl) -I../api -Wall -MMD -fPIC -fvisibility=hidden
-
-.PHONY: all build clean
-all: build
-
-build: $(libs)
-
-clean:
-       rm -f $(objs) $(deps) $(libs)
-
-%.so: $(objs)
-       gcc $(LDFLAGS) $^ $(LIBS) -shared -o $@
-
-%.a: $(objs)
-       ar rcs $@ $<
-
-%.o: %.c
-       gcc $(CFLAGS) -c $< -o $@
-
--include $(deps)
diff --git a/src/owl.pc.in b/src/owl.pc.in
new file mode 100644 (file)
index 0000000..4fc5167
--- /dev/null
@@ -0,0 +1,12 @@
+# Package Information for pkg-config
+
+prefix=@CMAKE_INSTALL_PREFIX@
+exec_prefix=@CMAKE_INSTALL_PREFIX@
+libdir=@LIB_INSTALL_DIR@
+includedir=@INCLUDE_INSTALL_DIR@
+
+Name: owl
+Description: Openssl wrapper layer
+Version: @_LIB_VERSION_@
+Libs: -L${libdir} -l@PROJECT_NAME@
+Cflags: -I${includedir}