Skip to content

Instantly share code, notes, and snippets.

@mishurov
Last active April 9, 2024 21:06
Show Gist options
  • Star 22 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mishurov/8134532 to your computer and use it in GitHub Desktop.
Save mishurov/8134532 to your computer and use it in GitHub Desktop.
Makefile to build QT projects (Linux) without qmake
CC=g++
MOC=moc-qt4
CFLAGS=-Wall
SOURCES=hello.cc hello_cls.cc
MOC_HEADERS=hello_cls.h
EXECUTABLE=hello
INCDIRS=-I/usr/include/qt4 -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtCore
LIBS=-lQtCore -lQtGui
# Change postfixes
MOC_SOURCES=$(MOC_HEADERS:.h=.moc.cc)
OBJECTS=$(SOURCES:.cc=.o) $(MOC_SOURCES:.cc=.o)
all: $(EXECUTABLE)
@echo Done!
$(EXECUTABLE): $(OBJECTS)
$(CC) $^ $(LIBS) -o $@
# Generate object files, rule to change postfix
%.o: %.cc
$(CC) $(CFLAGS) $(INCDIRS) -c $< -o $@
# Generate cc from h via Qt's Meta Object Compiler, rule to change postfix
%.moc.cc: %.h
$(MOC) $(INCDIRS) $< -o $@
.PHONY: tags clean
clean:
rm *.o
# Generate ctags file for all included files (autocomplete and jump to source)
tags:
gcc -M $(INCDIRS) $(SOURCES) | \
sed -e 's/[\\ ]/\n/g' | \
sed -e '/^$$/d' -e '/\.o:[ \t]*$$/d' | \
ctags -L - --c++-kinds=+p --fields=+iaS --extra=+q
@mishurov
Copy link
Author

mishurov commented Aug 7, 2023

Why even ask that. Sure, of course. I'm not a lawyer. Everything I share, it is for public use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment