¿Cómo llamar a Makefile desde otro Makefile?


Estoy obteniendo algunos resultados inesperados llamando a un makefile desde otro. Tengo dos makefiles, uno llamado /path/to/project/makefile y otro llamado /path/to/project/gtest-1.4.0/make/Makefile. Estoy intentando que los primeros llamen a los segundos. En/path/to/project / makefile, tengo

dev: $(OBJ_FILES)
  $(CPPC) $(LIBS) $(FLAGS_DEV) $(OBJ_FILES) -o $(BIN_DIR)/$(PROJECT)
  $(MAKE) -f ./gtest-1.4.0/make/Makefile

clean:
  rm -f ./*~ ./gmon.out ./core $(SRC_DIR)/*~ $(OBJ_DIR)/*.o
  rm -f ../svn-commit.tmp~
  rm -f $(BIN_DIR)/$(PROJECT)
  make -f gtest-1.4.0/make/Makefile clean

Y en /path/to/project/gtest-1.4.0/make/Makefile tengo{[15]]}

all: $(TESTS)

clean:
  rm -f $(TESTS) gtest.a gtest_main.a *.o

Emitiendo lo siguiente:

cd /path/to/project
make

Salidas:

make -f ./gtest-1.4.0/make/Makefile
make[1]: Entering directory `/path/to/project'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/path/to/project'

Sin embargo, cuando emito estos comandos:{[15]]}

cd /path/to/project
make clean

Veo:

make -f gtest-1.4.0/make/Makefile clean
make[1]: Entering directory `/path/to/project'
rm -f  gtest.a gtest_main.a *.o
make[1]: Leaving directory `/path/to/project'

No entiendo: En ambos casos, /path/to/project/makefile es diciéndome que está entrando en el directorio de trabajo actual. En el primer caso, no cree que tenga trabajo que hacer (cuando lo hace) y en el segundo caso, es capaz de encontrar la directiva apropiada (cuando la salida me dice que está buscando en el directorio equivocado) sin embargo, intenta ejecutar el comando rm en /path/to/project, en lugar de /path/to/makefile/gtest-1.4.0/make/.

¿Me estoy perdiendo algo fundamental para llamar a makefiles unos de otros? ¿He cometido un error conceptual atroz, o he encontrado una trampa común? ¿Cómo puedo efectivamente cambiar directorios y llamar a un segundo makefile desde dentro del primero? Mi entendimiento era que simplemente llamar make -f <name> sería suficiente.

Esto es make/gmake 3.81 en bash.

Author: kenorb, 2010-02-05

4 answers

No estoy muy claro lo que está pidiendo, pero usando la opción de línea de comandos -f solo especifica un archivo - no le dice a make que cambie los directorios. Si quieres hacer el trabajo en otro directorio, necesitas cd al directorio:

clean:
    cd gtest-1.4.0 && $(MAKE) clean

Tenga en cuenta que cada línea en Makefile se ejecuta en un shell separado, por lo que no hay necesidad de cambiar el directorio de nuevo.

 88
Author: kenorb,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-11-10 19:36:57

En lugar de -f de make es posible que desee utilizar la opción -C <path>. Esto primero cambia a la ruta' <path>', y luego calles make allí.

Ejemplo:

clean:
  rm -f ./*~ ./gmon.out ./core $(SRC_DIR)/*~ $(OBJ_DIR)/*.o
  rm -f ../svn-commit.tmp~
  rm -f $(BIN_DIR)/$(PROJECT)
  $(MAKE) -C gtest-1.4.0/make clean
 95
Author: Tader,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-05-02 14:38:55

Http://www.gnu.org/software/make/manual/make.html#Recursion

 subsystem:
         cd subdir && $(MAKE)

O, equivalentemente, esto:

 subsystem:
         $(MAKE) -C subdir
 24
Author: Aadishri,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-08-02 10:51:55

Parece claro que $(TESTS) está vacío por lo que su makefile 1.4.0 es efectivamente

all: 

clean:
  rm -f  gtest.a gtest_main.a *.o

De hecho, todo no tiene nada que ver. y clean hace exactamente lo que dice rm -f gtest.a ...

 1
Author: John Knoeller,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-02-05 10:17:32