# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0

name                nsis
version             3.12
set major           [lindex [split ${version} .] 0]
categories          devel
license             zlib CPL-1 MIT
maintainers         nomaintainer

description         NSIS is a tool for creating win32 installers.
long_description    NSIS (Nullsoft Scriptable Install System) is a tool \
                    that allows programmers to create software installers \
                    for Windows. It is released under an open source \
                    license and is completely free for any use.

homepage            https://nsis.sourceforge.io/
master_sites        sourceforge:project/nsis/NSIS%20${major}/${version}

distname            ${name}-${version}-src
use_bzip2           yes

distfiles-append    nsis-${version}.zip
extract.only-delete nsis-${version}.zip

checksums           nsis-${version}-src.tar.bz2 \
                    rmd160  7f67beda26c41d27edc0b337067dba2473368979 \
                    sha256  f3ed7a8e4aa2cf4e8cf47d3b563a02559e0cb4934db2662b2f9661b824e2b186 \
                    size    1818389 \
                    nsis-${version}.zip \
                    rmd160  fc0dba397487891354de80aa6c4bafdbde717a9c \
                    sha256  56581f90db321581c5381193d796fffcf2d24b2f8fed2160a6c6a3baa67f2c4f \
                    size    2362938

depends_build       port:scons

depends_lib         port:libiconv \
                    port:zlib

# Installer checks for cross-compiler during build, but doesn't seem to use it?
#                   port:i386-mingw32-gcc

post-extract {
    system -W ${workpath} "unzip ${distpath}/nsis-${version}.zip"
}

use_configure       no

# https://sourceforge.net/p/nsis/bugs/1251/
compiler.blacklist  {clang < 900} *gcc-4.*

build.args          APPEND_CCFLAGS="[get_canonical_archflags cc] -stdlib=${configure.cxx_stdlib}" \
                    APPEND_CPPPATH="${prefix}/include" \
                    APPEND_LIBPATH="${prefix}/lib" \
                    APPEND_LINKFLAGS="[get_canonical_archflags ld] -stdlib=${configure.cxx_stdlib}" \
                    CC="${configure.cc}" \
                    CXX="${configure.cxx}" \
                    PREFIX="${prefix}" \
                    SKIPMISC=all \
                    SKIPPLUGINS=all \
                    SKIPSTUBS=all \
                    SKIPUTILS=all \
                    STRIP=0 \
                    VERSION=${version}

use_parallel_build  no

build.cmd           ${prefix}/bin/scons
build.target

destroot.args       {*}${build.args}
destroot.destdir    PREFIX_DEST="${destroot}"

post-destroot {
    foreach dir {Bin Contrib Docs Examples Include Plugins Stubs} {
        file delete -force ${destroot}${prefix}/share/nsis/${dir}
        file copy ${workpath}/nsis-${version}/${dir} ${destroot}${prefix}/share/nsis
    }
    system "chmod -R go-w '${destroot}${prefix}/share/nsis'"
}

variant advanced_logging description {Build makensis with advanced logging support} {
    build.args-append    NSIS_CONFIG_LOG=yes
}

variant large_strings description {Build makensis with support for large strings} {
    build.args-append    NSIS_MAX_STRLEN=8192
}

variant debug description {Build makensis with debugging information} {
    build.args-append    DEBUG=1
}
