makefile editor/wizard
Is there makefile editor or wizard available?
Like simple application to select source & include files, libraries and so on that then generates proper makefile.
I don''t mean KDevelop or VisualC like IDE''s just simle makefile generator would bew fine.
I have made a commented makefile which can rather easily be reused. I can post it if you want.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
quote: Original post by Fruny
I have made a commented makefile which can rather easily be reused. I can post it if you want.
I''d be glad if you post it, since makefiles are always a little mysterious.
I''v copy/pasted parts from other makefiles (like from nehe-tutorials) but how to keep it simple with multiple files and libraries is a little problem.
But I just wanted to be lazy and thoght if there is a program that can generate makefile (no, I don''t mean text-editor :p).
You might want to look in to Automake (of course, it may end up being more trouble than it''s worth for you ).
You should take the time to learn about make since it is very powerful, but also becoming a lost art thanks to IDEs.
heres the makefile from one of my projects.
$@ is the name of the current target, and $< is the current dependancy. This way all .o files get compiled without having to specify their .cpp counterpart.
On one project I was working on, there was an awk script that generated a .cpp file that was then linked in. Pretty cool!
University is a fountain of knowledge, and students go there to drink.
heres the makefile from one of my projects.
#makefileCC=g++INCLUDE=-I/usr/src/SDL/SDL-1.2.3/includeLIBS=-lGL -lGLU -lSDL%.o : %.cpp $(CC) $(INCLUDE) -c -o $@ $< gltest : test.o windowman.o error.o $(CC) -o $@ $(LIBS) $(INCLUDE) $^ clean : rm *.oall : gltest clean
$@ is the name of the current target, and $< is the current dependancy. This way all .o files get compiled without having to specify their .cpp counterpart.
On one project I was working on, there was an awk script that generated a .cpp file that was then linked in. Pretty cool!
University is a fountain of knowledge, and students go there to drink.
Sorry for the dump, but source tags destroy the structure.
Edit: HTML ate my TABs
[edited by - Fruny on April 8, 2002 12:23:14 PM]
## Generic Makefile (c) 1999-2002 Yannick Loitiere## #include <disclaimer>## This makefile make HEAVY use of the GNU make (gmake)# default rules. It works on my machine, but I am not# responsible if it doesn't on yours. Use at your own# risk.## Makefile notes### Obviously, a line beginning with # is a comment## A variable declared by 'VAR = var' is referenced by $(VAR)# Variable declarations must be on a single line... # use '\' before the carriage return to make a continuation.# A make rule MUST begin with a , not spaces.## Note that any variable not explicitely defined in the# makefile defaults to the corresponding environment variable. # Usually, on *NIX, CC is already defined and points to the # local compiler. I redefined it, since I wanted to use the GNU # compiler suite under IRIX and SUNOS, where the default compilers # are cc and CC.## Oh, and MAKE points to make, for recursive makefiles...### Target# ------## This is the name of the final executable.# There must be a source (.c or .cc) file with a matching # name.#TARGET = main## Source files# ------------# A .c extension denotes a C file, compiled with $(CC)# A .cc extension denotes a C++ file, compiled with $(CXX)# SRCS = $(wildcard *.cc) $(wildcard *.c)## $(wildcard FOO) expands to all the files matching the shell# expression FOO. In this case, it will be all the .c and .cc# files in the current directory, which will be compiled and# linked into the TARGET executable.### Add here the libraries to link.# TODO: put GLUT & GLUI here.#LDLIBS =## There is another library variable, LOADLIBES, which I use# to declare the 'default' libraries, which must be linked# with all of my programs. By defaule, I link in all of X11,# OpenGL (including GLUT and GLUI) and the Math library.# I use LDLIBS to declare 'extra' libraries.### Headers and Libraries# ---------------------## PATH is the absolute path to the base directory# HDRS is header path directive (-I)# LIBPATH is the library path directive (-L)# LIBS is the actual library include directive (-l)## XWindowX11_PATH = /usr/X11R6X11_HDRS = -I$(X11_PATH)/includeX11_LIBPATH = -L$(X11_PATH)/libX11_LIBS = $(X11_LIBPATH) -lXi -lX11 -lXmu -lXext -lXt# OpenGL# GFXOSTYPE is an environment variable set by my login script# which detects which OS I'm running on, and thus which# directory holds the GL libraries I must link with.GL_PATH = /home/gfxGL_HDRS = -I$(GL_PATH)/includeGL_LIBPATH = -L$(GL_PATH)/lib -L$(GL_PATH)/lib/$(GFXOSTYPE)GL_LIBS = $(GL_LIBPATH) -lglui -lglut -lGL -lGLU## Putting it all together, these are the variables that will# be used in the compiler and linker options.#GFX_HDRS = $(GL_HDRS) $(X11_HDRS)GFX_LIBS = $(GL_LIBS) $(X11_LIBS)## Optimizations# -------------GENERIC_OPT = -O3MIPS_OPT = $(GENERIC_OPT) -INLINE:=ON:all:dfe=ON: -mips4 \ -IPA:alias=ON:addressing=ON:aggr_cprop=ON:cgi=ON \ -LNO:auto_dist=ON:non_blocking_loads=ON:gather_scatter=2:ou_further=3:pf1=ON:pf2=ON:pf3=ON:pf4=ONSPARC_OPT = $(GENERIC_OPT)X86_OPT = $(GENERIC_OPT)## Optimization flags, select which of the above to use# I could have adder a machine-detection macro, like# GFXOSTYPE, but that's not worth it, because I only# need 'full' optimization when running on a SGI, which# has special graphics hardware and stuff.#OPT = $(GENERIC_OPT)## Debug options# -------------## Now, gcc is nice enough to let optimizations (-O)# work with debugging (-g), but that's not necessarily# ideal. When not debuggin, use the full optimizations,# and also define (-D) NDEBUG, which disable assertions#DEBUG = -g -O3NDEBUG = $(OPT) -DNDEBUG## Compiler selection and options# ------------------------------## CC = C compiler# CXX = C++ compiler# CPPFLAGS = C preprocessor flags## Here I cheat a bit. Technically, the flags for C/C++# should be put in CFLAGS and CXXFLAGS respectively,# but since both use the preprocessor, the default rule# includes CPPFLAGS for both. So I can get away with# putting my command line options there. Note though# that other compilers (e.g. Fortran) also use the# preprocessor (and thus refer to CPPFLAGS), but since# I am not using Fortran, I'm safe.#CC = gccCXX = g++CPPFLAGS = $(GFX_HDRS) $(DEBUG)## Linker options & libraries# --------------------------## LDFLAGS is meant to pass options to the linker.# You can get away with passing the same optimizations # options, since the linker is called through $(CC). It # doesn't care about headers though.# LOADLIBES is another set of libraries, just like LDLIBS.# I don't quite know the rationale behind having two# separate sets of library flags, so I use them to hold # 'system-wide' libraries and 'project-wide' libraries.#LDFLAGS = $(DEBUG)LOADLIBES = -lm $(GFX_LIBS)# Suffix rules# ------------## This is the important stuff. This is where you tell gmake# which rules it must use to build the project. Usually,# people just throw in whatever individual rule they want to# use, but I decided (since I was in a 'makefile learning'# phase) to use the implicit rules for gmake.#.SUFFIXES:.SUFFIXES: .o .cc .c## So, what is done here, is declare the type of files we are# going to process. .c files are C source, .cc are C++ source,# and .o files are object files (like .obj in windows, files# which have been compiled, but not linked). The first .SUFFIXES# directive first removes all predefined rules, then I add the# rules for C, C++ and object files only. This is why I'm safe# from Fortran's use of the C preprocessor, if I use this makefile# on a Fortran project, nothing will happen: it will fail at the# makefile level, and not try to include the default C header# files I have referenced (GL,X11...) into the Fortran sources.## The implicit rules used translate as## foo.c -> foo.o using $(CC) -c $(CPPFLAGS) $(CFLAGS)# foo.cc -> foo.o using $(CXX) -c $(CPPFLAGS) $(CXXFLAGS)# foo.o -> foo using $(CC) $(LDFLAGS) foo.o $(LOADLIBES) $(LDLIBS)# and according to the documentation, does# 'the right thing' for multiple object file# so long as one of them matches the target.### Build the target # ----------------## Ok, I lied, there is a rule I defined. Unless you pass an option # to make (like 'make clean', see below), gmake will execute the# first rule it encounters in the makefile. So here, I put the# rule wich will build the target.#$(TARGET): $(patsubst %.c,%.o,$(filter %.c,$(SRCS))) $(patsubst %.cc,%.o,$(filter %.cc,$(SRCS)))## The syntax of a rule is :## TargetFile: Dependencies (on a single line)# Command1# Command2# ...## Which means that, if any file in 'Dependencies' changed, then# make needs to regenerate 'TargetFile' by calling 'Command1',# 'Command2' ...## The weird $(...) variables above are commands specific to gmake.## $(filter %.c,$(SRCS)) expands to 'all tokens in SRCS ending in .c'# $(patsubst %.c,%.o,($FOO)) does a pattern substitution of .c into# .o for all tokens in FOO.## So that means "The dependencies of TARGET are the .o files# corresponding to the .cc and .c files in SRCS". Or, more clearly,# the object files generated from the source files.## gmake tests whether a file needs to be rebuilt by comparing its # modification time to that of its dependencies.# The 'Command' lines must begin with a tab, that's how gmake# figures out when to stop looking for commands.## You could have written :## target : file1.o file2.o file3.o ### Commands# --------## This declares commands that you can pass on the command line when# calling make. In this case, I only declare 'make clean'.#.PHONY: clean## .PHONY tells make that 'clean' isn't a real target, that it# should not try to build a file by that name, that it is just# only there to be passed on the command line.#clean: -rm -rf *.o *.d core a.out \#* *~ *.bak *.save $(TARGET) ii_files## See, a rule for clean. It doesn't have any dependencies, and# calls rm to do some cleanup. Specifically, it removes all object# files (.o), all dependency files (.d see below), any core dump,# temp files (#*, *~, *.bak, *.save), executable (TARGET, a.out),# and template instanciations (ii_files directory).## The - before rm tells make not to print out the command (like @# in DOS batch files)### Dependencies# ------------## Here is some Unix magic that I ripped off the gmake manual.# Whenever a .c or .cc file is modified, it generates a .d file# by running it through the preprocessor looking for dependencies# (-M option). That is, include files and the like. Then it passes# the result to sed (stream editor), which does some on-the-fly# replacement, putting the dependencies into the correct make# rule format.## Finally, the last command in the makefile actually includes# all those dependencies into the makefile, so that gmake takes# them into account when building your project.## You would add dependencies manually by writing a series of :## file1.o : file1.cc header1.h header2.h header3.h# file2.o : file2.cc header1.h header4.h header5.h# file3.o : file3.cc header1.h header4.h header6.h# ...%.d: %.cc set -e; $(CXX) -M $(GFX_HDRS) $(CPPFLAGS) $< | sed 's/\($*\)\.o[ :]*/\1.o $@ : /g' > $@; [ -s $@ ] || rm -f $@%.d: %.c set -e; $(CC) -M $(GFX_HDRS) $(CPPFLAGS) $< | sed 's/\($*\)\.o[ :]*/\1.o $@ : /g' > $@; [ -s $@ ] || rm -f $@include $(patsubst %.c,%.d,$(filter %.c,$(SRCS))) $(patsubst %.cc,%.d,$(filter %.cc,$(SRCS)))
Edit: HTML ate my TABs
[edited by - Fruny on April 8, 2002 12:23:14 PM]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Ok, thanks verry much for everybody
Now I don''t need to add two lines for each source file Great.
Why dows the difference mean? The first links but the second doesnt link.
$(CC) $(INCLUDE) $^ -o $@ $(LIBS)
$(CC) $(INCLUDE) $(LIBS) $^ -o $@
I actually fought for a while ''how come it doesn''t link''. Then I just chaned the order like above and it worked.
$@, @^, @< and @? I didn''t know before. They help much!
Now I don''t need to add two lines for each source file Great.
Why dows the difference mean? The first links but the second doesnt link.
$(CC) $(INCLUDE) $^ -o $@ $(LIBS)
$(CC) $(INCLUDE) $(LIBS) $^ -o $@
I actually fought for a while ''how come it doesn''t link''. Then I just chaned the order like above and it worked.
$@, @^, @< and @? I didn''t know before. They help much!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement