LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 01-18-2007, 02:08 PM   #1
markelo
Member
 
Registered: Mar 2004
Distribution: Red hat 9 -> 64bit fedora
Posts: 190

Rep: Reputation: 30
Is this makefile rule possible?


Here is the makefile. Is it possible to write a rule which
first search every file in same directory and then compile
and link those files which end with .cpp extension.

Requirement is that it have to pass linking rule which is in
makefile ( ie. execute @echo command during linking phase )

Dummy rule can be erased if it is required to make it work.

This is just an artificial test and there is no real world
requirements to make this work. I am just curious how to do it if
it is possible.

One last requirement. Have to be possible by single make command.
I get a working version for two make commands already.

Code:
CXXFLAGS= -ansi -Wall -pedantic

SRCS=$(wildcard *.cpp )
BINARIES=$(basename $(SRCS))
OBJS=$(subst .cpp,.o,$(SRCS)) 

all: $(BINARIES) $(OBJS)

%.o: %.cpp
	@echo binaries are $(BINARIES) and objects are $(OBJS)
	@echo mycompile $(CXX) -c $< $(CXXFLAGS)
	$(CXX) -c $< $(CXXFLAGS)

%:%.o
	@echo mylinking $(CXX) $< -o $@ $(LIBS)
	$(CXX) $< -o $@ $(LIBS)

%:
	@echo dummy rule

clean:
	rm -f *.o $(BINARIES) *~ stdout.txt stderr.txt
Thank you from your time. Happy head scratching
 
Old 01-31-2007, 08:26 AM   #2
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
I do it like this:

Code:
#       ---------------------------------
#       Standard makefile for standalone
#       C files (not multifile projects)
#
#       using the built-in rules for simple single source programs
#
#       you need 'makedepend' for this to work
#
#       the 'include' call cannot find the include files
#       so it becomes a *target*, and gets made first.
#       Must be deleted at the end to work next time around
#       ---------------------------------------------------

DEPENDFILE=depend.mk
TARGETS=$(CFILES:.c=)

all:do_it
        @rm $(DEPENDFILE)

# include must come after the first target

-include $(DEPENDFILE)

# TARGETS must come after the include

do_it:${TARGETS}

$(DEPENDFILE):
        @touch $@
        @echo CFILES = *.c > $@
        @makedepend -f $@ *.c
 
  


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
What is wrong with this simple rule in makefile? George2 Programming 6 05-03-2006 01:53 AM
Rule.mk and make.mk for makefile evenglist2005 Programming 1 09-21-2005 03:39 AM
how to get (makefile -f makefile )output into the textview widget in Pygtk sailu_mvn Programming 3 02-28-2005 03:57 AM
generate Makefile from Makefile.in without calling ./configure ? chris78 Programming 2 05-02-2004 12:23 PM
No rule to make target `/mkspecs/default/qmake.conf', needed by `Makefile'. Stop Julianus Linux - General 0 12-21-2003 07:17 AM

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

All times are GMT -5. The time now is 05:41 AM.

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