Re: how do you add to the makefile

From: Yura Ushakhow (
Date: 05/05/02

Ken Kreb wrote:
> Ok how do you add a new .c file to your makefile?
> ea;  what all has to be done to make it work?
You add to
OBJFILES = ... newfile.o

Then you add a ``newfile.o'' definition in the end of the file,--
newfile.o: newfile.h newfile.c
  $(CC) -c $(CFLAGS) newfile.c

It is the simpliest way.  The way I'd prefer is adding new modules to
the Makefile via ``gcc -MM''. I wrote a little script to generate the
OBJFILES and the definitions sections... It is on your head to understand
what's for what further. :)

rm -f ${out}

echo -n "OBJFILES =" >>${out}
for file in *.c; do
        filealt="`echo ${file}|sed -e \"s/^\(.*\)\.c$/\1/\"`"
        echo -n " ${filealt}.o" >>${out}
echo >>${out}
echo >>${out}

for file in *.c; do
        gcc -MM ${file} >>${out}
        printf "\t\$(CC) -c \$(CFLAGS) ${file}\n" >>${out}

> and what does the makefile do?
> thanks for your time.
It checks if you have such and such files or if they were modified
since last compilation and to those which looks updated/new it will
execute a particular command you tell it to do... In other words,
like most other programmes, it does exactly what you tell it to do. :)

Yura Ushakhow <>
Moscow, Russia

   | FAQ: |
   | Archives: |
   | Newbie List:   |

This archive was generated by hypermail 2b30 : 06/25/03 PDT