jbsrc/lib/src/core/jb-install-options.c (3902B) - raw
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 JBInstallOptions * 25 jb_install_options_new (void) 26 { 27 return g_new0(JBInstallOptions, 1); 28 } 29 30 void 31 jb_install_options_set_installdir (JBInstallOptions *self, 32 const char *installdir) 33 { 34 g_return_if_fail(self != NULL); 35 36 g_free(self->installdir); 37 self->installdir = g_strdup(installdir); 38 } 39 40 void 41 jb_install_options_set_owner (JBInstallOptions *self, const char *owner) 42 { 43 g_return_if_fail(self != NULL); 44 45 g_free(self->owner); 46 self->owner = g_strdup(owner); 47 } 48 49 void 50 jb_install_options_set_group (JBInstallOptions *self, const char *group) 51 { 52 g_return_if_fail(self != NULL); 53 54 g_free(self->group); 55 self->group = g_strdup(group); 56 } 57 58 void 59 jb_install_options_set_extra_mode (JBInstallOptions *self, mode_t extra_mode) 60 { 61 g_return_if_fail(self != NULL); 62 63 self->extra_mode = extra_mode; 64 } 65 66 void 67 jb_install_options_install (JBInstallOptions *self, 68 const char *srcfile, 69 const char *dstfile, 70 const char *default_owner, 71 const char *default_group, 72 mode_t default_mode) 73 { 74 const char *owner; 75 const char *group; 76 mode_t mode; 77 78 g_return_if_fail(self != NULL); 79 g_return_if_fail(srcfile != NULL); 80 81 if (self->installdir == NULL) 82 return; 83 84 owner = self->owner != NULL ? self->owner : default_owner; 85 group = self->group != NULL ? self->group : default_group; 86 mode = default_mode | self->extra_mode; 87 88 if (dstfile == NULL) 89 jb_action_install_file(srcfile, 90 self->installdir, 91 owner, 92 group, 93 mode); 94 else 95 { 96 char *full_dstfile; 97 98 full_dstfile = g_strdup_printf("%s/%s", self->installdir, dstfile); 99 jb_action_install_to_file(srcfile, 100 full_dstfile, 101 owner, 102 group, 103 mode); 104 g_free(full_dstfile); 105 } 106 } 107 108 void 109 jb_install_options_install_data (JBInstallOptions *self, 110 const char *srcfile, 111 const char *dstfile) 112 { 113 g_return_if_fail(self != NULL); 114 g_return_if_fail(srcfile != NULL); 115 116 jb_install_options_install(self, 117 srcfile, 118 dstfile, 119 jb_variable_get_string_or_null("data-owner"), 120 jb_variable_get_string_or_null("data-group"), 121 jb_variable_get_mode("data-mode")); 122 } 123 124 void 125 jb_install_options_install_program (JBInstallOptions *self, 126 const char *srcfile, 127 const char *dstfile) 128 { 129 g_return_if_fail(self != NULL); 130 g_return_if_fail(srcfile != NULL); 131 132 jb_install_options_install(self, 133 srcfile, 134 dstfile, 135 jb_variable_get_string_or_null("program-owner"), 136 jb_variable_get_string_or_null("program-group"), 137 jb_variable_get_mode("program-mode")); 138 } 139 140 void 141 jb_install_options_install_library (JBInstallOptions *self, 142 const char *srcfile, 143 const char *dstfile) 144 { 145 g_return_if_fail(self != NULL); 146 g_return_if_fail(srcfile != NULL); 147 148 jb_install_options_install(self, 149 srcfile, 150 dstfile, 151 jb_variable_get_string_or_null("library-owner"), 152 jb_variable_get_string_or_null("library-group"), 153 jb_variable_get_mode("library-mode")); 154 }