source: trunk/base/src/package1.0/portdpkg.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: 6.5 KB
Line 
1# et:ts=4
2# portdpkg.tcl
3# $Id: portdpkg.tcl,v 1.7 2005/08/27 00:07:27 pguyot Exp $
4#
5# Copyright (c) 2004 Landon Fuller <landonf@opendarwin.org>
6# Copyright (c) 2002 - 2003 Apple Computer, Inc.
7# All rights reserved.
8#
9# Redistribution and use in source and binary forms, with or without
10# modification, are permitted provided that the following conditions
11# are met:
12# 1. Redistributions of source code must retain the above copyright
13#    notice, this list of conditions and the following disclaimer.
14# 2. Redistributions in binary form must reproduce the above copyright
15#    notice, this list of conditions and the following disclaimer in the
16#    documentation and/or other materials provided with the distribution.
17# 3. Neither the name of Apple Computer, Inc. nor the names of its contributors
18#    may be used to endorse or promote products derived from this software
19#    without specific prior written permission.
20#
21# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31# POSSIBILITY OF SUCH DAMAGE.
32#
33
34package provide portdpkg 1.0
35package require portutil 1.0
36
37set com.apple.dpkg [target_new com.apple.dpkg com.apple.dpkg::main]
38target_runtype ${com.apple.dpkg} always
39target_provides ${com.apple.dpkg} dpkg
40target_requires ${com.apple.dpkg} destroot
41
42# Target Namespace
43namespace eval com.apple.dpkg {
44}
45
46# Options
47options package.destpath
48
49set_ui_prefix
50
51proc com.apple.dpkg::main {args} {
52        global UI_PREFIX destpath os.arch os.platform
53   
54        ui_msg "$UI_PREFIX [format [msgcat::mc "Creating dpkg for %s-%s"] [option portname] [option portversion]]"
55
56        # get deplist
57        set deps [make_dependency_list [option portname]]
58        set deps [lsort -unique $deps]
59        foreach dep $deps {
60                set name [lindex [split $dep /] 0]
61                set vers [lindex [split $dep /] 1]
62                # don't re-package ourself
63                if {$name != [option portname]} {
64                        lappend dependencies "${name} (>= ${vers})"
65                }
66        }
67
68        if {[info exists dependencies]} {
69                ui_debug $dependencies
70        }
71
72        set controlpath [file join ${destpath} DEBIAN]
73        if {[file exists ${controlpath}]} {
74                if {![file isdirectory ${controlpath}]} {
75                        return -code error [format [msgcat::mc "Can not create dpkg control directory. %s not a directory."] ${controlpath}]
76                } else {
77                        ui_info [msgcat::mc "Removing stale dpkg control directory."]
78                        system "rm -rf \"${controlpath}\""
79                }
80        }
81        file mkdir ${controlpath}
82
83        set controlfd [open [file join ${controlpath} control] w+]
84
85        # Size, in kilobytes, of ${destpath}
86        set pkg_installed-size [expr [dirSize ${destpath}] / 1024]
87
88        # Create debian dependency list
89        if {[info exists dependencies]} {
90                if {[llength ${dependencies}] != 0} {
91                        set pkg_depends [join ${dependencies} ", "]
92                }
93        }
94       
95        # Create dpkg version number
96        if {[expr [option epoch] != 0]} {
97                set pkg_version "[option epoch]:[option portversion]"
98        } else {
99                set pkg_version "[option portversion]"
100        }
101        if {[expr [option revision] != 0]} {
102                append pkg_version "-[option revision]"
103        }
104
105        # Set dpkg category to first (main) category
106        set pkg_category [lindex [option categories] 0]
107
108        # Format the long description. Add a homepage if possible.
109        if {[exists long_description]} {
110                set pkg_long_description " [option long_description]\n"
111        } elseif {[exists description]} {
112                set pkg_long_description " [option description]\n"
113        } else {
114                set pkg_long_description " [option portname]\n"
115        }
116
117        if {[exists homepage]} {
118                append pkg_long_description " .\n"
119                append pkg_long_description " [option homepage]\n"
120        }
121
122        # Discern correct architecture
123        # From http://www.debian.org/doc/debian-policy/ch-customized-programs.html#fr55:
124        # The following architectures and operating systems are currently recognised   
125        # by dpkg-archictecture. The architecture, arch, is one of the following:     
126        # alpha, arm, hppa, i386, ia64, m68k, mips, mipsel, powerpc, s390, sh, sheb,   
127        # sparc and sparc64. The operating system, os, is one of: linux, gnu,         
128        # freebsd and openbsd. Use of gnu in this string is reserved for the           
129        # GNU/Hurd operating system.
130        switch -regex ${os.arch} {
131                i[3-9]86 { set pkg_arch "i386" }
132                default { set pkg_arch ${os.arch} }
133        }
134
135        # On systems other than Linux, the Architecture must contain
136        # the operating system name
137        if {${os.platform} != "linux"} {
138                set pkg_arch "${os.platform}-${pkg_arch}"
139        }
140
141        puts $controlfd "Package: [option portname]"
142        puts $controlfd "Architecture: ${pkg_arch}"
143        puts $controlfd "Version: ${pkg_version}"
144        puts $controlfd "Section: ${pkg_category}"
145        puts $controlfd "Maintainer: [option maintainers]"
146        if {[info exists pkg_depends]} {
147                puts $controlfd "Depends: ${pkg_depends}"
148        }
149        puts $controlfd "Installed-Size: ${pkg_installed-size}"
150
151        puts $controlfd "Description: [option description]"
152        # pkg_long_description is pre-formatted. Do not add a newline
153        puts -nonewline $controlfd "$pkg_long_description"
154        close $controlfd
155
156        # Build debian package in package.destpath
157        system "dpkg-deb -b \"${destpath}\" \"[option package.destpath]\""
158
159        ui_info [msgcat::mc "Removing dpkg control directory."]
160        system "rm -rf \"${controlpath}\""
161}
162
163proc com.apple.dpkg::make_dependency_list {portname} {
164        set result {}
165        if {[catch {set res [dport_search "^$portname\$"]} error]} {
166                global errorInfo
167                ui_debug "$errorInfo"
168                ui_error "port search failed: $error"
169                return 1
170        }
171        foreach {name array} $res {
172                array set portinfo $array
173       
174                if {[info exists portinfo(depends_run)] || [info exists portinfo(depends_lib)]} {
175                        # get the union of depends_run and depends_lib
176                        # xxx: only examines the portfile component of the depspec
177                        set depends {}
178                        if {[info exists portinfo(depends_run)]} {
179                                eval "lappend depends $portinfo(depends_run)"
180                        }
181                        if {[info exists portinfo(depends_lib)]} {
182                                eval "lappend depends $portinfo(depends_lib)"
183                        }
184
185                        foreach depspec $depends {
186                                set dep [lindex [split $depspec :] end]
187                                eval "lappend result [make_dependency_list $dep]"
188                        }
189                }
190                                lappend result $portinfo(name)/$portinfo(version)
191                                unset portinfo
192        }
193        return $result
194}
Note: See TracBrowser for help on using the repository browser.