LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-06-2006, 09:40 AM   #1
Thinking
Member
 
Registered: Oct 2003
Posts: 249

Rep: Reputation: 30
how does make know that 'nothing to be done for \'all\''


hiho@ll

i'm just wondering how the program "make" knows when the files have changed and recompilation is needed?

the background of this question is, that i have wrote my own makefile
and from other makefiles (other projects) i know the message "nothing to be done for ..."
but my makefile recompiles everything everytime i call it

what i want:
>make all
# some compilation stuff
>make all
nothing to be done for all

what i get:
>make all
# some compilation stuff
>make all
# some compilation stuff

the makefile looks like this:
Code:
OWNER=username
GROUP=groupname
CFLAGS= -g -g3 -ggdb -ggdb3 -O4 -ldl -rdynamic -Wl,-export-dynamic -Wall
CLIBFLAGS= -g -g3 -ggdb -ggdb3 -O4 -fPIC -Wall -Wl,-export-dynamic -shared
CCOMP= -g -g3 -ggdb -ggdb3 -O4 -Wall -fPIC
SRCS=utils/classone.cpp utils/classtwo.cpp daemon.cpp server.cpp
OBJS=utils/classone.o utils/classtwo.o daemon.o server.o
INCLUDES= -Iutils
CC=g++
BINDIR=/usr/local/project

all: objects partone parttwo

objects:
    $(CC) $(CCOMP) $(INCLUDES) -c utils/classone.cpp -o utils/classone.o
    $(CC) $(CCOMP) $(INCLUDES) -c utils/classtwo.cpp -o utils/classtwo.o
    $(CC) $(CCOMP) $(INCLUDES) -c daemon.cpp -o daemon.o
    $(CC) $(CCOMP) $(INCLUDES) -c server.cpp -o server.o

partone:
    $(CC) $(CFLAGS) $(INCLUDES) $(OBJS) daemon.o -o daemon

parttwo:
    $(CC) $(CLIBFLAGS) $(INCLUDES) $(OBJS) server.o -lpthread -o libserver.so.0
 
Old 07-06-2006, 10:14 AM   #2
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
Quote:
but my makefile recompiles everything everytime i call it
because that's what you are specifying

firstly, you don't need to specify the CC behaviour, it's built in.
Also your targets have no dependencies.

start with this, see how simple it can be:

Code:
all:daemon server

daemon: daemon.o

server:server.o
you don't need to redifine CC stuff, there are anough flags
for you to use, eg: $(CFLAGS) $(CPPFLAGS) $(LDFLAGS)

make -pns and grep CC
 
Old 07-06-2006, 10:51 AM   #3
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
Simple changes that will fix the dependencies:
Code:
GROUP=groupname
CFLAGS= -g -g3 -ggdb -ggdb3 -O4 -ldl -rdynamic -Wl,-export-dynamic -Wall
CLIBFLAGS= -g -g3 -ggdb -ggdb3 -O4 -fPIC -Wall -Wl,-export-dynamic -shared
CCOMP= -g -g3 -ggdb -ggdb3 -O4 -Wall -fPIC

%.o:    %.cpp
        $(CC) $(CCOMP) $(INCLUDES) -c -o $@ $<


OBJS=utils/classone.o utils/classtwo.o daemon.o server.o

INCLUDES= -Iutils
CC=g++
BINDIR=/usr/local/project

#all:   objects partone parttwo

objects:        $(OBJS)
#objects:
#       $(CC) $(CCOMP) $(INCLUDES) -c utils/classone.cpp -o utils/classone.o
#       $(CC) $(CCOMP) $(INCLUDES) -c utils/classtwo.cpp -o utils/classtwo.o
#       $(CC) $(CCOMP) $(INCLUDES) -c daemon.cpp -o daemon.o
#       $(CC) $(CCOMP) $(INCLUDES) -c server.cpp -o server.o

partone:
        $(CC) $(CFLAGS) $(INCLUDES) $(OBJS) daemon.o -o daemon

parttwo:
        $(CC) $(CLIBFLAGS) $(INCLUDES) $(OBJS) server.o -lpthread -o libserver.so.0
The partone and parttwo are somewhat incorrect. You're specifing the $(OBJS) and the server.o or daemon.o which are included in the OBJS target.

Other changes I'd make to the makefile is creating a seperate makefile for the subdirectory and put the results in a static library. I'd also remove the server.o and daemon.o from the OBJS list. Perhaps you need a DAEMON_OBJ and SERVER_OBJ list of sorts.

Last edited by crabboy; 07-06-2006 at 10:54 AM.
 
Old 07-06-2006, 11:35 AM   #4
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
...and since I don't feel like working:

utils/Makefile:
Code:
OWNER=username
GROUP=groupname
AR=ar

CC=g++
CCOMP= -g -g3 -ggdb -ggdb3 -O4 -Wall -fPIC

LIB= ../libutils.a

%.o:    %.cpp
        $(CC) $(CCOMP) $(INCLUDES) -c -o $@ $<


OBJS=classone.o classtwo.o

all:    $(LIB)

objects:        $(OBJS)

$(LIB): objects  $(OBJS)
        $(AR) rcs $@ $(OBJS)

clean:
        rm -f $(OBJS) $(LIB)
Base Makefile:
Code:
OWNER=username
GROUP=groupname
CFLAGS= -g -g3 -ggdb -ggdb3 -O4 -ldl -rdynamic -Wl,-export-dynamic -Wall
CLIBFLAGS= -g -g3 -ggdb -ggdb3 -O4 -fPIC -Wall -Wl,-export-dynamic -shared
CCOMP= -g -g3 -ggdb -ggdb3 -O4 -Wall -fPIC

%.o:    %.cpp
        $(CC) $(CCOMP) $(INCLUDES) -c -o $@ $<

.PHONY: dummy

DAEMON_OBJ=daemon.o
SERVER_OBJ=server.o

LIBDIR=.
INCLUDES= -Iutils
LIBS=utils

SHARED=libserver.so.0

CC=g++
BINDIR=/usr/local/project

all:    $(LIBS) daemon shared

$(LIBS):        dummy
        $(MAKE) -C $(LIBS)

daemon: $(DAEMON_OBJ) $(LIBS)
        $(CC) $(CFLAGS) $(INCLUDES) $(DAEMON_OBJ) -L$(LIBDIR) -o $@  -l$(LIBS)

shared:         $(SHARED)

$(SHARED):      $(SERVER_OBJ) $(LIBS)
        $(CC) $(CLIBFLAGS) $(INCLUDES) -L(LIBLIST) $(SERVER_OBJ) -o $@ -lpthread -l$(LIBS)

clean:  dummy
        rm -f *.a $(DAEMON_OBJ) $(SERVER_OBJ)
        $(MAKE) -C $(LIBS) clean
A few more simple changes need to be made to either make it work for a few directories or a tree of sub-directories.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Make Trouble linking some fortran code Make file problem? any ideas? TheBrick Linux - General 0 05-17-2006 11:21 AM
package compiling from source, make & make install concepts shujja Linux - Newbie 2 09-20-2005 12:18 AM
I accidentally deleted make file in /usr/local/bin, now cannot use make command.... Niceman2005 Linux - Software 2 11-17-2004 07:55 PM
How to make rule for make install and make uninstall melinda_sayang Programming 1 06-14-2004 05:58 AM
make dep,make clean,make bzImage problem Babba Linux - Newbie 2 01-08-2003 03:49 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:06 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration