# -*- 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
PortGroup           compiler_blacklist_versions 1.0

name                nsis
version             3.09
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  c8176eb2b3381a2c0bb3f4951c2f38224ff3a91d \
                    sha256  0cd846c6e9c59068020a87bfca556d4c630f2c5d554c1098024425242ddc56e2 \
                    size    1808806 \
                    nsis-${version}.zip \
                    rmd160  f4f1506c06c4a78b80e1d616656fa8fc7f81c513 \
                    sha256  f5dc52eef1f3884230520199bac6f36b82d643d86b003ce51bd24b05c6ba7c91 \
                    size    2354828

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}

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
}
