~ubuntu-branches/debian/sid/link-monitor-applet/sid

« back to all changes in this revision

Viewing changes to jbsrc/lib/jb-install-options.c

  • Committer: Bazaar Package Importer
  • Author(s): Adriaan Peeters
  • Date: 2008-03-30 22:26:13 UTC
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20080330222613-5aubcuo9mgg2n7st
Tags: upstream-3.0
ImportĀ upstreamĀ versionĀ 3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * JB, the Jean-Yves Lefort's Build System
 
3
 * Copyright (C) 2008 Jean-Yves Lefort <jylefort@brutele.be>
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 3 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License along
 
16
 * with this program; if not, write to the Free Software Foundation, Inc.,
 
17
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
18
 */
 
19
 
 
20
#include "jb-install-options.h"
 
21
#include "jb-action.h"
 
22
#include "jb-variable.h"
 
23
 
 
24
void
 
25
jb_install_options_init (JBInstallOptions *self)
 
26
{
 
27
  g_return_if_fail(self != NULL);
 
28
 
 
29
  self->installdir = NULL;
 
30
  self->owner = NULL;
 
31
  self->group = NULL;
 
32
  self->extra_mode = 0;
 
33
}
 
34
 
 
35
void
 
36
jb_install_options_set_installdir (JBInstallOptions *self,
 
37
                                   const char *installdir)
 
38
{
 
39
  g_return_if_fail(self != NULL);
 
40
 
 
41
  g_free(self->installdir);
 
42
  self->installdir = g_strdup(installdir);
 
43
}
 
44
 
 
45
void
 
46
jb_install_options_set_owner (JBInstallOptions *self, const char *owner)
 
47
{
 
48
  g_return_if_fail(self != NULL);
 
49
 
 
50
  g_free(self->owner);
 
51
  self->owner = g_strdup(owner);
 
52
}
 
53
 
 
54
void
 
55
jb_install_options_set_group (JBInstallOptions *self, const char *group)
 
56
{
 
57
  g_return_if_fail(self != NULL);
 
58
 
 
59
  g_free(self->group);
 
60
  self->group = g_strdup(group);
 
61
}
 
62
 
 
63
void
 
64
jb_install_options_set_extra_mode (JBInstallOptions *self, mode_t extra_mode)
 
65
{
 
66
  g_return_if_fail(self != NULL);
 
67
 
 
68
  self->extra_mode = extra_mode;
 
69
}
 
70
 
 
71
void
 
72
jb_install_options_install (JBInstallOptions *self,
 
73
                            const char *srcfile,
 
74
                            const char *dstfile,
 
75
                            const char *default_owner,
 
76
                            const char *default_group,
 
77
                            mode_t default_mode)
 
78
{
 
79
  const char *owner;
 
80
  const char *group;
 
81
  mode_t mode;
 
82
 
 
83
  g_return_if_fail(self != NULL);
 
84
  g_return_if_fail(srcfile != NULL);
 
85
 
 
86
  if (self->installdir == NULL)
 
87
    return;
 
88
 
 
89
  owner = self->owner != NULL ? self->owner : default_owner;
 
90
  group = self->group != NULL ? self->group : default_group;
 
91
  mode = default_mode | self->extra_mode;
 
92
 
 
93
  if (dstfile == NULL)
 
94
    jb_action_install_file(srcfile,
 
95
                           self->installdir,
 
96
                           owner,
 
97
                           group,
 
98
                           mode);
 
99
  else
 
100
    {
 
101
      char *full_dstfile;
 
102
 
 
103
      full_dstfile = g_strdup_printf("%s/%s", self->installdir, dstfile);
 
104
      jb_action_install_to_file(srcfile,
 
105
                                full_dstfile,
 
106
                                owner,
 
107
                                group,
 
108
                                mode);
 
109
      g_free(full_dstfile);
 
110
    }
 
111
}
 
112
 
 
113
void
 
114
jb_install_options_install_data (JBInstallOptions *self,
 
115
                                 const char *srcfile,
 
116
                                 const char *dstfile)
 
117
{
 
118
  g_return_if_fail(self != NULL);
 
119
  g_return_if_fail(srcfile != NULL);
 
120
 
 
121
  jb_install_options_install(self,
 
122
                             srcfile,
 
123
                             dstfile,
 
124
                             jb_variable_get_string_or_null("data-owner"),
 
125
                             jb_variable_get_string_or_null("data-group"),
 
126
                             jb_variable_get_mode("data-mode"));
 
127
}
 
128
 
 
129
void
 
130
jb_install_options_install_program (JBInstallOptions *self,
 
131
                                    const char *srcfile,
 
132
                                    const char *dstfile)
 
133
{
 
134
  g_return_if_fail(self != NULL);
 
135
  g_return_if_fail(srcfile != NULL);
 
136
 
 
137
  jb_install_options_install(self,
 
138
                             srcfile,
 
139
                             dstfile,
 
140
                             jb_variable_get_string_or_null("program-owner"),
 
141
                             jb_variable_get_string_or_null("program-group"),
 
142
                             jb_variable_get_mode("program-mode"));
 
143
}
 
144
 
 
145
void
 
146
jb_install_options_install_library (JBInstallOptions *self,
 
147
                                    const char *srcfile,
 
148
                                    const char *dstfile)
 
149
{
 
150
  g_return_if_fail(self != NULL);
 
151
  g_return_if_fail(srcfile != NULL);
 
152
 
 
153
  jb_install_options_install(self,
 
154
                             srcfile,
 
155
                             dstfile,
 
156
                             jb_variable_get_string_or_null("library-owner"),
 
157
                             jb_variable_get_string_or_null("library-group"),
 
158
                             jb_variable_get_mode("library-mode"));
 
159
}