1 / 40

La herramienta make

La herramienta make. Cómo leer y modificar un Makefile. > make . busca por “makefile”. busca por “Makefile”. > make  make: *** No makefile found. Stop. > make  make: *** No makefile found. Stop. > make –f mimakefile.mak . objetivo : dependencias.

laurel
Download Presentation

La herramienta make

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. La herramienta make Cómo leer y modificar un Makefile

  2. > make  busca por “makefile” busca por “Makefile” 2

  3. > make make: *** No makefile found. Stop. 3

  4. > make make: *** No makefile found. Stop.> make –f mimakefile.mak  objetivo : dependencias 4

  5. > make make: *** No makefile found. Stop.> make –f mimakefile.mak  main : main.f dependecias objetivo 5

  6. > make make: *** No makefile found. Stop.> make –f mimakefile.mak f77 main.f –o main main : main.f .f extensión reconocida sólo si no existe o si antiguo 6

  7. > make make: *** No makefile found. Stop.> make –f mimakefile.mak make: ‘main’ is up date. main : main.f 7

  8. > make  main : main.f fn1.f fn2.f  dependecias objetivo 8

  9. > make  main : main.f fn1.f fn2.f main2 : main2.f fn3.f fn4.f objetivo1 objetivo2 9

  10. > make objetivo> make main2  main : main.f fn1.f fn2.f main2 : main2.f fn3.f fn4.f objetivo1 objetivo2 10

  11. > make [objetivo] main : main.o fn1.o fn2.o main.o : main.f fn1.o : fn1.f fn2.o : fn2.f jerarquía 11

  12. > make [objetivo]  main : main.o fn1.o fn2.o [TAB] f77 –O –o main main.o fn1.o fn2.o main.o : main.f fn1.o : fn1.f fn2.o : fn2.f línea de comando 12

  13. > make [objetivo]  main : main.o fn1.o fn2.o [TAB] f77 –O –o main main.o fn1.o fn2.o main.o : main.f [TAB] f77 –O –c main.f fn1.o : fn1.f fn2.o : fn2.f línea de comando 13

  14. > make [objetivo]  main : main.o fn1.o fn2.o [TAB] f77 –O –o main main.o fn1.o fn2.o main.o : main.f [TAB] f77 –O –c main.f fn1.o : fn1.f [TAB] f77 –O –c fn1.f fn2.o : fn2.f línea de comando 14

  15. > make [objetivo]  main : main.o fn1.o fn2.o [TAB] f77 –O –o main main.o fn1.o fn2.o main.o : main.f [TAB] f77 –O –c main.f fn1.o : fn1.f [TAB] f77 –O –c fn1.f fn2.o : fn2.f [TAB] f77 –O –c fn2.f línea de comando ojo con los tabuladores 15

  16. > make [objetivo]  main : main.o fn1.o fn2.o [TAB] f77 –O –o main main.o fn1.o fn2.o main.o : main.f [TAB] f77 –O –c main.f fn1.o : fn1.f [TAB] f77 –O –c fn1.f fn2.o : fn2.f [TAB] f77 –O –c fn2.f • orden shell: sh • división líneas: ‘\’ •  un comando: ‘;’ •  una línea: ojo • sin eco: @ 16

  17. > make [objetivo]  main : main.o fn1.o fn2.o [TAB] f77 –O –o main main.o fn1.o fn2.o [TAB]@ echo “Muevo el ejecutable.” [TAB]@ mv main .. ; ls [TAB]@ cd .. ; \ [RETURN] chmod a+x main main.o : main.f [TAB] f77 –O –c main.f fn1.o : fn1.f [TAB] f77 –O –c fn1.f fn2.o : fn2.f [TAB] f77 –O –c fn2.f • orden shell: sh • división líneas: ‘\’ •  un comando: ‘;’ •  una línea: ojo • sin eco: @ 17

  18. > make [objetivo]  main : main.o fn1.o fn2.o [TAB] f77 –O –o main main.o fn1.o fn2.o main.o : main.f [TAB] f77 –O –c main.f fn1.o : fn1.f [TAB] f77 –O –c fn1.f fn2.o : fn2.f [TAB] f77 –O –c fn2.f fn1.o : include.inc fn2.o : include.inc repetición de objetivos 18

  19. > make limpia  main : main.o fn1.o fn2.o [TAB] f77 –O –o main main.o fn1.o fn2.o main.o : main.f [TAB] f77 –O –c main.f fn1.o : fn1.f [TAB] f77 –O –c fn1.f fn2.o : fn2.f [TAB] f77 –O –c fn2.f fn1.o fn2.o : include.inc limpia : [TAB] rm *% podemos agrupar objetivo etiqueta 19

  20. > make [todo] > make libreria.a> make limpia> todo : libreria.a main limpia main : main.o fn1.o fn2.o [TAB] f77 –O –o mainmain.o fn1.o fn2.o main.o : main.f [TAB] f77 –O –c main.f fn1.o : fn1.f [TAB] f77 –O –c fn1.f fn2.o : fn2.f [TAB] f77 –O –c fn2.f fn1.o fn2.o : include.inc libreria.a : libfn.o [TAB] ar r libreria.a libfn.o libfn.o : libfn.f [TAB] f77 –O –c libfn.f limpia : [TAB]rm *%  20

  21. > make  nombre = valor macro = se referencia como $(nombre) o ${nombre} 21

  22. > make  • macros del usuario • macros internas • variables de entorno • línea de ejecución • indefinidas = vacías Orden de prioridad: 1) macros internas 2) variables entorno 3) en Makefile 4) línea de ejecución EXE = main OBJS = main.o fn1.o fn2.o INCS = include.inc FFLAGS = –O LDFLAGS = ${FFLAGS} ${EXE} : ${OBJS} [TAB] f77${LDFLAGS} –o ${EXE} ${OBJS} [TAB] cp${EXE} /home/usuario/bin main.o : main.f [TAB] f77 ${FFLAGS} –c main.f fn1.o : fn1.f [TAB] f77 ${FFLAGS} –c fn1.f fn2.o : fn2.f [TAB] f77 ${FFLAGS} –c fn2.f fn1.o fn2.o : ${INCS} 22

  23. > touch fn2.f > make “FFLAGS = –v –O” f77 –v –O –c fn2.f f77 –v –O –o main main.o fn1.o fn2.o EXE = main OBJS = main.o fn1.o fn2.o DIR = ${HOME}/bin FFLAGS = –O LDFLAGS = ${FFLAGS} ${EXE} : ${OBJS} [TAB] ${FC} ${LDFLAGS} –o ${EXE} ${OBJS} [TAB] cp ${EXE} ${DIR} main.o : main.f [TAB] ${FC} ${FFLAGS} –c main.f fn1.o : fn1.f [TAB] ${FC} ${FFLAGS} –c fn1.f fn2.o : fn2.f [TAB] ${FC} ${FFLAGS} –c fn2.f fn1.o fn2.o : include.inc • FFLAGS ignorada • FC = f77 (interna) • podemos FC = f90 • make –p • no usar ‘~’ en rutas 23

  24. > touch fn2.f > make “FFLAGS = –v –O” f77 –v –O –c fn2.f f77 –v –O –o main main.o fn1.o fn2.o EXE = main SRCS = main.f fn1.f fn2.f OBJS = ${SRCS:.f=.o} FFLAGS = –O LDFLAGS = ${FFLAGS} ${EXE} : ${OBJS} [TAB] ${FC} ${LDFLAGS} –o ${EXE} ${OBJS} [TAB] cp ${EXE} ${HOME}/bin main.o : main.f [TAB] ${FC} ${FFLAGS} –c main.f fn1.o : fn1.f [TAB] ${FC} ${FFLAGS} –c fn1.f fn2.o : fn2.f [TAB] ${FC} ${FFLAGS} –c fn2.f fn1.o fn2.o : include.inc OBJS = SRCS pero sustituyendo ‘.f’ por ‘.o’ 24

  25. > touch fn2.f > make “FFLAGS = –v –O” f77 –v –O –c fn2.f f77 –v –O –o main main.o fn1.o fn2.o EXE = main SRCS = main.f fn1.f fn2.f OBJS = ${SRCS:.f=.o} FFLAGS = –O LDFLAGS = ${FFLAGS} ${EXE} : ${OBJS} [TAB] ${FC} ${LDFLAGS} –o ${EXE} ${OBJS} [TAB] cp ${EXE} ${HOME}/bin main.o : main.f [TAB] ${FC} ${FFLAGS} –c main.f fn1.o : fn1.f [TAB] ${FC} ${FFLAGS} –c fn1.f fn2.o : fn2.f [TAB] ${FC} ${FFLAGS} –c fn2.f fn1.o fn2.o : include.inc $? = lista de dependencias $@ = objetivo en comandos $$@ = objetivo (sólo Unix) en dependencias 25

  26. > touch fn2.f > make “FFLAGS = –v –O” f77 –v –O –c fn2.f f77 –v –O –o main main.o fn1.o fn2.o EXE = main SRCS = fn1.f fn2.f OBJS = ${SRCS:.f=.o} FFLAGS = –O LDFLAGS = ${FFLAGS} ${EXE} : $$@.o ${OBJS} [TAB] ${FC} ${LDFLAGS} –o ${EXE}${OBJS} [TAB] cp ${EXE} ${HOME}/bin main.o : main.f [TAB] ${FC} ${FFLAGS} –c main.f fn1.o : fn1.f [TAB] ${FC} ${FFLAGS} –c fn1.f fn2.o : fn2.f [TAB] ${FC} ${FFLAGS} –c fn2.f fn1.o fn2.o : include.inc omitimos main.f $$@.o = main.o 26

  27. > touch fn2.f > make “FFLAGS = –v –O” f77 –v –O –c fn2.f f77 –v –O –o main main.o fn1.o fn2.o EXE = main SRCS = fn1.f fn2.f OBJS = ${SRCS:.f=.o} FFLAGS = –O LDFLAGS = ${FFLAGS} ${EXE} : $$@.o ${OBJS} [TAB] ${FC} ${LDFLAGS} –o $@ ${OBJS} [TAB] cp $@ ${HOME}/bin main.o : main.f [TAB] ${FC} ${FFLAGS} –c main.f fn1.o : fn1.f [TAB] ${FC} ${FFLAGS} –c fn1.f fn2.o : fn2.f [TAB] ${FC} ${FFLAGS} –c fn2.f fn1.o fn2.o : include.inc omitimos main.f $$@.o = main.o $@ = main 27

  28. > touch fn2.f > make “FFLAGS = –v –O” f77 –v –O –c fn2.f f77 –v –O –o main main.o fn1.o fn2.o EXE = main SRCS = fn1.f fn2.f OBJS = ${SRCS:.f=.o} FFLAGS = –O LDFLAGS = ${FFLAGS} ${EXE} : $$@.o ${OBJS} [TAB] ${FC} ${LDFLAGS} –o $@ $? [TAB] cp $@ ${HOME}/bin main.o : main.f [TAB] ${FC} ${FFLAGS} –c main.f fn1.o : fn1.f [TAB] ${FC} ${FFLAGS} –c fn1.f fn2.o : fn2.f [TAB] ${FC} ${FFLAGS} –c fn2.f fn1.o fn2.o : include.inc omitimos main.f $$@.o = main.o $@ = main $? = main.o fn1.o fn2.o 28

  29. > touch fn2.f > make “FFLAGS = –v –O” f77 –v –O –c fn2.f f77 –v –O –o main main.o fn1.o fn2.o EXE = main SRCS = fn1.f fn2.f OBJS = ${SRCS:.f=.o} FFLAGS = –O LDFLAGS = ${FFLAGS} ${EXE} : $$@.o ${OBJS} [TAB] ${FC} ${LDFLAGS} –o $@ $? [TAB] cp $@ ${HOME}/bin main.o : main.f [TAB] ${FC} ${FFLAGS} –c $? fn1.o : fn1.f [TAB] ${FC} ${FFLAGS} –c fn1.f fn2.o : fn2.f [TAB] ${FC} ${FFLAGS} –c fn2.f fn1.o fn2.o : include.inc omitimos main.f $$@.o = main.o $@ = main $? = main.o fn1.o fn2.o $? = main.f 29

  30. > touch fn2.f > make “FFLAGS = –v –O” f77 –v –O –c fn2.f f77 –v –O –o main main.o fn1.o fn2.o EXE = main SRCS = fn1.f fn2.f OBJS = ${SRCS:.f=.o} FFLAGS = –O LDFLAGS = ${FFLAGS} ${EXE} : $$@.o ${OBJS} [TAB] ${FC} ${LDFLAGS} –o $@ $? [TAB] cp $@ ${HOME}/bin main.o : main.f [TAB] ${FC} ${FFLAGS} –c $? fn1.o : fn1.f [TAB] ${FC} ${FFLAGS} –c $? fn2.o : fn2.f [TAB] ${FC} ${FFLAGS} –c fn2.f fn1.o fn2.o : include.inc omitimos main.f $$@.o = main.o $@ = main $? = main.o fn1.o fn2.o $? = main.f $? = fn1.f 30

  31. > touch fn2.f > make “FFLAGS = –v –O” f77 –v –O –c fn2.f f77 –v –O –o main main.o fn1.o fn2.o EXE = main SRCS = fn1.f fn2.f OBJS = ${SRCS:.f=.o} FFLAGS = –O LDFLAGS = ${FFLAGS} ${EXE} : $$@.o ${OBJS} [TAB] ${FC} ${LDFLAGS} –o $@$? [TAB] cp $@ ${HOME}/bin main.o : main.f [TAB] ${FC} ${FFLAGS} –c $? fn1.o : fn1.f [TAB] ${FC} ${FFLAGS} –c $? fn2.o : fn2.f [TAB] ${FC} ${FFLAGS} –c $? fn1.o fn2.o : include.inc omitimos main.f $$@.o = main.o $@ = main $? = main.o fn1.o fn2.o $? = main.f $? = fn1.f $? = fn2.f 31

  32. > touch fn2.f > make “FFLAGS = –v –O” f77 –v –O –c fn2.f f77 –v –O –o main main.o fn1.o fn2.o EXE = main SRCS = fn1.f fn2.f OBJS = ${SRCS:.f=.o} FFLAGS = –O LDFLAGS = ${FFLAGS} ${EXE} : $$@.o ${OBJS} [TAB] ${FC} ${LDFLAGS} –o $@ $? [TAB] cp $@ ${HOME}/bin main.o : main.f [TAB] ${FC} ${FFLAGS} –c $? fn1.o : fn1.f [TAB] ${FC} ${FFLAGS} –c $? fn2.o : fn2.f [TAB] ${FC} ${FFLAGS} –c $? ${OBJS} : include.inc OBJS = fn1.o fn2.o se desdobla 32

  33. > touch fn2.f > make “FFLAGS = –v –O” f77 –v –O –c fn2.f f77 –v –O –o main main.o fn1.o fn2.o EXE = main SRCS = fn1.f fn2.f OBJS = ${SRCS:.f=.o} FFLAGS = –O LDFLAGS = ${FFLAGS} ${EXE} : $$@.o ${OBJS} [TAB] ${FC} ${LDFLAGS} –o $@$? [TAB] cp $@ ${HOME}/bin main.o : main.f [TAB] ${FC} ${FFLAGS} –c $? fn1.o : fn1.f [TAB] ${FC} ${FFLAGS} –c $? fn2.o : fn2.f [TAB] ${FC} ${FFLAGS} –c $? ${OBJS} : include.inc 33

  34. > touch fn2.f > make “FFLAGS = –v –O” f77 –v –O –c fn2.f f77 –v –O –o main main.o fn1.o fn2.o EXE = main SRCS = fn1.f fn2.f INCS = include.inc OBJS = ${SRCS:.f=.o} DIR = ${HOME}/bin FFLAGS = –O LDFLAGS = ${FFLAGS} .f.o : [TAB] ${FC} ${FFLAGS} –c $< ${EXE} : $$@.o ${OBJS} [TAB] ${FC} ${LDFLAGS} –o $@$? [TAB] cp $@ ${DIR} ${OBJS} : ${INCS} regla para construir los .o a partir de los .f $< = .f más nuevos 34

  35. > touch fn2.f > make “FFLAGS = –v –O” f77 –v –O –c fn2.f f77 –v –O –o main main.o fn1.o fn2.o EXE = main SRCS = fn1.F fn2.F INCS = include.inc OBJS = ${SRCS:.f=.o} DIR = ${HOME}/bin FFLAGS = –O LDFLAGS = ${FFLAGS} .SUFFIXES : .F .F.o : [TAB] ${FC} ${FFLAGS} –c $< ${EXE} : $$@.o ${OBJS} [TAB] ${FC} ${LDFLAGS} –o $@$? [TAB] cp $@ ${DIR} ${OBJS} : ${INCS}  añade sufijos a lista de make 35

  36. Makefile de IRAF # Name: # makefile # # Purpose: # Build and install the IRAFSTAR package. # # Type of Module: # Description file for the make utility. # # Description: # This description file is used by the make utility to # build the IRAFSTAR package from the distributed # source files, to install the resulting system for use, # and to perform other housekeeping tasks. # ###################################################### # # Pathname of the root directory beneath which # other Starlink software is currently installed. STARLINK = /star 36

  37. Makefile de IRAF # Pathnames of Starlink sub-directories that may # be referenced when building this package. STAR_BIN = $(STARLINK)/bin STAR_DATES = $(STARLINK)/dates STAR_DOCS = $(STARLINK)/docs STAR_ETC = $(STARLINK)/etc STAR_HELP = $(STARLINK)/help STAR_INC = $(STARLINK)/include STAR_LIB = $(STARLINK)/lib STAR_SHARE = $(STARLINK)/share # Pathname of the root directory beneath which the # built files for this package should be installed for # use. This defaults to the user's home directory. INSTALL = $(HOME) # Pathname of root directory beneath which TCLADAM # is installed. and the version number of TCL TCL_VERS = 8.2 TCL_INC_DIR = $(STAR_INC) TCL_LIB_DIR = $(STAR_LIB) 37

  38. Makefile de IRAF # Default macros for compiling C and Fortran source code. CC = c89 CFLAGS = -O -I$(TCL_INC_DIR) -I$(STAR_INC) FC = fort77 FFLAGS = -O # Commands for adding to and extracting from an # archive file (.tar). TAR_IN = tar cvhf TAR_OUT = tar xf #------------------------------------------------------------------------------- # DEFINE PACKAGE SOURCE FILES. # # This section defines the set of source files for # the package. # Name of the package as specified in documentation # The value is used in messages from make to the user. PACK_NAME = IRAFSTAR 38

  39. Makefile de IRAF # C routines required for building the package. This is # just a list of all the C source files. C_ROUTINES = tclAppInit.c tclIrafio.c zfiopr.c #------------------------------------------------------------------------------- # DEFINE FILES REQUIRED FOR BUILDING # THE PACKAGE. # # This section defines the set of files produced from # the source files when the package is built and installed. # List of object files produced by compiling the source # code and rules for performing the compilations. OBJECT_FILES = $(C_ROUTINES:.c=.o) # Use .o, .c, .f, .ifc, .ifl, .shl and .hlp suffix rules. .SUFFIXES: .o .c .f .ifc .ifl .shl .hlp # Implicit rule. .c.o: $(CC) $(CFLAGS) -c $< 39

  40. Makefile de IRAF ######################################################## # PRIMARY TARGETS. # # Rules for extracting source files from the source archive. $(C_ROUTINES) : [TAB] $(TAR_OUT) $(PKG_NAME)_source.tar $@ [TAB]@ if test -r $@; then ; \ else echo $@ is not in the tar file ; exit 1 ; fi # Rule and dependencies for building the # executable image. aitclsh : $(OBJECT_FILES) [TAB] $(FC) $(FFLAGS) -o $@\ tclAppInit.o $(STAR_LIB)/tclAdam.o \ tclIrafio.o zfiopr.o \ $(LDFLAGS) -L$(TCL_LIB_DIR) \ -L$(STAR_LIB) \ -ltcl$(TCL_VERS) 40

More Related