summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2022-03-21 11:32:43 +0100
committerJo-Philipp Wich <jo@mein.io>2022-03-21 11:32:43 +0100
commiteb0d2f124872aa279ed605c5231997f71f0b6139 (patch)
tree201063be20559c0312dfd4118c07aa8da78577c2
parent753dea91bcfecb82fb5db646e72c9a022d2d2cbf (diff)
main: turn ucode into multicall executable
Turn the ucode executable into a multicall binary and select default flags based on the name it was invoked with. Introduce two new symlinks "ucc" and "utpl" which start ucode in compile and template mode respectively. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r--CMakeLists.txt4
-rw-r--r--main.c30
2 files changed, 30 insertions, 4 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c0ed3d4..1f81cdb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -216,6 +216,10 @@ INSTALL(TARGETS ucode RUNTIME DESTINATION bin)
INSTALL(TARGETS libucode LIBRARY DESTINATION lib)
INSTALL(TARGETS ${LIBRARIES} LIBRARY DESTINATION lib/ucode)
+ADD_CUSTOM_TARGET(ucc ALL COMMAND ${CMAKE_COMMAND} -E create_symlink ucode ucc)
+ADD_CUSTOM_TARGET(utpl ALL COMMAND ${CMAKE_COMMAND} -E create_symlink ucode utpl)
+INSTALL(FILES ucc;utpl DESTINATION bin)
+
FILE(GLOB UCODE_HEADERS "include/ucode/*.h")
INSTALL(FILES ${UCODE_HEADERS} DESTINATION include/ucode)
diff --git a/main.c b/main.c
index c974c69..e066961 100644
--- a/main.c
+++ b/main.c
@@ -37,8 +37,6 @@ static FILE *stdin_unused;
static void
print_usage(const char *app)
{
- const char *p = strrchr(app, '/');
-
printf(
"Usage:\n"
" %1$s -h\n"
@@ -100,7 +98,7 @@ print_usage(const char *app)
"-s\n"
" Omit (strip) debug information when compiling files.\n"
" Only meaningful in conjunction with `-c`.\n\n",
- p ? p + 1 : app);
+ app);
}
@@ -444,6 +442,22 @@ parse_library_load(char *opt, uc_vm_t *vm)
return true;
}
+static const char *
+appname(const char *argv0)
+{
+ const char *p;
+
+ if (!argv0)
+ return "ucode";
+
+ p = strrchr(argv0, '/');
+
+ if (p)
+ return p + 1;
+
+ return argv0;
+}
+
int
main(int argc, char **argv)
{
@@ -454,6 +468,7 @@ main(int argc, char **argv)
bool strip = false;
uc_vm_t vm = { 0 };
int opt, rv = 0;
+ const char *app;
uc_value_t *o;
int fd;
@@ -464,11 +479,18 @@ main(int argc, char **argv)
.raw_mode = true
};
+ app = appname(argv[0]);
+
if (argc == 1) {
- print_usage(argv[0]);
+ print_usage(app);
goto out;
}
+ if (!strcmp(app, "utpl"))
+ config.raw_mode = false;
+ else if (!strcmp(app, "ucc"))
+ outfile = "./uc.out";
+
stdin_unused = stdin;
uc_vm_init(&vm, &config);