Sto imparando come configurare i makefile e ho riscontrato un problema. Per dimostrarlo ho creato un semplice "progetto" composto da file sorgente main.m
e test.m
.Makefile ricompilando sempre un file
Sto provando ad installare fare per compilare questi file (solo se quarantina cambiato), e memorizzare i file oggetto in un altro posto (qui build/
)
mio Makefile:
OBJ = ./build
SOURCES=main.m test.m
OBJECTS=$(addprefix $(OBJ)/,$(SOURCES:.m=.o))
EXECUTABLE=test
all: $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS)
gcc $(OBJECTS) -o $(EXECUTABLE)
$(OBJECTS): $(OBJ)/%.o: %.m build/
gcc -c $< -o [email protected]
build/:
mkdir build
Quando eseguo per la prima volta (con la sola Makefile e le fonti nella directory corrente) fa quello che mi aspetto che faccia:
gcc -c main.m -o build/main.o
gcc -c test.m -o build/test.o
gcc ./build/main.o ./build/test.o -o test
Tuttavia, se corro make
ancora:
gcc -c main.m -o build/main.o
gcc ./build/main.o ./build/test.o -o test
Cosa ho fatto di sbagliato? Apprezziamo anche qualsiasi altro errore nel Makefile, poiché sto cercando di imparare a creare "buoni" Makefile.
EDIT:
Quello che ho notato da make -d
:
Finished prerequisites of target file `build/main.o'.
Prerequisite `main.m' is older than target `build/main.o'.
Prerequisite `build/' is older than target `build/main.o'.
No need to remake target `build/main.o'.
e
Finished prerequisites of target file `build/test.o'.
Prerequisite `test.m' is older than target `build/test.o'.
Prerequisite `build/' is newer than target `build/test.o'.
Must remake target `build/test.o'.
Penso che semplicemente non si desidera che il '/' 'attaccato al build' in un un paio di posti. Fammi provare qui. Puoi usare 'make -d' per vedere come' make' sta prendendo le sue decisioni su cosa costruire, se questo aiuta. –
Grazie. Tuttavia, la rotta 'make -d' richiederà un po 'di tempo perché emette 927 linee di informazioni :) – varesa
Puoi tranquillizzarlo eliminando tutte le regole implicite che sono possibili. Ho appena provato il tuo makefile qui con un semplice progetto di test, e mi è sembrato che funzionasse come previsto. Cioè, alla seconda manche, ho appena ottenuto "make: Nothing to be done for 'all'". –