help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Running makefiles from emacs


From: Arthur Miller
Subject: Re: Running makefiles from emacs
Date: Thu, 01 Jul 2021 20:18:50 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

mrf <joinlaw@cock.li> writes:

> Arthur Miller writes:
>
>> Emacs comment is neat. You can achieve similar with a small shell script
>> too, check this:
>>
>> https://github.com/ryanmjacobs/c
>
> I love this community it's nice place to share nice hacks
>
> But I have something surpasses this and I don't use it in my article
> because it's too old, anyway take this:
>
> /*****************/
> /* script.c file */
> /*****************/
> #if 0
> #//if file is not yet compiled
> if [ -f $(basename $0 .c) ]
> then
>   printf ""
> else
>   gcc $CFLAGS $CXXFLAGS $LDFLAGS $0 -o `basename $0 .c` && exec ./`basename 
> $0 .c` "$@";
> fi;
>
> #//if file is already compiled
> if [ `stat -c %Y $(basename $0 .c) ` -lt `stat -c %Y $0` ]
> then
> gcc $CFLAGS $CXXFLAGS $LDFLAGS $0 -o `basename $0 .c` && exec ./`basename $0 
> .c` "$@";
> else
>   exec ./`basename $0 .c` "$@";
>     fi;
> exit
> #endif // 0
>
> #include <stdio.h>
> #include <math.h>
>     
> int main (int argc, char **argv)
> {
>   printf("%f\n", cosf (103.0f));
>
>   printf(
>     "variables in argv (excluding %s) =%d\nparam1=%s param2=%d param3=%d\n\n",
>     __FILE__, argc-1, argv[1], atoi(argv[2]), atoi(argv[3]));
>
>   return 0;
> }
>
> /* Local Variables: */
> /* compile-command: "LDFLAGS='-lm' CFLAGS='-Wall' bash script.c 'String' 10 
> 5395" */
> /* End: */
>
>
>
>
> this neat hack will include a full fledged bash script and this script
> will only compile when file is changed otherwise will run the program,
> you can run it with:
>
> bash script_name.c
>
> or by changing the file permission `chmod +x script_name.c` and then
> `./script_name.c`
>
> the idea is that there is conditional preprocessor that will only
> compile when true(1) and we set it to false(0) on purpose.
>
> Also this script allow you to pass paramenters and also compiler flags
> by using environment variable and I think this is great way to write C
> CGI scripts.
>
> And BTW tiny C compiler is better option than what you send.

Yes, TCC comes with a similar hack, but the C script is independent of
the compiler and you don't need to clutter each and every file with bash
script and linker/compiler directives in each file either.

But sure, there is more than one way to skin a cat .... no idea why
people say that, I assure I have never try to skinn a cat nor any other
animal.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]