PDA

View Full Version : makefile without using QMake



Rayven
8th September 2006, 03:17
I am developing a multi-language application (c, c++, FORTRAN and soon Java...hopefully), and used qmake only once to create the makefile. Since then, I have been just updating the makefile each time by hand. I am trying to get the makefile to be able to handle generic filename redirections i.e (this is an example from the net, not my actual makefile...):



CXX=g++
CC=gcc
FC=pgf77
CFLAGS=-c -Wall
FFLAGS=
LDFLAGS=
SOURCES=main.cpp hello.cpp factorial.f
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=hello

:
:

all: $(SOURCES) $(EXECUTABLE)

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

.cpp.o:
$(CXX) $(CXXFLAGS) $< -o $@

.c.o:
$(CC) $(CFLAGS) $< -o $@

.f.o:
$(FC) $(FFLAGS) $< -o $@

#Steps for moc...
???


and moc the correct Q_OBJECT files at the same time. I have created a variable call MOC_FILES that lists all the files to be moc'd but each time I try and create a generic moc rule, nothing compiles. I am "so-so" at makefiles, and was wondering if anyone has sucessfully done this? Also, I am not using UI files or Project (.pro) files in Qt. I am writing all code by hand.

jacek
8th September 2006, 10:56
http://doc.trolltech.com/4.1/moc.html#writing-make-rules-for-invoking

cjtsai
6th April 2010, 23:04
Here is an example of modified `makefile` based on the `Makefile` generated by Qmake under Qt/4.6.2/examples/opengl/textures.


prog = f90main

F90 = gfortran
F90FLAGS = -m32 -O1 -ffree-line-length-0 -ffree-form

LINK = gfortran

f90Objects = f90main.o

Qt = /mingw/Qt/4.6.2

CC = gcc
CXX = g++
DEFINES = -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_EVAL -DQT_DLL -DQT_NO_DEBUG -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN
CFLAGS = -m32 -O2 -Wall $(DEFINES)
CXXFLAGS = -m32 -O2 -frtti -fexceptions -mthreads -Wall $(DEFINES)
INCPATH = -I'c:/minGW/Qt/4.6.2/include/QtCore' -I'c:/minGW/Qt/4.6.2/include/QtGui' -I'c:/minGW/Qt/4.6.2/include/QtOpenGL' -I'c:/minGW/Qt/4.6.2/include' \
-I'c:/minGW/Qt/4.6.2/include/ActiveQt' -I'tmp/moc/release_shared' -I'c:/minGW/Qt/4.6.2/mkspecs/win32-g++'

LFLAGS = -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-s -mthreads -Wl -Wl,-subsystem,windows
LIBS = -L'c:/minGW/Qt/4.6.2/lib' -L'c:/minGW/Qt/4.6.2/lib' -lstdc++ -lopengl32 -lglu32 -lgdi32 -luser32 -lmingw32 -lqtmain -lQtOpenGL4 -lQtGui4 -lQtCore4

####### Files
SOURCES = qtmain.cpp glwidget.cpp window.cpp moc_glwidget.cpp moc_window.cpp
OBJECTS = qtmain.o glwidget.o window.o moc_glwidget.o moc_window.o qrc_textures.o
TARGET = $(prog).exe

MOC = $(Qt)/bin/moc

####### Implicit rules
.SUFFIXES: .o .c .cpp .cc .cxx .C .f .h

.f.o:
$(F90) -c $(F90FLAGS) $(F90INCPATH) -o $@ $<

.cpp.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"

.cc.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"

.cxx.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"

.C.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
.c.o:
$(CC) -c $(CFLAGS) $(INCPATH) -o "$@" "$<"


####### Build rules
$(TARGET): $(f90Objects) $(OBJECTS)
$(LINK) $(LFLAGS) -o $(TARGET) $(f90Objects) $(OBJECTS) $(LIBS)

####### moc
moc_glwidget.cpp: glwidget.h
$(MOC) $(DEFINES) $(INCPATH) glwidget.h -o moc_glwidget.cpp

moc_window.cpp: window.h
$(MOC) $(DEFINES) $(INCPATH) window.h -o moc_window.cpp

####### rcc
RCC = $(Qt)/bin/rcc
qrc_textures.cpp: textures.qrc images/side4.png images/side5.png images/side6.png images/side1.png images/side2.png images/side3.png
$(RCC) -name textures textures.qrc -o qrc_textures.cpp

moc_glwidget.o: moc_glwidget.cpp window.h
moc_window.o: moc_window.cpp window.h

all: $(TARGET)

clean:
rm *.o
rm moc*.cpp