looking for an automated way of creating makefiles

Asked by Gary Kline on 2011-04-10

Is there anything like the mkmf utility in the BSD would for Ubuntu? I'm working on a project that uses the curses library and can't figure out where to put the sting "-lcurses" in the makefile that mkmf builds. Yes, this is fairly trivial, but important since I am constantly rebuilding things.

thanks in advance.

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu ncurses Edit question
Assignee:
No assignee Edit question
Solved by:
Gary Kline
Solved:
2011-04-10
Last query:
2011-04-10
Last reply:
2011-04-10
mycae (mycae) said : #1

mkmf should work for ubuntu too.. I see no reason why it would be *nix specific.

If you post your exact mkmf output, you might see something like this

 $(LD) $(OBJ) -o a.out $(LDFLAGS)

You probably want to set the variable LDFLAGS to -lcurses

you can do this by putting the following somwhere near the top (try above the SRC= line)

LDFLAGS=-lcurses

There is not magic tool for doing this automatically, AFAIK, you usually have to specify what libs you want to link against explicitly.

However there are *many* makefiles writing programs out there; but I generally find you need a largish project (Rough rule of thumb : > 15k lines) before it becomes more of a pain to just write the inputs for the auto-writer than it is to just write the makefile.

You may wish to look at (in no particular order; I use Autotools, but none of the tools i find "great").

* CMake
* Autotools
* Scons

As an aside, one does wonder why you are writing many makefiles -- you should be writing one per project, or just copy the makefile from an old project and hack it a little to fit the new.

The above tools are really just tools for automatically writing makefiles, but sometimes working with them is harder than just working with the makefile directly; and the payoff only comes from their greater robustness to differently configured systems. This is usually only a concern if you are shipping your code in an open source fashion, or if you are working in a heterogeneous programming environment.

Gary Kline (kline) said : #2

I tried exactly what you suggested; got some strange output and the ./a.out failed to exec. The user-side deamon I'm working on now requires only one makefile. But since I left my FreeBSD just-be and act as my server and am using Ubuntu [10.10] for hacking <whatever>, I keep running into problems that I didn't expect.

I'll play around with the Ubuntu mkmf and look more closely, thanks ....

gary kline

PS: I've got a question about "/dev/dsp", but I'll open a new request.

mycae (mycae) said : #3

Well, if you post your exact makefile, we might be able to troubleshoot it. Feel free to reopen this question.

Gary Kline (kline) said : #4

.DEFAULT:
    -touch $@
all: a.out
tt5.o: ./tt5.c
    $(CC) $(CPPDEFS) $(CPPFLAGS) $(CFLAGS) $(OTHERFLAGS) -c ./tt5.c
SRC = ./tt5.c
OBJ = tt5.o
clean: neat
    -rm -f .cppdefs $(OBJ) a.out
neat:
    -rm -f $(TMPFILES)
TAGS: $(SRC)
    etags $(SRC)
tags: $(SRC)
    ctags $(SRC)
a.out: $(OBJ)
    $(LD) $(OBJ) -o a.out $(LDFLAGS) -lcurses

Note that while this does build, there are a slew of warnings and the a.out will not exec. However if I type

% gcc tt5.c -lcurses on the cmd line (there are errors,fewer), and the binary does run. It just reads chars from stdin and outputs same until I end with a ^C

I'd be happy to email both the tt5.c and the makefile if anybody want to dig deeper. O/wise, I'll join the curses stuff with my daemon code.

mycae (mycae) said : #5

changing

$(LD) $(OBJ) -o a.out $(LDFLAGS) -lcurses

to

gcc $(OBJ) -o a.out $(LDFLAGS) -lncurses

gives me a working binary.. Trying to use LD directly gives me the wrong entry point.