c - Creating a make file -


i know there infinite amount of resources on internet regards makefiles, still not understand it. @ moment have 3 c files polycalculatormain.c polycalculator.c polycalculator.h , polyfunctions.c

so far have

polycalculator: polycalculator.o polycalculatormain.c     gcc -wall -ggdb -o polycalculator polycalculatormain.c polycalculator.o  polycalculator.o:   polycalculator.c      gcc -wall -ggdb -c polycalculator.c polycalculator.h  clean:      rm polycalculator *.o *~ *# 

any or explanation on go complete file appreciated. note im beginning dont want complex code not understand it

in compile command don't specify .h files. included preprocessor (which runs before compiler) encounters #include statements. thing can see.

the .h files show in makefiles dependencies since changes them can require code uses them need recompiled.

i basic rule include on dependency line cause recompile necessary if changed.

polycalculator: polycalculator.o polyfunctions.o polycalculatormain.c     gcc -wall -ggdb -o polycalculator polycalculatormain.c polycalculator.o polyfunctions.o  polycalculator.o:   polycalculator.c polycalculator.h     gcc -wall -ggdb -c polycalculator.c   polyfunctions.o: polyfunctions.c polyfunctions.h     gcc -wall -ggdb -c polyfunctions.c  clean:  rm polycalculator *.o *~ *# 

makefiles allow have variables can reused. example, can have compiler options in variable:

options=-wall -ggdb 

and use them brackets , dollar sign

gcc ${options} 

you can break them up:

debug=-ggdb  warnings=-wall  options=${warnings} ${debug} 

you can combine object files variable:

obj_files=polycalculator.o polyfunctions.o   polycalculator: ${obj_files} polycalculatormain.c     gcc -wall -ggdb -o polycalculator polycalculatormain.c ${obj_files}  polycalculator.o:   polycalculator.c polycalculator.h     gcc -wall -ggdb -c polycalculator.c   polyfunctions.o: polyfunctions.c polyfunctions.h     gcc -wall -ggdb -c polyfunctions.c  clean:      rm polycalculator *.o *~ *# 

Comments

Popular posts from this blog

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -