Re: using a shell script to compile your C programs
- From: pereges <Broli00@xxxxxxxxx>
- Date: Fri, 9 May 2008 00:49:32 -0700 (PDT)
On May 9, 12:37 pm, Richard Heathfield <r...@xxxxxxxxxxxxxxx> 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 ?
.
- Follow-Ups:
- Re: using a shell script to compile your C programs
- From: Joachim Schmitz
- Re: using a shell script to compile your C programs
- From: Antoninus Twink
- Re: using a shell script to compile your C programs
- From: Richard Heathfield
- Re: using a shell script to compile your C programs
- References:
- using a shell script to compile your C programs
- From: pereges
- Re: using a shell script to compile your C programs
- From: Richard Heathfield
- using a shell script to compile your C programs
- Prev by Date: Re: casting question - i64 = *((__int64*)&d);
- Next by Date: Re: Wit-to-whine ratios
- Previous by thread: Re: using a shell script to compile your C programs
- Next by thread: Re: using a shell script to compile your C programs
- Index(es):
Relevant Pages
|