aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSlendi <slendi@socopon.com>2023-03-21 21:52:32 +0200
committerSlendi <slendi@socopon.com>2023-03-21 21:52:32 +0200
commit78fe1150a5dccfda9d281fd9b77cd4c63b1be45d (patch)
tree5caa3596b88a76341502a2939321395bdec4306d
parent8b885fdb282358505ba1655f523780d2d3f10d84 (diff)
Fix build system on Windows.
Signed-off-by: Slendi <slendi@socopon.com>
-rw-r--r--main.c55
1 files changed, 32 insertions, 23 deletions
diff --git a/main.c b/main.c
index aead009..2ba8488 100644
--- a/main.c
+++ b/main.c
@@ -13,17 +13,6 @@
#include "tomlc99/toml.h"
#include "x-watcher/x-watcher.h"
-#if defined(_WIN32)
-// FIXME: Find a way to do ANSI on Windows.
-#define RED ""
-#define GREEN ""
-#define YELLOW ""
-#define BLUE ""
-#define MAGENTA ""
-#define CYAN ""
-
-#define RESET ""
-#else
#define RED "\e[31m"
#define GREEN "\e[32m"
#define YELLOW "\e[33m"
@@ -32,13 +21,23 @@
#define CYAN "\e[36m"
#define RESET "\e[0m"
-#endif
typedef struct {
bool zeal_build;
bool watch;
} build_options;
+void unixify_path(char *str) {
+#if defined(_WIN32)
+ if (!str) return;
+ while (*str != '\0') {
+ if (*str == '\\')
+ *str = '/';
+ str++;
+ }
+#endif
+}
+
// FIXME: This is hardcoded, fix it.
char *python_interpreter_path = "/usr/local/bin/python3";
@@ -356,16 +355,6 @@ char *text_format(char const *format, ...) {
char *get_username(void) {
#if defined(_WIN32)
- // FIXME: This leaks memory.
-
- // TCHAR infoBuf[105];
- // DWORD bufCharCount = 105;
- // if(!GetUserName( infoBuf, &bufCharCount ))
- // fputs("Error: Cannot get username: GetUserName failed.\n", stderr);
-
- // char *c_szText[105];
- // wcstombs(c_szText, infoBuf, wcslen(infoBuf) + 1);
- // return c_szText;
return getenv("USERNAME");
#else
uid_t uid = geteuid();
@@ -420,8 +409,19 @@ void print_help(char **argv) {
}
bool file_exists(char const *path) {
+#if defined(_WIN32)
+ if( _taccess_s(path, 0) == 0 )
+ {
+ struct _stat status;
+ _tstat(path, &status);
+ return (status.st_mode & S_IFDIR) != 0;
+ }
+
+ return FALSE;
+#else
struct stat st = {0};
return (stat(path, &st) != -1);
+#endif
}
// FIXME: Implement for Windows.
@@ -694,6 +694,7 @@ int build_project(char *project_path, build_options options) {
text_format("%s/build", project_path);
char *build_dir = malloc((strlen(buffer_text_format)+1)*sizeof(char));
strcpy(build_dir, buffer_text_format);
+ unixify_path(build_dir);
if (!file_exists(build_dir)) {
bool status = makedir(build_dir);
if (!status) {
@@ -706,6 +707,7 @@ int build_project(char *project_path, build_options options) {
text_format("%s/src", project_path);
char *src_dir = malloc((strlen(buffer_text_format)+1)*sizeof(char));
strcpy(src_dir, buffer_text_format);
+ unixify_path(src_dir);
// Clear and populate.
puts(" -> Populating build directory...");
@@ -737,6 +739,7 @@ int build_project(char *project_path, build_options options) {
text_format("%s/output", project_path);
char *out_dir = malloc((strlen(buffer_text_format)+1)*sizeof(char));
strcpy(out_dir, buffer_text_format);
+ unixify_path(out_dir);
if (!file_exists(out_dir)) {
bool status = makedir(out_dir);
if (!status) {
@@ -750,12 +753,13 @@ int build_project(char *project_path, build_options options) {
text_format("%s/output/%s-%s.zeal.ISO.C", project_path, manifest->name, manifest->version);
else
text_format("%s/output/%s-%s.ISO.C", project_path, manifest->name, manifest->version);
+ unixify_path(buffer_text_format);
puts(" -> Generating ISO.C");
char *iso_c = malloc((strlen(buffer_text_format)+1)*sizeof(char));
strcpy(iso_c, buffer_text_format);
#if defined(_WIN32)
- system(text_format("RedSeaGen.exe '%s' '%s'", build_dir, iso_c));
+ system(text_format("RedSeaGen.exe %s %s", build_dir, iso_c));
#else
system(text_format("RedSeaGen '%s' '%s'", build_dir, iso_c));
#endif
@@ -842,6 +846,7 @@ int main(int argc, char **argv) {
text_format("%s/src", project_path);
char *src_dir = malloc((strlen(buffer_text_format)+1)*sizeof(char));
strcpy(src_dir, buffer_text_format);
+ unixify_path(src_dir);
if (!file_exists(src_dir)) {
bool status = makedir(src_dir);
@@ -934,12 +939,14 @@ Del(\"C:/Apps/Main/RunCD.*\");\n\
fputs("Error: Cannot build project: Cannot get current working directory.\n", stderr);
return 1;
}
+ unixify_path(cwd);
project_path = find_project_root();
if (project_path == NULL) {
fputs("Error: Cannot build project: Not in a project directory.\n", stderr);
return 1;
}
+ unixify_path(project_path);
int ret = build_project(project_path, options);
if (ret != 0)
@@ -949,10 +956,12 @@ Del(\"C:/Apps/Main/RunCD.*\");\n\
text_format("%s/src", project_path);
char *src_dir = malloc((strlen(buffer_text_format)+1)*sizeof(char));
strcpy(src_dir, buffer_text_format);
+ unixify_path(src_dir);
text_format("%s/lib", project_path);
char *lib_dir = malloc((strlen(buffer_text_format)+1)*sizeof(char));
strcpy(lib_dir, buffer_text_format);
+ unixify_path(lib_dir);
x_watcher *watcher = xWatcher_create();