unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: mrf <joinlaw@cock.li>
To: Arthur Miller <arthur.miller@live.com>
Cc: help-gnu-emacs@gnu.org, mrf <joinlaw@cock.li>,
	Emanuel Berg <moasenwood@zoho.eu>
Subject: Re: Running makefiles from emacs
Date: Thu, 01 Jul 2021 12:33:48 +0300	[thread overview]
Message-ID: <878s2qfja9.fsf@cock.li> (raw)
In-Reply-To: <AM9PR09MB49776754A52D57AD0A78F61996009@AM9PR09MB4977.eurprd09.prod.outlook.com>


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.



  reply	other threads:[~2021-07-01  9:33 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-28  0:07 Running makefiles from emacs lisa-asket
2021-06-28  0:58 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-28  2:13   ` lisa-asket
2021-06-28  4:14   ` mrf
2021-06-29 10:34     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-29 10:59       ` mrf
2021-06-30 19:04         ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-30 19:49           ` mrf
2021-07-01  8:39             ` Arthur Miller
2021-07-01  9:33               ` mrf [this message]
2021-07-01 18:18                 ` Arthur Miller
2021-07-02  8:13                   ` mrf
2021-07-02  9:00                     ` Arthur Miller
2021-07-02 17:13                       ` mrf
2021-07-02 18:24                         ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-07-02  4:32                 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-07-01 18:55             ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-07-02  7:44               ` mrf
2021-07-02 11:00                 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-28 10:37 ` Arthur Miller
2021-06-28 14:05   ` Jean Louis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=878s2qfja9.fsf@cock.li \
    --to=joinlaw@cock.li \
    --cc=arthur.miller@live.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=moasenwood@zoho.eu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).