Date: Fri, 3 Mar 2023 11:17:48 -0000 (UTC) From: uwe@...err.spb.ru (Valery Ushakov) To: musl@...ts.openwall.com Subject: Re: Off topic question about shebang and exec() A. Wilcox <awilfox@...lielinux.org> wrote: >> On Thu, Mar 02, 2023 at 04:15:38PM +0200, Paul Schutte wrote: >> >>> I apologize for abusing the knowledge of the people on this list, but I >>> know they will know the answer. Google does not provide a usable answer. >>> >>> I am busy writing a toy language and I would like it to be used as both a >>> compiler and "interpreter" >>> >>> I would like it to compile the source and then run the resulting binary >>> when the source file is called via the shebang and it should just do a >>> normal compile when called with "compile code.src" >>> >>> argv contains the path to the compiler in both cases, which makes sense. >>> >>> Is there any way to determine which method was used to call the compiler? >> >> Not to my knowledge. I would also consider it poor design to use a trick >> like that. The normal assumption is that a shebang and just running the >> command from command line are equivalent. >> >> Normal solution here is to have a command line switch to select one >> behavior or the other. That switch can be added to the shebang or the >> command line, whatever you choose. > > An even better solution is hinted in OP's problem description: argv. > > Have two entry points, like a multi call binary, based on that. > > You could use a softlink or hardlink named `lang` to `langc`. argv tricks are cute but, if employed, they cannot be the only way for the binary to infer its "identity". Because sooner or later you will need to have a copy of (or a symlink to) the binary called foo.old or something and the heuristic will break down. What's the problem with separate binaries? Off the top of my head I can think of e.g. UCB Pascal (pi, px, pix) and Icon (icont, iconx, icon). Even cc(1) is kinda in this category too (except it doesn't execute the result, but it arranges for cpp/cc1//as/ld stages to be run in proper sequence). Crunched binaries like NetBSD's /rescue or busybox are trying to save every byte of space b/c they need to fit tight constraints, like e.g. a memory disk. But is there really a good reason to try to save those few pages in the case of the compiler/interpreter (that are likely dynamically linked to begin with, so "manually" sharing library bits is not really a problem)? -uwe
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.