Diferencia entre revisiones de «Introducción a Patrones de Diseño en C++ con Qt4/1.9 El comando make»

Contenido eliminado Contenido añadido
Página creada con '{{nav2|Introducción a Patrones de Diseño en C++ con Qt4/1.8.1 include: Encontrando archivos de cabecera|#include: Encontrando archivos de cabecera|Introducción a Patrones de …'
 
Paynalton (discusión | contribs.)
Sin resumen de edición
Línea 1:
{{nav2|Introducción a Patrones de Diseño en C++ con Qt4/1.8.1 include: Encontrando archivos de cabecera|#include: Encontrando archivos de cabecera|Introducción a Patrones de Diseño en C++ con Qt4|Contenido|Introducción a Patrones de Diseño en C++ con Qt4/1.10 Obteniendo ayuda en línea|Obteniendo ayuda en línea}}
----
1.9.=El Thecomando make Command=
 
[ fromfile: makefile.xml id: makefile ]
 
En lugar de correr la línea de comando del compilador directamente, comenzaremos a usar '''make'''<ref>Dependiendo de tu entorno de desarrollo, este programa puede tener algúnos otros nombres como ''mingw32-make'', ''nmake'', ''gmake'', o ''unsermake''.</ref> que simplifica enormemente el proceso de construcción cuando un proyecto involucra múltiples archivos fuente y librerías.
Instead of running the command line compiler directly, we will start using make, [8] which greatly simplifies the build process when a project involves multiple source files and libraries.
 
We have seen before that qmake (without arguments) reads a project file and builds a Makefile. Example 1.8 is a slightly abbreviated look at the Makefile generated from a simple project called qapp.
 
Hemos visto antes que '''qmake''' (sin argumentos) lee un archivo de proyecto y construye un ''Makefile''. El Ejemplo 1.8 es una vista medianamente abreviada de el ''Makefile'' generado por un simple proyecto llamado ''qapp''.
Example 1.8. src/qapp/Makefile-abbreviated
 
# Exerpts from a makefile
 
====Ejemplo 1.8====
####### Compiler, tools and options
{{ejemplo2|Ejemplo 1.8 src/qapp/Makefile-abbreviated||
# Exerpts from a makefile
####### Compiler, tools and options
CC &#61; gcc # executable for C compiler
CXX &#61; g++ # executable for c++ compiler
LINK &#61; g++ # executable for linker
# flags that get passed to the compiler
CFLAGS &#61; -pipe -g -Wall -W -D_REENTRANT $(DEFINES)
CXXFLAGS &#61; -pipe -g -Wall -W -D_REENTRANT $(DEFINES)
INCPATH &#61; -I/usr/local/qt/mkspecs/default -I. \
-I$(QT4)/include/QtGui -I$(QT4)/include/QtCore \
-I$(QT4)/include
# Linker flags
LIBS &#61; $(SUBLIBS) -L$(QT4)/lib -lQtCore_debug -lQtGui_debug -lpthread
LFLAGS &#61; -Wl,-rpath,$(QT4)/lib
# macros for performing other operations as part of build steps:
QMAKE &#61; /usr/local/qt/bin/qmake
####### Files
HEADERS &#61; # If we had some, they'd be here.
SOURCES &#61; main.cpp
OBJECTS &#61; main.o
[snip]
QMAKE_TARGET &#61; qapp
DESTDIR &#61;
TARGET &#61; qapp # default target to build
first: all # to build "first" we must build "all"
####### Implicit rules
.SUFFIXES: .c .o .cpp .cc .cxx .C
.cpp.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
## Possible targets to build
all: Makefile $(TARGET) # this is how to build "all"
$(TARGET): $(OBJECTS) $(OBJMOC) # this is how to build qapp
$(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJMOC) $(OBJCOMP) \
$(LIBS)
qmake: FORCE # "qmake" is a target too!
@$(QMAKE) -o Makefile qapp.pro # what does it do?
dist: # Another target
@mkdir -p .tmp/qapp \
&& $(COPY_FILE) --parents $(SOURCES) $(HEADERS) \
$(FORMS) $(DIST) .tmp/qapp/ \
&& (cd `dirname .tmp/qapp` \ && $(TAR) qapp.tar qapp \
&& $(COMPRESS) qapp.tar) \
&& $(MOVE) `dirname .tmp/qapp`/qapp.tar.gz . \
&& $(DEL_FILE) -r .tmp/qapp
clean:compiler_clean # yet another target
-$(DEL_FILE) $(OBJECTS)
-$(DEL_FILE) *~ core *.core
####### Dependencies for implicit rules
main.o: main.cpp
 
|http://cartan.cas.suffolk.edu/oopdocbook/docs/src/qapp/Makefile-abbreviated}}
CC = gcc # executable for C compiler
CXX = g++ # executable for c++ compiler
LINK = g++ # executable for linker
 
# flags that get passed to the compiler
CFLAGS = -pipe -g -Wall -W -D_REENTRANT $(DEFINES)
CXXFLAGS = -pipe -g -Wall -W -D_REENTRANT $(DEFINES)
INCPATH = -I/usr/local/qt/mkspecs/default -I. \
-I$(QT4)/include/QtGui -I$(QT4)/include/QtCore \
-I$(QT4)/include
 
El comando '''make''' revisa las dependencias y realiza cada paso de construcción del ''Makefile''. El nombre y ubicación del resultado final puede ser establecido con las variables del proyecto ''TARGET'' y ''target.path''. Si ''TARGET'' no es especificado, el nombre por defecto dado es el nombre del directorio en el que el archivo del proyecto se aloja. Si ''target.path'' no se especifica, la localización por defecto es el directorio en el que el proyecto se ubica
# Linker flags
LIBS = $(SUBLIBS) -L$(QT4)/lib -lQtCore_debug -lQtGui_debug -lpthread
LFLAGS = -Wl,-rpath,$(QT4)/lib
 
# macros for performing other operations as part of build steps:
QMAKE = /usr/local/qt/bin/qmake
 
==Limpiando Archivos==
####### Files
 
'''make''' puede limpiar los archivos generados por tí por medio de dos objetivos, ''clean'' y ''distclean''. Observa cómo ambos son distintos:
HEADERS = # If we had some, they'd be here.
SOURCES = main.cpp
OBJECTS = main.o
[snip]
QMAKE_TARGET = qapp
DESTDIR =
TARGET = qapp # default target to build
 
src/qapp> '''make clean'''
first: all # to build "first" we must build "all"
rm -f main.o
rm -f *~ core *.core
src/qapp> ls
Makefile main.cpp qapp qapp.pro
 
src/qapp> '''make distclean'''
####### Implicit rules
rm -f qmake_image_collection.cpp
rm -f main.o
rm -f *~ core *.core
rm -f qapp
rm -f Makefile
src/qapp> ls
main.cpp qapp.pro
 
.SUFFIXES: .c .o .cpp .cc .cxx .C
 
Después de un '''make distclean''', los únicos archivos que restan son los de las fuentes que pueden ir dentro de una ''tarball'' para su distribución
.cpp.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
 
## Possible targets to build
 
{{note|Si modificas un archivo de proyecto desde la última ejecución de '''make''', la siguiente invocación de '''make''' debería reconstruir el ''Makefile'' mismo (por medio de qmake) antes de volver a correr '''make''' sobre el nuevo ''Makefile'' generado.
all: Makefile $(TARGET) # this is how to build "all"
 
$(TARGET): $(OBJECTS) $(OBJMOC) # this is how to build qapp
$(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJMOC) $(OBJCOMP) \
$(LIBS)
 
qmake: FORCE # "qmake" is a target too!
@$(QMAKE) -o Makefile qapp.pro # what does it do?
 
En otras palabras, el ''Makefile'' es ''sencible a qmake'' y puede ''rehacerse'' a si mismo.}}
dist: # Another target
@mkdir -p .tmp/qapp \
&& $(COPY_FILE) --parents $(SOURCES) $(HEADERS) \
$(FORMS) $(DIST) .tmp/qapp/ \
&& (cd `dirname .tmp/qapp` \ && $(TAR) qapp.tar qapp \
&& $(COMPRESS) qapp.tar) \
&& $(MOVE) `dirname .tmp/qapp`/qapp.tar.gz . \
&& $(DEL_FILE) -r .tmp/qapp
 
clean:compiler_clean # yet another target
-$(DEL_FILE) $(OBJECTS)
-$(DEL_FILE) *~ core *.core
 
 
{{tip|make dist|El comando '''make dist''' creará un tarball (nombre_del_directorio.tar.gz) que contenga todos loas archivos fuente sobre los que el proyecto tenga conocimiento.}}
####### Dependencies for implicit rules
 
main.o: main.cpp
 
 
Así como nosotros agregamos más codigo fuente, cabeceras o módulos de librerías para nuestro proyecto, editamos el archivo ''.pro'' y añadimos los nuevos elementos a las listas ''SOURCES'', ''HEADERS'', y ''LIBS''. La misma documentación standard que aplica también para el código fuente de C++ debería ser aplicada a los archivos de proyecto (con los comentarios comenzando con #).
(link)
 
The command make checks the dependencies and performs each build step specified in the Makefile. The name and location of the final result can be set with the project variables, TARGET and target.path. If TARGET is not specified, the name defaults to the name of the directory in which the project file is located. If target.path is not specified, the location defaults to the directory in which the project file is located.
Cleaning up Files
 
make can clean up the generated files for you, with the two targets, clean and distclean. Observe how they are different:
 
Pensemoss en el archivo de proyecto como un mapa de nuestro proyecto, conteniendo referencias para todos los archivos y localizaciones requeridas para construir nuestra aplicación o librería. Como otros archivos fuente, este es tanto leible por humanos como por la máquina. El archivo ''.pro'' es el primer lugar para mirar cuando encontramos mensajes ''not found'' o ''undefined'' durante el proceso de construcción (especialmente en el momento del enlace). Para más detalles recomendamos que leas la [http://cartan.cas.suffolk.edu/qtdocs/qmake-manual.html Guía para qmake de Trolltech].
src/qapp> make clean
rm -f main.o
rm -f *~ core *.core
src/qapp> ls
Makefile main.cpp qapp qapp.pro
 
src/qapp> make distclean
rm -f qmake_image_collection.cpp
rm -f main.o
rm -f *~ core *.core
rm -f qapp
rm -f Makefile
src/qapp> ls
main.cpp qapp.pro
 
After a make distclean, the only files that remain are the source files that can go into a tarball for distribution.
[Note] Note
 
If you modify a project file since the last execution of make, the next invocation of make should rebuild the Makefile itself (via qmake) before re-running make on the newly generated Makefile.
 
In other words, the Makefile is qmake-aware and can re-qmake itself.
[Tip] Tip
The command make dist will create a tarball (dirname.tar.gz) that contains all the source files that the project file knows about.
 
As we add more source-code, header, or library modules for our project, we edit the .pro file and add the new items to the SOURCES, HEADERS, and LIBS lists. The same documentation standards that apply to C++ source code should be applied to project files (where comments begin with #).
 
We think of the project file as a map of our project, containing references to all files and locations required for building our application or library. Like other source code files, this is both human-readable and machine-readable. The .pro file is the first place to look when we encounter “not found” or “undefined” messages during the build process (especially at link time). For further details we recommend that you read Trolltech's guide to qmake.
 
[8] Depending on your development environment, this program goes under many other names, such as mingw32-make, nmake, gmake, or unsermake
----
{{nav2|Introducción a Patrones de Diseño en C++ con Qt4/1.8.1 include: Encontrando archivos de cabecera|#include: Encontrando archivos de cabecera|Introducción a Patrones de Diseño en C++ con Qt4|Contenido|Introducción a Patrones de Diseño en C++ con Qt4/1.10 Obteniendo ayuda en línea|Obteniendo ayuda en línea}}