##
##  lljvm.spec -- OpenPKG RPM Package Specification
##  Copyright (c) 2000-2025 OpenPKG Project <http://openpkg.org/>
##
##  Permission to use, copy, modify, and distribute this software for
##  any purpose with or without fee is hereby granted, provided that
##  the above copyright notice and this permission notice appear in all
##  copies.
##
##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
##  SUCH DAMAGE.
##

#   package version
%define       V_lljvm  0.2
%define       V_newlib 1.18.0

#   package information
Name:         lljvm
Summary:      C to Java Bytecode Compiler
URL:          http://da.vidr.cc/projects/lljvm/
Vendor:       David Roberts
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Compiler
License:      MIT
Version:      %{V_lljvm}
Release:      20100125

#   list of sources
Source0:      http://lljvm.googlecode.com/files/lljvm-%{V_lljvm}.tar.gz
Source1:      ftp://sources.redhat.com/pub/newlib/newlib-%{V_newlib}.tar.gz
Patch0:       lljvm.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, make, ant
PreReq:       OpenPKG, openpkg >= 20160101
BuildPreReq:  llvm, jasmin, python, java, JAVA-JDK
PreReq:       llvm, jasmin, python, java, JAVA-JDK

%description
    LLJVM provides a set of tools and libraries for running
    comparatively low-level languages (such as C) on the JVM. The C to
    JVM bytecode compilation provided by LLJVM involves several steps.
    Source code is first compiled to LLVM intermediate representation
    (IR) by a frontend such as llvm-gcc or clang. LLVM IR is then
    translated to Jasmin assembly code, linked against other Java
    classes, and then assembled to JVM bytecode.

%track
    prog lljvm:lljvm = {
        version   = %{V_lljvm}
        url       = http://code.google.com/p/lljvm/downloads/list
        regex     = lljvm-(__VER__)\.tar\.gz
    }
    prog lljvm:newlib = {
        version   = %{V_newlib}
        url       = ftp://sources.redhat.com/pub/newlib/
        regex     = newlib-(__VER__)\.tar\.gz
    }

%prep
    %setup -q
    cp %{SOURCE newlib-%{V_newlib}.tar.gz} thirdparty/
    %patch -p0

%build
    %{l_shtool} subst \
        -e 's;/usr/bin/python;%{l_prefix}/bin/python;g' \
        -e 's;\(\[.\)java., .jasmin\.Main;\1%{l_prefix}/bin/jasmin;g' \
        -e 's;\(\[.\)java\(.,\);\1%{l_prefix}/bin/java\2;g' \
        lljvm-cc
    %{l_make} %{l_mflags}
    %{l_make} %{l_mflags} check
    ( echo "#!/bin/sh"
      echo "PATH=%{l_prefix}/bin:\$PATH"
      echo "exec %{l_prefix}/libexec/lljvm/lljvm-cc \${1+\"\$@\"}"
    ) >lljvm-cc.sh

%install
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/bin \
        $RPM_BUILD_ROOT%{l_prefix}/libexec/lljvm
    %{l_shtool} install -c -m 755 \
        lljvm-cc.sh $RPM_BUILD_ROOT%{l_prefix}/bin/lljvm-cc
    %{l_shtool} install -c -m 755 \
        lljvm-cc $RPM_BUILD_ROOT%{l_prefix}/libexec/lljvm/
    %{l_shtool} install -c -s -m 755 \
        lljvm-backend $RPM_BUILD_ROOT%{l_prefix}/libexec/lljvm/
    %{l_shtool} install -c -m 644 \
        lljvm-%{version}.jar $RPM_BUILD_ROOT%{l_prefix}/libexec/lljvm/
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}

%files -f files

%clean

