Mercurial > molko
comparison libmlk-core/core/sys.c @ 307:363024b76da7
make: create install-data rather than fakeroot
author | David Demelier <markand@malikania.fr> |
---|---|
date | Tue, 29 Jun 2021 09:49:48 +0200 |
parents | f04b4ee04db3 |
children | 0858e33a762d |
comparison
equal
deleted
inserted
replaced
306:6a7bca547f9a | 307:363024b76da7 |
---|---|
53 [SYS_DIR_BIN] = MOLKO_BINDIR, | 53 [SYS_DIR_BIN] = MOLKO_BINDIR, |
54 [SYS_DIR_DATA] = MOLKO_DATADIR, | 54 [SYS_DIR_DATA] = MOLKO_DATADIR, |
55 [SYS_DIR_LOCALE] = MOLKO_LOCALEDIR | 55 [SYS_DIR_LOCALE] = MOLKO_LOCALEDIR |
56 }; | 56 }; |
57 | 57 |
58 static const char *abspaths[] = { | |
59 [SYS_DIR_BIN] = MOLKO_ABS_BINDIR, | |
60 [SYS_DIR_DATA] = MOLKO_ABS_DATADIR, | |
61 [SYS_DIR_LOCALE] = MOLKO_ABS_LOCALEDIR | |
62 }; | |
63 | |
64 #if defined(_WIN32) | |
65 | |
66 static inline int | |
67 is_absolute(const char *path) | |
68 { | |
69 return !PathIsRelativeA(path); | |
70 } | |
71 | |
72 #else | |
73 | |
74 static inline int | |
75 is_absolute(const char *path) | |
76 { | |
77 return path[0] == '/'; | |
78 } | |
79 | |
80 #endif | |
81 | |
82 static inline char * | 58 static inline char * |
83 normalize(char *str) | 59 normalize(char *str) |
84 { | 60 { |
85 for (char *p = str; *p; ++p) | 61 for (char *p = str; *p; ++p) |
86 if (*p == '\\') | 62 if (*p == '\\') |
104 { | 80 { |
105 static char path[PATH_MAX]; | 81 static char path[PATH_MAX]; |
106 static char ret[PATH_MAX]; | 82 static char ret[PATH_MAX]; |
107 char *base, *binsect; | 83 char *base, *binsect; |
108 | 84 |
109 /* 1. Get current binary directory. */ | 85 if ((base = getenv("MLK_ROOT"))) { |
110 base = SDL_GetBasePath(); | 86 snprintf(ret, sizeof (ret), "%s/%s/%s", base, MOLKO_PREFIX, paths[kind]); |
111 | 87 } else { |
112 /* | 88 /* |
113 * 2. Decompose the path to the given special directory by computing | 89 * Some system does not provide support (shame on you OpenBSD) |
114 * relative directory to it from where the binary is located. | 90 * to the executable path. In that case we use PREFIX+<dir> |
115 * | 91 * instead. |
116 * Example: | 92 */ |
117 * PREFIX/bin/mlk | 93 if (!(base = SDL_GetBasePath())) |
118 * PREFIX/share/molko | 94 snprintf(ret, sizeof (ret), "%s/%s", MOLKO_PREFIX, paths[kind]); |
119 * | 95 else { |
120 * The path to the data is ../share/molko starting from the binary. | 96 /* |
121 * | 97 * Decompose the path to the given special directory by |
122 * If path to binary is absolute we can't determine relative paths to | 98 * computing relative directory to it from where the |
123 * any other directory and use the absolute one instead. | 99 * binary is located. |
124 * | 100 * |
125 * Also, on some platforms SDL_GetBasePath isn't implemented and returns | 101 * Example: |
126 * NULL, in that case return the fallback to the installation prefix. | 102 * |
127 */ | 103 * PREFIX/bin/mlk |
128 if (is_absolute(paths[SYS_DIR_BIN]) || is_absolute(paths[kind]) || !base) | 104 * PREFIX/share/mlk-adventure |
129 return absolute(abspaths[kind]); | 105 * |
130 | 106 * The path to the data is ../share/molko starting from |
131 /* | 107 * the binary. |
132 * 3. Put the base path into the path and remove the value of | 108 * |
133 * MOLKO_BINDIR. | 109 * Put the base path into the path and remove the value |
134 * | 110 * of MOLKO_BINDIR. |
135 * Example: | 111 * |
136 * from: /usr/local/bin | 112 * Example: |
137 * to: /usr/local | 113 * from: /usr/local/bin |
138 */ | 114 * to: /usr/local |
139 strlcpy(path, base, sizeof (path)); | 115 */ |
140 SDL_free(base); | 116 strlcpy(path, base, sizeof (path)); |
141 | 117 SDL_free(base); |
142 if ((binsect = strstr(path, paths[SYS_DIR_BIN]))) | 118 |
143 *binsect = '\0'; | 119 if ((binsect = strstr(path, paths[SYS_DIR_BIN]))) |
144 | 120 *binsect = '\0'; |
145 snprintf(ret, sizeof (ret), "%s%s", path, paths[kind]); | 121 |
122 snprintf(ret, sizeof (ret), "%s%s", path, paths[kind]); | |
123 } | |
124 } | |
146 | 125 |
147 return normalize(ret); | 126 return normalize(ret); |
148 } | 127 } |
149 | 128 |
150 static const char * | 129 static const char * |