project scraps ;

alias objc : : : :
    <target-os>darwin:<cxxflags>"-x objective-c++"
    <target-os>iphone:<cxxflags>"-x objective-c++"
    <target-os>appletv:<cxxflags>"-x objective-c++"
    <target-os>darwin:<cflags>-fobjc-arc
    <target-os>iphone:<cflags>-fobjc-arc
    <target-os>appletv:<cflags>-fobjc-arc
;

import needs/pkgconfig.jam ;
pkgconfig.dependency mbedtls ;
pkgconfig.dependency curl : libcurl ;
pkgconfig.dependency fmtlib ;
pkgconfig.dependency libsodium ;
pkgconfig.dependency gsl ;
pkgconfig.dependency asio ;
pkgconfig.dependency mnmlstc ;
pkgconfig.dependency json11 ;
pkgconfig.dependency googletest ;
pkgconfig.dependency jshackle ;
pkgconfig.dependency benchmark ;

lib GLESv2 : : <link>shared ;
lib z : : <link>shared ;
lib dl : : <link>shared ;
lib pthread : : <link>shared ;

alias scraps_deps :
    mbedtls
    curl
    fmtlib
    libsodium
    gsl
    asio
    mnmlstc
    objc
    json11
: : :
    <include>include
    <cxxflags>"-Wall -Wextra -Wno-unused-parameter -Wno-missing-braces -Wno-sign-compare -std=c++1z -fvisibility=hidden"
    <define>ASIO_STANDALONE=1
    <define>STATICLIB

    <target-os>darwin:<framework>Foundation
    <target-os>iphone:<framework>Foundation
    <target-os>appletv:<framework>Foundation

    <target-os>darwin:<framework>CoreServices
    <target-os>darwin:<framework>CoreFoundation
    <target-os>darwin:<framework>Security

    <target-os>darwin:<framework>OpenGL
    <target-os>iphone:<framework>OpenGLES
    <target-os>appletv:<framework>OpenGLES
;

lib scraps :
    [ glob-tree-ex src : *.cpp ]
    scraps_deps
    mnmlstc
    z
:
    <link>static
    <target-os>android:<source>GLESv2
    <target-os>linux:<source>pthread
    <target-os>linux:<source>dl
;

import package ;

package.install install-lib : <install-source-root>include : : scraps : [ glob-tree-ex include : *.h ] ;

path-constant PREFIX : [ option.get prefix : "/usr/local" ] ;
path-constant LIB : [ option.get libdir : $(PREFIX)/lib ] ;
path-constant PKG_CONFIG : $(LIB)/pkgconfig ;

make scraps.pc : Jamroot : @pkgconfig ;
rule pkgconfig ( targets * : sources * : properties * ) {
    if <toolset>darwin in $(properties) {
        PRIVATE_LIBS on $(targets) = -framework Foundation ;
    }
    if <target-os>linux in $(properties) {
        PRIVATE_LIBS on $(targets) = -lm -lpthread ;
    }
    if <target-os>android in $(properties) {
        PRIVATE_LIBS on $(targets) = -llog ;
    }
}
actions pkgconfig {
cat > $(<) <<- EOM
prefix=\${pcfiledir}/../..
exec_prefix=\${prefix}
libdir=\${exec_prefix}/lib
includedir=\${exec_prefix}/include

Name: scraps
Version: 0
Description: Random scraps of C++
Requires: mbedtls, libcurl, fmt, asio, gsl, libsodium, mnmlstc, json11
Libs: -L\${libdir} -lscraps
Libs.private: $(PRIVATE_LIBS)
Cflags: -I\${includedir} -DASIO_STANDALONE=1 -fvisibility=hidden
EOM
}

install install-pkgconfig : scraps.pc : <location>$(PKG_CONFIG) ;

alias install :
    install-lib
    install-pkgconfig
    install-mbedtls-if-owned
    install-curl-if-owned
    install-fmtlib-if-owned
    install-libsodium-if-owned
    install-gsl-if-owned
    install-asio-if-owned
    install-mnmlstc-if-owned
    install-json11-if-owned
;

explicit install install-lib install-pkgconfig ;
