Kontakt:
Thorsten Gunkel
63456 Hanau
Deutschland
Mail
Stimm ab und hilf mit diese Seite zu verbessern!
Hat die Seite Deine Erwartung erfüllt?
vote3 Ja
vote2 Naja
vote1 Nein
Ein kurzer Kommentar?
Dieses Feld nicht ändern:
Schreibe Deinen Kommentar doch einfach in das
Gästebuch.
Letzte Änderung: 20-05-2007 00.10
NO ePATENTS

Makefiles

06-08-2005 13.09

Kommentare

# foo bar
06-08-2005 13.09

Rules, Dependency Lines, Target Sources, Shell Lines

Erzeugt TARGET welches von TARGETSOURCE1 TARGETSOURCE2 TARGETSOURCE3 ... abhängt indem SHELLLINE1 SHELLLINE2 SHELLLINE3 ... ausgeführt werden:
TARGET: TARGETSOURCE1 TARGETSOURCE2 TARGETSOURCE3 ...
SHELLLINE1
SHELLLINE2
SHELLLINE3
...
Falls TARGET keine echte Datei ist sollte man .PHONY TARGET einfügen:
.PHONY: TARGET
TARGET: TARGETSOURCE1 TARGETSOURCE2 TARGETSOURCE3 ...
...
Man kann in einer SHELLLINE auch wieder rekursiv ein anderes TARGET anspringen
TARGET2:
test -e FOO && $(make) TARGET3
27-06-2006 17.52

Inference Rules

Statt lauter Regeln wie diese aufzustellen:
foo.obj: foo.c
$(CC) foo.c -o foo.obj

bar.obj: bar.c
$(CC) bar.c -o bar.obj

....obj: ....c
$(CC) ....c -o ....obj
Kann man auch das schreiben:
%.obj: %.c
$(CC) $< -o $@
$@ Aktuelles TARGET
$(@F) Dateiname (ohne Pfad) des aktuellen TARGETS
$< Aktuell erstes TARGETSOURCE
$^ Alle aktuellen TARGETSOURCES
$? Aktuelle TARGETSOURCES die sich geändert haben
20-05-2007 00.10

Macros

VAR1 = foo bar
VAR2 = bar $(VAR1)

Macro Modifiers

Alle ".obj" in VAR1 mit ".c" ersetzen:
VAR2 = $(VAR1,.obj=.c)
VAR4 = $(VAR3:foo%.obj=bar%.c)
24-11-2006 00.21

Aufruf

Ohne Ausgaben:
make -s
make TARGET:
make TARGET
06-08-2005 13.09

Beispiel

# Enforce that $CC contains a valid compiler
ifndef CC
CC=g++
endif

# Some variables that our compiler understands
CFLAGS=-c -Wall -O2
LDFLAGS= -L/usr/X11R6/lib -lGLU -lGL -lglut -lm

# List of all source files
SOURCES=myprg.cpp file1.cpp file2.cpp

# Replace .cpp with .h the get the header files names
HEADERS=$(SOURCES:.cpp=.h)

# Replace .cpp with .o the get the object file names
OBJECTS=$(SOURCES:.cpp=.o)

# Name of our binary
EXECUTABLE=myprg_bin

.PHONY: all
all: $(SOURCES) $(EXECUTABLE)

$(EXECUTABLE): $(OBJECTS) $(HEADERS)
$(CC) $(LDFLAGS) $(OBJECTS) -o $@

%.o: %.cpp
$(CC) $(CFLAGS) $< -o $@

.PHONY: clean
clean:
-rm *.o
-rm *~
-rm $(EXECUTABLE)
06-08-2005 13.09

Links

GNU MAKE
27-06-2006 07.04
Powered by PHP Created with Xemacs Valid XHTML 1.0! Valid CSS!