From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: mrf Newsgroups: gmane.emacs.help Subject: Re: Running makefiles from emacs Date: Thu, 01 Jul 2021 12:33:48 +0300 Message-ID: <878s2qfja9.fsf@cock.li> References: <87tulibyap.fsf@zoho.eu> <87pmw6oc1z.fsf@cock.li> <87k0md9cxb.fsf@zoho.eu> <87h7hggafy.fsf@cock.li> <874kdf6uo7.fsf@zoho.eu> <87bl7nf7tx.fsf@cock.li> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="11066"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.5.8; emacs 27.2 Cc: help-gnu-emacs@gnu.org, mrf , Emanuel Berg To: Arthur Miller Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jul 01 11:57:59 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lytSC-0002Va-4d for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 01 Jul 2021 11:57:59 +0200 Original-Received: from localhost ([::1]:57906 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lytSB-0008KI-1o for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 01 Jul 2021 05:57:51 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50894) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lytRQ-0008K0-Fe for help-gnu-emacs@gnu.org; Thu, 01 Jul 2021 05:57:04 -0400 Original-Received: from mail.cock.li ([37.120.193.124]:57322) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lytRO-00022z-6y for help-gnu-emacs@gnu.org; Thu, 01 Jul 2021 05:57:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cock.li; s=mail; t=1625133419; bh=0zU1i2kvMx48/UGuhTqCkHtFNSWvRuKLykDnSS+j64w=; h=References:From:To:Cc:Subject:Date:In-reply-to:From; b=mvWtTFzeOqo8icNbPnG0YSlGj/V7X+bai/1yAZ4HRsiLTMWxG0YJEqmGgcez042lj iZeEiFpvIOw9PugqjU/qZo/cT3Eap1XTvFvKVd4jo8sAcRbRpvSTbCqegaE3DzwpTa Azq3tPf3PpYyzgz87DKaxf5tBRtQGuqvf5+QSlNasKqfgqD2J3WoDf9t8uqMxVkCMY soZ39DRFQsaLImEkH7sMRB7iJppmx+EBralqw1mjGvNxB7RCQGMqZ9CqiyRrGMbQwt kdG1Blakkcd+HOrZAnbi2CTLuPYVQmbZt1wuxllSsfvumCvZ3FOgsz06GE2uWgjNSK SfeftvQpvbriQ== In-reply-to: Received-SPF: pass client-ip=37.120.193.124; envelope-from=joinlaw@cock.li; helo=mail.cock.li X-Spam_score_int: 25 X-Spam_score: 2.5 X-Spam_bar: ++ X-Spam_report: (2.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_PBL=3.335, RCVD_IN_VALIDITY_RPBL=1.31, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:131362 Archived-At: 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 #include 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.