mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-30 08:18:30 +00:00
Make build hermetic without shell scripts
- Fix some minor issues in ar.com - Have execve() look for `ape` command - Rewrite NT paths using /c/ rather /??/c:/ - Replace broken GCC symlinks with .sym files - Rewrite $PATH environment variables on startup - Make $(APE_NO_MODIFY_SELF) the default bootloader - Add all build command dependencies to build/bootstrap - Get the repository mostly building from source on non-Linux
This commit is contained in:
parent
d44ff6ce1f
commit
d230a01222
160 changed files with 2754 additions and 1342 deletions
|
@ -35,23 +35,24 @@ const char *FindDebugBinary(void) {
|
|||
char *p;
|
||||
size_t n;
|
||||
if (!once) {
|
||||
if (!(res = getenv("COMDBG"))) {
|
||||
p = GetProgramExecutableName();
|
||||
n = strlen(p);
|
||||
if (n > 4 && READ32LE(p + n - 4) == READ32LE(".dbg")) {
|
||||
res = p;
|
||||
} else if (n > 4 && READ32LE(p + n - 4) == READ32LE(".com") &&
|
||||
n + 4 < ARRAYLEN(buf)) {
|
||||
mempcpy(mempcpy(buf, p, n), ".dbg", 5);
|
||||
if (fileexists(buf)) {
|
||||
res = buf;
|
||||
}
|
||||
} else if (n + 8 < ARRAYLEN(buf)) {
|
||||
mempcpy(mempcpy(buf, p, n), ".com.dbg", 9);
|
||||
if (fileexists(buf)) {
|
||||
res = buf;
|
||||
}
|
||||
p = GetProgramExecutableName();
|
||||
n = strlen(p);
|
||||
if (n > 4 && READ32LE(p + n - 4) == READ32LE(".dbg")) {
|
||||
res = p;
|
||||
} else if (n > 4 && READ32LE(p + n - 4) == READ32LE(".com") &&
|
||||
n + 4 < ARRAYLEN(buf)) {
|
||||
mempcpy(mempcpy(buf, p, n), ".dbg", 5);
|
||||
if (fileexists(buf)) {
|
||||
res = buf;
|
||||
}
|
||||
} else if (n + 8 < ARRAYLEN(buf)) {
|
||||
mempcpy(mempcpy(buf, p, n), ".com.dbg", 9);
|
||||
if (fileexists(buf)) {
|
||||
res = buf;
|
||||
}
|
||||
}
|
||||
if (!res) {
|
||||
res = getenv("COMDBG");
|
||||
}
|
||||
once = true;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/str/tpenc.h"
|
||||
|
@ -23,6 +24,19 @@
|
|||
|
||||
#define ToUpper(c) ((c) >= 'a' && (c) <= 'z' ? (c) - 'a' + 'A' : (c))
|
||||
|
||||
forceinline int IsAlpha(int c) {
|
||||
return ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z');
|
||||
}
|
||||
|
||||
forceinline char *MemChr(const char *s, unsigned char c, unsigned long n) {
|
||||
for (; n; --n, ++s) {
|
||||
if ((*s & 255) == c) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static textwindows noasan noinstrument axdx_t Recode16to8(char *dst,
|
||||
size_t dstsize,
|
||||
const char16_t *src) {
|
||||
|
@ -45,13 +59,51 @@ static textwindows noasan noinstrument axdx_t Recode16to8(char *dst,
|
|||
}
|
||||
w = tpenc(x);
|
||||
do {
|
||||
if (r.ax + 1 >= dstsize) break;
|
||||
dst[r.ax++] = w;
|
||||
if (r.ax + 1 < dstsize) {
|
||||
dst[r.ax++] = w;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} while ((w >>= 8));
|
||||
}
|
||||
if (r.ax < dstsize) {
|
||||
dst[r.ax] = 0;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
textwindows noinstrument noasan void FixPath(char *path) {
|
||||
char *p;
|
||||
size_t i;
|
||||
|
||||
// turn backslash into slash
|
||||
for (p = path; *p; ++p) {
|
||||
if (*p == '\\') {
|
||||
*p = '/';
|
||||
}
|
||||
}
|
||||
|
||||
// turn c:/... into /c/...
|
||||
p = path;
|
||||
if (IsAlpha(p[0]) && p[1] == ':' && p[2] == '/') {
|
||||
p[1] = p[0];
|
||||
p[0] = '/';
|
||||
}
|
||||
for (; *p; ++p) {
|
||||
if (p[0] == ';' && IsAlpha(p[1]) && p[2] == ':' && p[3] == '/') {
|
||||
p[2] = p[1];
|
||||
p[1] = '/';
|
||||
}
|
||||
}
|
||||
|
||||
// turn semicolon into colon
|
||||
for (p = path; *p; ++p) {
|
||||
if (*p == ';') {
|
||||
*p = ':';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Transcodes NT environment variable block from UTF-16 to UTF-8.
|
||||
*
|
||||
|
@ -66,12 +118,17 @@ textwindows noasan noinstrument int GetDosEnviron(const char16_t *env,
|
|||
char *buf, size_t size,
|
||||
char **envp, size_t max) {
|
||||
int i;
|
||||
char *p;
|
||||
axdx_t r;
|
||||
i = 0;
|
||||
--size;
|
||||
while (*env) {
|
||||
if (i + 1 < max) envp[i++] = buf;
|
||||
r = Recode16to8(buf, size, env);
|
||||
if ((p = memchr(buf, '=', r.ax)) && IsAlpha(p[1]) && p[2] == ':' &&
|
||||
(p[3] == '\\' || p[3] == '/')) {
|
||||
FixPath(p + 1);
|
||||
}
|
||||
size -= r.ax + 1;
|
||||
buf += r.ax + 1;
|
||||
env += r.dx;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue