Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C > Re: using a she...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 10 of 17 Topic 26125 of 26977
Post > Topic >>

Re: using a shell script to compile your C programs

by "Joachim Schmitz" <nospam.schmitz@[EMAIL PROTECTED] > May 9, 2008 at 12:33 PM

"pereges" <Broli00@[EMAIL PROTECTED]
> schrieb im Newsbeitrag 
news:ab6bd1df-68e8-47ae-8419-117478a85be0@[EMAIL PROTECTED]
> On May 9, 12:37 pm, Richard Heathfield <r...@[EMAIL PROTECTED]
> wrote:
>
>>
>> Make files save on typing and braining. Which would you rather have to
>> remember and type: this...
>>
>> $ cc -o test file1.c file2.c file3.c
>>
>> or this?
>>
>> $ make
>>
>> It's no contest, right? Also, make only bothers to compile stuff that 
>> needs
>> compiling. If you haven't touched file3.c, why bother to recompile it?
It
>> only needs to be re-linked. So if you separate compilation from
linking,
>> you can save yourself some actual time.
>>
>
> hello, i think this C program for generating make files on linux was
> written by you which I found by searching through archives :
>
>
---------------------------------------------------------------------------------------------------
> #include <stdio.h>
>
> void genflags(void)
> {
>  puts("CC=gcc");
>  puts("CFLAGS=-W -Wall -ansi -pedantic -O2");
>  puts("DFLAGS=-g -pg");
>
> }
>
> void makeprg(int argc, char **argv)
> {
>  int i = 0;
>  printf("%s: %s.o", argv[1], argv[1]);
>  for(i = 2; i < argc; i++)
>  {
>    printf(" %s.o", argv[i]);
>  }
>  printf("\n\t$(CC) $(CFLAGS) $(DFLAGS) -o %s %s.o", argv[1],
> argv[1]);
>  for(i = 2; i < argc; i++)
>  {
>    printf(" %s.o", argv[i]);
>  }
>  putchar('\n');
>
> }
>
> void makeobjs(int argc, char **argv)
> {
>  int i = 0;
>  for(i = 1; i < argc; i++)
>  {
>    printf("%s.o: %s.c\n", argv[i], argv[i]);
>    printf("\t$(CC) $(CFLAGS) $(DFLAGS) -c -o %s.o %s.c\n", argv[i],
> argv[i]);
>  }
>  putchar('\n');
>
> }
>
> void makeclean(int argc, char **argv)
> {
>  int i = 0;
>  printf("clean:\n");
>  for(i = 1; i < argc; i++)
>  {
>    printf("\trm %s.o\n", argv[i]);
>  }
>  printf("\trm %s\n", argv[1]);
>  putchar('\n');
> }
>
> void makeinstall(int argc, char **argv)
> {
>  printf("install:\n");
>  printf("\tcp %s /usr/local/bin\n", argv[1]);
>  putchar('\n');
>
> }
>
> int main(int argc, char **argv)
> {
>  if(argc > 1)
>  {
>    genflags();
>    makeprg(argc, argv);
>    makeobjs(argc, argv);
>    makeclean(argc, argv);
>    makeinstall(argc, argv);
>  }
>  else
>  {
>    fputs("Usage: makegen progname [sourcename*]\n", stderr);
>  }
>  return 0;
>
> }
>
>
----------------------------------------------------------------------------------------------------
>
>
> I would like to use this for my project. Can you please tell me what
> is the purpose behind the functions makeclean and makeinstall ?
Just for the fun of it I've writen that program as a shell script:
$ cat makegen.sh
#!/bin/sh

if [ $# -gt 1 ]
then
        # genflags
        cat <<-!
        CC=gcc
        CFLAGS= -W -WALL -ansi -pedantic -O2
        DFLAGS=-g -pg

!

        # makeprg
        printf '%s:' $1
        for arg in $@[EMAIL PROTECTED]
 do
                printf ' %s.o' $arg
        done
        printf '\n\n'

        # makeobjs
        for arg in $@[EMAIL PROTECTED]
 do
                printf '%s.o: %s.c\n' $arg $arg
                printf '\t$(CC) $(CFLAGS) $(DFLAGS) -c -o %s.o %s.c\n'
$arg 
$arg
        done
        printf '\n'

        # makeclean
        printf 'clean:\n\trm -f %s' $arg
        for arg in $@[EMAIL PROTECTED]
 do
                printf ' %s.o' $arg
        done
        printf '\n\n'

        # makeinstall
        printf 'install:\n\tcp %s /usr/local/bin\n\n' $arg
else
        echo "Usage: makegen.sh progname [sourcename*]" >&2
fi
return 0


Has the advantage that to change it doesn't requite a recompile...
downside: you need a shell with builtin echo), the printf, rm and cp 
commands and most im****tantly: it is off topic here 8-)

Bye, Jojo
 




 17 Posts in Topic:
using a shell script to compile your C programs
pereges <Broli00@[EMAI  2008-05-09 00:10:09 
Re: using a shell script to compile your C programs
"Joachim Schmitz&quo  2008-05-09 09:14:45 
Re: using a shell script to compile your C programs
Spiros Bousbouras <spi  2008-05-09 00:21:25 
Re: using a shell script to compile your C programs
"Default User"   2008-05-09 17:44:58 
Re: using a shell script to compile your C programs
Richard Heathfield <rj  2008-05-09 07:37:22 
Re: using a shell script to compile your C programs
"Dan" <voids  2008-05-09 17:37:58 
Re: using a shell script to compile your C programs
Spiros Bousbouras <spi  2008-05-09 00:39:30 
Re: using a shell script to compile your C programs
pereges <Broli00@[EMAI  2008-05-09 00:49:32 
Re: using a shell script to compile your C programs
Richard Heathfield <rj  2008-05-09 08:28:56 
Re: using a shell script to compile your C programs
"Joachim Schmitz&quo  2008-05-09 12:33:07 
Re: using a shell script to compile your C programs
pereges <Broli00@[EMAI  2008-05-09 00:56:56 
Re: using a shell script to compile your C programs
Eligiusz Narutowicz<el  2008-05-09 11:50:17 
Re: using a shell script to compile your C programs
Antoninus Twink <nospa  2008-05-09 12:12:35 
Re: using a shell script to compile your C programs
"Joachim Schmitz&quo  2008-05-09 12:52:42 
Re: using a shell script to compile your C programs
pereges <Broli00@[EMAI  2008-05-09 04:16:40 
Re: using a shell script to compile your C programs
"Joachim Schmitz&quo  2008-05-09 13:26:47 
Re: using a shell script to compile your C programs
Bart <bc@[EMAIL PROTEC  2008-05-09 06:04:02 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Jul 26 3:50:38 CDT 2008.