www.digitalmars.com         C & C++   DMDScript  

c++ - Simple Make File

reply Ronald Weidner <xecronix yahoo.com> writes:



CC=c:\dm\bin\dmc.exe
SRC=Inheritence.cpp
CFLAGS=
LINK=
INCLUDE=-I\dm\stlport\stlport
EXE=Inheritence.exe
RM=del

OBJS=$(SRC:.cpp=.obj)
MAPS=$(SRC:.cpp=.map)

all:${OBJS}
	${CC} ${OBJS} ${LINK} -o ${EXE}

%.obj: %.cpp
	${CC} ${INCLUDE} ${CFLAGS} -c $*.cpp -o $*.obj

clean:
	- ${RM} ${EXE}
	- ${RM} ${OBJS}
	- ${RM} ${MAPS}

tidy: all
	- ${RM} ${OBJS}
	- ${RM} ${MAPS}

rebuild: clean all


Dec 16 2008
parent reply Cesar Rabak <crabak acm.org> writes:
Ronald Weidner escreveu:


I would require modification of more lines if: DM is not installed in C:\DM if you invoke the make from a drive diferent than C: since your macro for include does not have the drive letter...
 
 CC=c:\dm\bin\dmc.exe
 SRC=Inheritence.cpp
 CFLAGS=
 LINK=
 INCLUDE=-I\dm\stlport\stlport
 EXE=Inheritence.exe
 RM=del
 
 OBJS=$(SRC:.cpp=.obj)
 MAPS=$(SRC:.cpp=.map)
Your makefile only considers C++ files.
 
 all:${OBJS}
 	${CC} ${OBJS} ${LINK} -o ${EXE}
 
 %.obj: %.cpp
 	${CC} ${INCLUDE} ${CFLAGS} -c $*.cpp -o $*.obj
 
 clean:
 	- ${RM} ${EXE}
 	- ${RM} ${OBJS}
 	- ${RM} ${MAPS}
 
 tidy: all
 	- ${RM} ${OBJS}
 	- ${RM} ${MAPS}
A call to make tidy will first call building of the target, is this what you intent?
 
 rebuild: clean all
Make takes care of only compiling and linking if necessary if sources are newer that object files, then why do you created a 'rebuild' that cleans all objects?
 

Dec 16 2008
parent reply Ronald Weidner <xecronix yahoo.com> writes:
== Quote from Cesar Rabak (crabak acm.org)'s article
 Ronald Weidner escreveu:


I would require modification of more lines if: DM is not installed in C:\DM if you invoke the make from a drive diferent than C: since your macro for include does not have the drive letter...
That's correct. If someone wanted to use this make file, they would need to "fix" it to match their project and system configuration. I wrote this to be a "light touch" makefile where this makefile could be copied, slightly edited, and used again for many C++ projects. I could probably make this even more generic with even less need to edit. The trade off is that the makefile may become more complicated/cryptic and harder to extend. It's my anticipation that this simple make file will be sufficient for 80% of my utilities and tests. I'll only need to modify SRC for each project. (since my last post I added a line for Defines). Additional modification would be needed for more complicated source trees such as multi-language projects, dll/lib creation, etc. Perhaps I should call this makefile a nice starting point. Currently I maintain several complex systems for the company I work for. The code base spans 15 years of development by scores of programmers. I've recently revamped all the makefiles for my company to something that isn't much more complicated than this make file.
 CC=c:\dm\bin\dmc.exe
 SRC=Inheritence.cpp
 CFLAGS=
 LINK=
 INCLUDE=-I\dm\stlport\stlport
 EXE=Inheritence.exe
 RM=del

 ...

 tidy: all
 	- ${RM} ${OBJS}
 	- ${RM} ${MAPS}
A call to make tidy will first call building of the target, is this what you intent?
Yes, this was the intent. I wanted a one shot call to make to build the exe and clean up files that aren't needed anymore. If I use make tidy it's probably because I'm going to zip up the folder and send it somewhere when build is complete.
 rebuild: clean all
Make takes care of only compiling and linking if necessary if sources are newer that object files, then why do you created a 'rebuild' that cleans all objects?
This is now more out of habit and perhaps paranoia. When I want to be absolutely certain that my exe is the most up to date I run rebuild. Basically, the fear is that some external force (such as a version control system) may mess up make's ability to build correctly. By deleting all obj files make is free from potentially making a bad decision. It will rebuild everything. (Brute force approach) I always rebuild before I bundle a release.

Dec 16 2008
parent reply Ronald Weidner <xecronix yahoo.com> writes:
I know this thread is a little long in the tooth now but I was wondering if any
one else has a makefile to share?  Something simple and written with the intent
of
being reusable in different projects.

--
Ronald Weidner
http://www.techport80.com
Jan 17 2012
parent "osbornedental" <harry.david32 gmail.com> writes:
On Wednesday, 18 January 2012 at 03:09:19 UTC, Ronald Weidner
wrote:
 I know this thread is a little long in the tooth now but I was 
 wondering if any
 one else has a makefile to share?  Something simple and written 
 with the intent of
 being reusable in different projects.

 --
 Ronald Weidner
 http://www.techport80.com
Yes agree with you dear.. its really littly long..
Aug 03 2012