source: trunk/base/src/package1.0/portrpmpackage.tcl @ 16589

Last change on this file since 16589 was 13738, checked in by pguyot (Paul Guyot), 15 years ago

Add a lot of missing $Id$

  • Property svn:eol-style set to native
File size: 7.1 KB
Line 
1# et:ts=4
2# portrpmpackage.tcl
3# $Id: portrpmpackage.tcl,v 1.6 2005/08/27 00:07:27 pguyot Exp $
4#
5# Copyright (c) 2002 - 2003 Apple Computer, Inc.
6# All rights reserved.
7#
8# Redistribution and use in source and binary forms, with or without
9# modification, are permitted provided that the following conditions
10# are met:
11# 1. Redistributions of source code must retain the above copyright
12#    notice, this list of conditions and the following disclaimer.
13# 2. Redistributions in binary form must reproduce the above copyright
14#    notice, this list of conditions and the following disclaimer in the
15#    documentation and/or other materials provided with the distribution.
16# 3. Neither the name of Apple Computer, Inc. nor the names of its contributors
17#    may be used to endorse or promote products derived from this software
18#    without specific prior written permission.
19#
20# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30# POSSIBILITY OF SUCH DAMAGE.
31#
32
33package provide portrpmpackage 1.0
34package require portutil 1.0
35
36set com.apple.rpmpackage [target_new com.apple.rpmpackage rpmpackage_main]
37target_runtype ${com.apple.rpmpackage} always
38target_provides ${com.apple.rpmpackage} rpmpackage
39target_requires ${com.apple.rpmpackage} destroot
40
41options package.destpath
42
43set_ui_prefix
44
45proc rpmpackage_main {args} {
46    global portname portversion portrevision UI_PREFIX
47   
48    ui_msg "$UI_PREFIX [format [msgcat::mc "Creating RPM package for %s-%s"] ${portname} ${portversion}]"
49   
50    return [rpmpackage_pkg $portname $portversion $portrevision]
51}
52
53proc rpmpackage_pkg {portname portversion portrevision} {
54    global UI_PREFIX package.destpath portdbpath destpath workpath prefix portresourcepath categories maintainers description long_description homepage epoch portpath
55   
56    set rpmdestpath ""
57    if {![string equal ${package.destpath} ${workpath}] && ![string equal ${package.destpath} ""]} {
58        set pkgpath ${package.destpath}
59        system "mkdir -p ${pkgpath}/BUILD"
60        system "mkdir -p ${pkgpath}/RPMS"
61        system "mkdir -p ${pkgpath}/SOURCES"
62        system "mkdir -p ${pkgpath}/SPECS"
63        system "mkdir -p ${pkgpath}/SRPMS"
64        set rpmdestpath "--define '_topdir ${pkgpath}'"
65    }
66   
67    foreach dir { "${prefix}/src/apple/RPMS" "/usr/src/apple/RPMS" "/darwinports/rpms/RPMS"} {
68        foreach arch {"ppc" "i386" "fat"} {
69            set rpmpath "$dir/${arch}/${portname}-${portversion}-${portrevision}.${arch}.rpm"
70            if {[file readable $rpmpath] && ([file mtime ${rpmpath}] >= [file mtime ${portpath}/Portfile])} {
71                ui_msg "$UI_PREFIX [format [msgcat::mc "RPM package for %s-%s is up-to-date"] ${portname} ${portversion}]"
72                return 0
73            }
74        }
75    }
76   
77    set specpath ${workpath}/${portname}.spec
78    # long_description, description, or homepage may not exist
79    foreach variable {long_description description homepage categories maintainers} {
80        if {![info exists $variable]} {
81            set pkg_$variable ""
82        } else {
83            set pkg_$variable [set $variable]
84        }
85    }
86    set category   [lindex [split $categories " "] 0]
87    set maintainer $maintainers
88   
89    set dependencies {}
90    # get deplist
91    set deps [make_dependency_list $portname]
92    set deps [lsort -unique $deps]
93    foreach dep $deps {
94        set name [lindex [split $dep /] 0]
95        set vers [lindex [split $dep /] 1]
96        # don't re-package ourself
97        if {$name != $portname} {
98            lappend dependencies "${name} >= ${vers}"
99        }
100    }
101   
102    system "rm -f '${workpath}/${portname}.filelist' && touch '${workpath}/${portname}.filelist'"
103    #system "cd '${destpath}' && find . -type d | grep -v -E '^.$' | sed -e 's/\"/\\\"/g' -e 's/^./%dir \"/' -e 's/$/\"/' > '${workpath}/${portname}.filelist'"
104    system "cd '${destpath}' && find . ! -type d | grep -v /etc/ | sed -e 's/\"/\\\"/g' -e 's/^./\"/' -e 's/$/\"/' >> '${workpath}/${portname}.filelist'"
105    system "cd '${destpath}' && find . ! -type d | grep /etc/ | sed -e 's/\"/\\\"/g' -e 's/^./%config \"/' -e 's/$/\"/' >> '${workpath}/${portname}.filelist'"
106    write_spec ${specpath} $portname $portversion $portrevision $pkg_description $pkg_long_description $category $maintainer $destpath $dependencies $epoch
107    system "DP_USERECEIPTS='${portdbpath}/receipts' rpmbuild -bb -v ${rpmdestpath} ${specpath}"
108   
109    return 0
110}
111
112proc make_dependency_list {portname} {
113    set result {}
114    if {[catch {set res [dport_search "^$portname\$"]} error]} {
115                global errorInfo
116                ui_debug "$errorInfo"
117        ui_error "port search failed: $error"
118        return 1
119    }
120    foreach {name array} $res {
121        array set portinfo $array
122       
123        if {[info exists portinfo(depends_run)] || [info exists portinfo(depends_lib)]} {
124            # get the union of depends_run and depends_lib
125            # xxx: only examines the portfile component of the depspec
126            set depends {}
127            if {[info exists portinfo(depends_run)]} { eval "lappend depends $portinfo(depends_run)" }
128            if {[info exists portinfo(depends_lib)]} { eval "lappend depends $portinfo(depends_lib)" }
129           
130            foreach depspec $depends {
131                set dep [lindex [split $depspec :] end]
132               
133                # xxx: nasty hack
134                if {$dep != "XFree86"} {
135                    eval "lappend result [make_dependency_list $dep]"
136                }
137            }
138        }
139        lappend result $portinfo(name)/$portinfo(version)
140        unset portinfo
141    }
142    ui_debug "dependencies for ${portname}: $result"
143    return $result
144}
145
146proc write_spec {specfile portname portversion portrevision description long_description category maintainer destroot dependencies epoch} {
147    set specfd [open ${specfile} w+]
148    set origportname ${portname}
149    regsub -all -- "\-" $portversion "_" portversion
150    regsub -all -- "\-" $portname "_" portname
151    puts $specfd "\#Spec file generated by DarwinPorts
152%define distribution DarwinPorts
153%define vendor OpenDarwin
154%define packager ${maintainer}
155
156Summary: ${description}
157Name: ${portname}
158Version: ${portversion}
159Release: ${portrevision}
160Group: ${category}
161License: Unknown
162BuildRoot: ${destroot}
163Epoch: ${epoch}"
164    if {[llength ${dependencies}] != 0} {
165        foreach require ${dependencies} {
166            puts $specfd "Requires: [regsub -all -- "\-" $require "_"]"
167        }
168    }
169    puts $specfd "
170%description
171${long_description}
172%prep
173%build
174echo \"Go DarwinPorts\"
175%install
176%clean
177%files -f ${destroot}/../${origportname}.filelist
178"
179    close $specfd
180}
Note: See TracBrowser for help on using the repository browser.