Tools to make makefiles?

M

milkyway

Hello,

I am running under Suse Linux and am putting together some code written
in C. I am not clear on how to create makefiles and was wondering if
there were any "makefile tools" out there. If so, what are the best
ones?

TIA
 
R

Richard Heathfield

[Followups set to comp.lang.c]

milkyway said:
Hello,

I am running under Suse Linux and am putting together some code written
in C. I am not clear on how to create makefiles and was wondering if
there were any "makefile tools" out there. If so, what are the best
ones?

If you don't want to get into autoconf etc, it's trivial to generate your
own simple makefiles by writing a program in elementary ISO C. Here's a
really, really simple one which you can hack to your heart's content.

#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);
}
printf("\n\t$(CC) $(CFLAGS) $(DFLAGS) -o %s %s.o", argv[1], argv[1]);
for(i = 2; i < argc; i++)
{
printf(" %s.o", argv);
}
putchar('\n');
}

void makeobjs(int argc, char **argv)
{
int i = 0;
for(i = 1; i < argc; i++)
{
printf("%s.o: %s.c\n", argv, argv);
printf("\t$(CC) $(CFLAGS) $(DFLAGS) -c -o %s.o %s.c\n", argv,
argv);
}
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);
}
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;
}
 
S

spike1

milkyway said:
Hello,

I am running under Suse Linux and am putting together some code written
in C. I am not clear on how to create makefiles and was wondering if
there were any "makefile tools" out there. If so, what are the best
ones?

autoconf, automake
:)
should help a bit at least.
--
______________________________________________________________________________
| (e-mail address removed) | |
|Andrew Halliwell BSc(hons)| "The day Microsoft makes something that doesn't |
| in | suck is probably the day they start making |
| Computer science | vacuum cleaners" - Ernst Jan Plugge |
------------------------------------------------------------------------------
 
A

Arne Schmitz

autoconf, automake

Thats quite a big step. Also scons is very nice, and IMHO much easier for
small projects. Alternatively, just use a text editor to write your make
file. With implicit rules, you do not even have to list all your source
files.

Arne
 
A

Alex Fraser

Arne Schmitz said:
Thats quite a big step.
Definitely.

Also scons is very nice, and IMHO much easier for small projects.

Looks interesting. Being written in Python is unfortunate in some respects.
Alternatively, just use a text editor to write your make file. With
implicit rules, you do not even have to list all your source files.

Yes, you only need to list source files which #include any non-system header
files, which is normally all of them if there is more than one source file.

I suspect at least a basic understanding of how you would write a makefile
for a given project would be very useful for most, if not all, "makefile
tools".

Alex
 
G

Grant Edwards

I am running under Suse Linux and am putting together some code written
in C. I am not clear on how to create makefiles

You don't create a makefile. You copy one and modify it.

Somebody once asked who created the first makefile, but there
was no first makefile -- it's just turtles all the way down...
 
D

Dan Espen

milkyway said:
Hello,

I am running under Suse Linux and am putting together some code written
in C. I am not clear on how to create makefiles and was wondering if
there were any "makefile tools" out there. If so, what are the best
ones?

Hmm, looks like some of the answers you've gotten are meant to
be humorous.

autoconf and friends are more complex than make.

I think you question is equivalent to asking for a tool to
write .bat files. Make is pretty simple,
using a tool to write make files is overkill unless you are
dealing with a really large project.

Spend a few minutes over at gnu.org reading the make documentation
or ask specific questions.
 
D

Dave Vandervies

[Followups set to comp.lang.c]

milkyway said:
Hello,

I am running under Suse Linux and am putting together some code written
in C. I am not clear on how to create makefiles and was wondering if
there were any "makefile tools" out there. If so, what are the best
ones?

If you don't want to get into autoconf etc, it's trivial to generate your
own simple makefiles by writing a program in elementary ISO C. Here's a
really, really simple one which you can hack to your heart's content.

printf("\t$(CC) $(CFLAGS) $(DFLAGS) -c -o %s.o %s.c\n", argv,
argv);


Posting a non-strictly-conforming program to comp.lang.c? What have
you done with The Real Richard Heathfield?


dave
(exercise for the reader: What's non-strictly-conforming about the code
I quoted?)
 
W

Wolfgang Riedel

Grant said:
You don't create a makefile. You copy one and modify it.

Somebody once asked who created the first makefile, but there
was no first makefile -- it's just turtles all the way down...

THE original:

%s/make/JCL/g

Wolfgang
 
R

Richard Heathfield

Dave Vandervies said:
Richard Heathfield said:
printf("\t$(CC) $(CFLAGS) $(DFLAGS) -c -o %s.o %s.c\n", argv,
argv);


Posting a non-strictly-conforming program to comp.lang.c? What have
you done with The Real Richard Heathfield?


Er, eek.
(exercise for the reader: What's non-strictly-conforming about the code
I quoted?)

I hear ya. Sorry, Dave - I was in helpful mode instead of picky guy mode.
I'll try not to let it happen again. :)
 
M

Mike Wahler

Dave Vandervies said:
printf("\t$(CC) $(CFLAGS) $(DFLAGS) -c -o %s.o %s.c\n", argv,
argv);


Posting a non-strictly-conforming program to comp.lang.c? What have
you done with The Real Richard Heathfield?


dave
(exercise for the reader: What's non-strictly-conforming about the code
I quoted?)


I don't have my copy of standard handy, so this is just a guess:
No '$' character guaranteed in execution character set?

-Mike
 
D

Dave Vandervies

Dave Vandervies said:

I hear ya. Sorry, Dave - I was in helpful mode instead of picky guy mode.
I'll try not to let it happen again. :)

It's the "instead of" that I'm worried about. Who says you can't do both?


dave
(helpful is good, nitpicky is better, helpful AND nitpicky is best of all.
Unless it's homework questions.)
 
M

Malcolm

milkyway said:
I am running under Suse Linux and am putting together some code written
in C. I am not clear on how to create makefiles and was wondering if
there were any "makefile tools" out there. If so, what are the best
ones?
make is already a tool to make programs.
Once you need a tool to make a makefile, you've reached the end of make's
usefulness, and it's time to look for something else.
 
K

Keith Thompson

Malcolm said:
make is already a tool to make programs.
Once you need a tool to make a makefile, you've reached the end of make's
usefulness, and it's time to look for something else.

Actually, tools that generate Makefiles are fairly common.
 
M

Malcolm

Keith Thompson said:
Actually, tools that generate Makefiles are fairly common.
And you need the horrible things to make emacs debug / error edit properly.

I'm a gcc *.c man myself.
 
S

Simon Biber

Emmanuel said:
Dave Vandervies a écrit :
printf("\t$(CC) $(CFLAGS) $(DFLAGS) -c -o %s.o %s.c\n", argv,
argv);


(exercise for the reader: What's non-strictly-conforming about the code
I quoted?)



Too easy. '$' is not part of the standard charset.


4#5 "A strictly conforming program shall use only those features of the
language and library specified in this International Standard. It shall
not produce output dependent on any unspecified, undefined, or
implementation-defined behavior, and shall not exceed any minimum
implementation limit.

5.2.1#1 "The values of the members of the execution character set are
implementation-defined."

6.4.5#5"The value of a string literal containing a multibyte character
or escape sequence not represented in the execution character set is
implementation-defined."

What if we use universal character names?

printf("\t\u0024(CC) \u0024(CFLAGS) \u0024(DFLAGS) -c -o %s.o %s.c\n",
argv, argv);

Unfortunately, it is still implementation-defined whether \u0024 is a
member of the execution character set, so this program cannot be
considered strictly conforming.
 
K

Keith Thompson

Emmanuel Delahaye said:
Dave Vandervies a écrit :
printf("\t$(CC) $(CFLAGS) $(DFLAGS) -c -o %s.o %s.c\n", argv,
argv);

(exercise for the reader: What's non-strictly-conforming about the code
I quoted?)

Too easy. '$' is not part of the standard charset.


Of course, we've never had a rule against posting
non-strictly-conforming code here. If we did, we couldn't post

#include <stdio.h>
int main(void)
{
printf("sizeof(int) = %d\n", (int)sizeof(int));
return 0;
}

(Yeah, I know, I'm spoiling the joke.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,527
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top