Help with a makefile I wrote

Oct 21, 2016 at 10:08am
Hello guys, I'm writing a c++ program using qt5 libraries.
I wrote this makefile (https://github.com/AlexK-IL/csti/blob/346376369e143374cc079442bfaf7faf72ccb458/Makefile) and wanted to consult with you if I wrote it properly.
I used these links for reference of how to make a makefile:
https://wiki.archlinux.org/index.php/qt#C.2B.2B
http://stackoverflow.com/a/2481326

It's important to mention that I intend for this program to be cross platform.
Oct 21, 2016 at 11:54am
Makefiles are not cross-platform.

Create a Qt's qmake project-file. Then you can use qmake to generate a platform-specific Makefile.
Oct 21, 2016 at 12:24pm
A makefile is a description of how to build something. I would argue that saying it's not "cross-platform" is like saying a text file is not cross-platform; you can use it on any system for which you have a Make programme that reads standard makefiles (noting that a GNU Makefile is not quite standard, so on some systems a GNU Makefile needs altering into a standard Makefile). Such as these operating systems:

Windows: http://www.equation.com/servlet/equation.cmd?fa=make
Linux: https://www.gnu.org/software/make/
BSDs have BSD make.
Haiku: cgit.haiku-os.org/buildtools/ (there's a make in there)
OSX: Has a GNU Make implementation
Solaris has one, I recall.




Last edited on Oct 21, 2016 at 12:26pm
Oct 21, 2016 at 1:06pm
Lets say that a Makefile starts:
CXX           = g++
DEFINES       = -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED
CXXFLAGS      = -pipe -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -O2 -Wall -W -D_REENTRANT $(DEFINES)

The variables CXX and CXXFLAGS are then used in rules that generate object files from source files.

I cannot copy this as is into OSX, Windows, or another Linux box, because on those the compiler isn't GCC, but Clang, MSVC, or Intel. The file content isn't portable even though each platform has a 'make' utility.

There is an another set of tools, like GNU build system, CMake, and qmake that have their own (ascii) project description format, and that are available on many platforms. When you run one of these on a platform, it looks up what make you have, what C++ compiler you have, etc and writes approriate
CXX = ...
CXXFLAGS = ...

Oct 21, 2016 at 3:22pm
I got it to work with qmake and it's much simpler.
Also it's cross platform like you said.
Thank you.
Oct 21, 2016 at 9:03pm
Lets say that a Makefile starts: ...


I don't disagree with anything you say. That doesn't change the fact that a makefile is a textfile and to say it's not cross platform makes no sense.It's a plain textfile. It's as cross platform as it's possible to get. Executables aren't cross platform. Plain textfiles are almost universal.

qmake isn't cross platform. You need a different qmake executable for every platform you run it on, and it produces output that is decidedly non cross-platform; it might produce a VS2015 project definition. How cross-platform is that? qmake is less cross-platform than a makefile.


I cannot copy this as is into OSX, Windows, or another Linux box, because on those the compiler isn't GCC,

Yes they are. Or rather, GCC is certainly available for every one of those platforms. If you choose to use a different compiler, that's your choice, but to say that on those platforms the complier isn't GCC purely because you chose for it not to be seems very dishonest.

or another Linux box

What Linux box are you using that doesn't have GCC available?

All that said, this is another ridiculous conversation on cplusplus.com sparked by a careless use of a technical term. Both of us wasting our own time and each others. Maybe eventually we'll learn.
Last edited on Oct 21, 2016 at 9:22pm
Topic archived. No new replies allowed.