From: Franco B. <fra...@we...> - 2002-04-29 14:24:03
|
"Robert Landle" <rl...@gd...> schrieb am 29.04.02: > Hi. > Below is a copy of a simple makefile which takes advantage of an > implicit rule. > file1.cpp is dependent on file2.h which lies in the "C:/anotherdir" > directory. > > Makefile > ------------------------------------------- > OBJS = file1.o file2.o > > INCDIR = C:/anotherdir/ > > program: $(OBJS) > g++ $(OBJS) -o program > > file1.o: > > file2.o: > g++ -c file2.cpp -I$(INCDIR) > --------------------------------------------- > > When I compile my program the first time everything works fine. > If I make a change to file1.cpp save and retype make, the compiler knows > that file1.cpp is out of date so it recompiles it, then relinks the > program with the unchanged file2.o. GREAT! > If I make a change to file2.cpp and retype make, file2.cpp does NOT get > recompiled and the only thing that happens is a new version of program > gets linked, with the old file2.o. :( > > What am I doing wrong ? Can I take advantage of an implicit rule, even Just tell make that file2.o depends on file2.cpp : file2.o: file2.cpp g++ -c file2.cpp -I$(INCDIR) Ciao, Franco ________________________________________________________________ Keine verlorenen Lotto-Quittungen, keine vergessenen Gewinne mehr! Beim WEB.DE Lottoservice: http://tippen2.web.de/?x=13 |
From: FMGCFMGC <FMG...@te...> - 2002-04-30 20:02:29
|
=22Robert Landle=22 =3Crlandle=40gdrs=2Ecom=3E wrote=3A =3E Hi=2E =3E Below is a copy of a simple makefile which takes advantage of an =3E implicit rule=2E =3E =2E=2E=2E =2E=2E=2E =2E=2E=2E Hello everybody! Here you have another Makefile example=2E It also responds a recent = question about CRCs=2E ----- Makefile -------------------------------------------------------- EXEEXT=3D=2Eexe =23 phony targets are targets that are not names of files you want to =23 create with make=2E If on the current exists a file with name =60clea= n=27=2C =23 when you do=3A =23 =3E make clean =23 make says =22make=3A =60clean=27 is up to date=22=2E If you put this = line=2C you =23 inform make to always execute this rule=2E =2EPHONY =3D clean LIBS=3D-lz=2Edll -lcomdlg32 CC=3Dgcc CCFLAGS=3D-Wall -I=2E=2E/=2E=2E/include -L =2E=2E/=2E=2E/lib TARGET=3Dcrc32=24(EXEEXT) =23 Reducing the number of keystrokes with =22Automatic Variables=22 =23 (make-3=2E79 manual=2C section 10=2E5=2E3)=2E =23 =23 target=3A list-of-prerequisites =23 = =23 =24=40 --- is the name of the target=2C i=2Ee=2C crc32=24(EXEEXT) =23 =24=3C --- is the name of the first prerequisite=2E In this example c= rc32=2Ec =23 =24=5E --- is the list of all prerequisites=2E Also=2C crc32=2Ec =23 =23 Another useful automatic variable =23 =24=3F --- list of prerequisites newer than the target=2E =24(TARGET)=3A crc32=2Ec =24(CC) =24(CCFLAGS) -o =24=40 =24=3C =24(LIBS) clean=3A rm *=2Eexe --------------------------------------------------- ZLIB has a function for calculating the CRC-32 of a file=2E Here is a = brief example=3A -------------------- crc32=2Ec ---------------------- /* * C=E1lculo del CRC-32 mediante la ZLIB=2EDLL=2E */ =23include =3Cstdio=2Eh=3E =23include =3Cstdlib=2Eh=3E =23include =3Cmalloc=2Eh=3E =23include =3Csys/types=2Eh=3E =23include =3Csys/stat=2Eh=3E =23include =3Cwindows=2Eh=3E =23include =3Czlib=2Eh=3E int main(int argc=2C char **argv) =7B OPENFILENAME OpenFile=3B char InFileName=5B256=5D=3D=22=22=3B char FileNameFilter=5B256=5D =3D =22*=2E*=22=3B char Title=5B=5D=3D=22CRC32 calculator=22=3B FILE *InFile=3B char CurDir=5B256=5D=3B struct stat statbuf=3B long TamFichero=3B unsigned long int bytesleidos=3B int valdev=3B int crc =3D 0=3B char *bloque=3B char *version=3B printf(=22ZLIB=2EDLL=3A=5Cn=5Ctgeneral purpose compression library=5Cn=22= )=3B printf(=22=5Ctversion =25s=2C March 11th=2C 2002=5Cn=22=2C version)=3B printf(=22=5CtCopyright (C) 1995-2002 Jean-loup Gailly and Mark Adler=5C= n=22)=3B valdev =3D GetCurrentDirectory(256=2C CurDir)=3B if (valdev =3D=3D 0) =7B printf(=22No se pudo determinar el directorio actual=5Cn=22)=3B return(EXIT=5FFAILURE)=3B =7D ZeroMemory(=26OpenFile=2C sizeof(OPENFILENAME))=3B OpenFile=2ElStructSize=3Dsizeof(OPENFILENAME)=3B OpenFile=2ElpstrFilter =3D FileNameFilter=3B OpenFile=2ElpstrInitialDir =3D CurDir=3B OpenFile=2EnFilterIndex =3D 0=3B OpenFile=2EhwndOwner=3DHWND=5FDESKTOP=3B OpenFile=2ElpstrFile=3DInFileName=3B OpenFile=2EnMaxFile=3Dsizeof(InFileName)-1=3B OpenFile=2ElpstrTitle=3DTitle=3B OpenFile=2EFlags=3DOFN=5FFILEMUSTEXIST =7C OFN=5FHIDEREADONLY=3B if (GetOpenFileName(=26OpenFile)) =7B valdev =3D stat (InFileName=2C =26statbuf)=3B if (valdev !=3D 0) =7B printf(=22Error en stat()=5Cn=22)=3B return(EXIT=5FFAILURE)=3B =7D TamFichero =3D statbuf=2Est=5Fsize=3B /* Abrimos el fichero */ InFile =3D fopen (InFileName=2C =22rb=22)=3B if (InFile =3D=3D NULL) =7B printf(=22No se pudo abrir el fichero =25s=5Cn=22=2C InFileName)=3B= return(EXIT=5FFAILURE)=3B =7D /* Be careful if your file is a BEAST of 100 MBytes =3A-) */ bloque =3D (char *) calloc (TamFichero=2C sizeof(char))=3B bytesleidos =3D fread((char *)bloque=2C sizeof(char)=2C TamFichero=2C InFile)=3B if (bytesleidos =3C TamFichero ) =7B printf(=22Error en fread() =3A-)=5Cn=22)=3B return(EXIT=5FFAILURE)=3B =7D /* Here is the calculus of the CRC-32=2E You MUST initialize crc to * 0 the first time you invoque crc32()=2E */ crc =3D 0=3B crc =3D crc32(crc=2C bloque=2C TamFichero)=3B /* * The work can be divided in smaller blocks=2E This is a dirty * solution to the problem=2E */ /* Bye!!!!!!! */ free(bloque)=3B fclose(InFile)=3B printf(=22Filename=2Csize=2CCRC-32=5Cn=22)=3B printf(=22=25s=2C=25ld=2C=2508X=5Cn=22=2C InFileName=2C TamFichero=2C= crc)=3B =7D return (EXIT=5FSUCCESS)=3B =7D ---------------------------------------------------- Type make and that=27s all =3A-) Francisco PD=3A make is a GREAT program =3A-) PPD=3A MinGW is GREAT too! Thanks! |
From: Tom B. <an...@dd...> - 2002-04-29 14:42:55
|
> Just tell make that file2.o depends on file2.cpp : > > file2.o: file2.cpp > g++ -c file2.cpp -I$(INCDIR) Excuse me, but shouldn't it be file2.o: file2.cpp $(INCDIR)file2.h g++ -c file2.cpp -I$(INCDIR) because make then checks the date of the header file too? Tom |