Here are some interesting articles and tips related to the C preprocessor and to creating makefiles.


This shows how to print the value of a macro:
http://c-faq.com/ansi/stringize.html

How to use static patterns with makefiles:
https://www.gnu.org/software/make/manual/make.html#Static-Pattern


Preprocessor tips:
The second article shows how to check which include files are used by a C or C++ file.

https://mischasan.wordpress.com/2013/04/07/the-c-preprocessor-not-as-cryptic-as-youd-think/
https://mischasan.wordpress.com/2011/06/14/stupid-gcc-trick-2-finding-all-included-files-recursively/
https://mischasan.wordpress.com/2011/10/12/stupid-gcc-trick-3-list-all-built-in-gcc-define-symbols/


Make tips:
The first article has a great tip for creating directories in makfiles using "%/..:".

https://mischasan.wordpress.com/2012/07/05/two-more-cheap-gmake-tricks-creating-directories-and-printing-variables/
https://mischasan.wordpress.com/2015/03/09/gmake-cheap-trick-3/
https://mischasan.wordpress.com/2015/03/21/gmake-cheap-trick-4-for-non-recursive-make/

To see what commands make will run when invoked, you can use:
make --just-print


Nonrecursive makefile tips:

https://mischasan.wordpress.com/2013/03/30/non-recursive-make-gmake-part-1-the-basic-gnumakefile-layouts/
https://mischasan.wordpress.com/2013/03/30/non-recursive-make-gmake-part-2-rules-mk/
https://mischasan.wordpress.com/2013/04/13/non-recursive-make-part-3-a-tool-for-the-fearless/


Replacing other utilities with sed:

In case you need these in a makefile, build script or elsewhere and don't have them on your system:

https://github.com/aureliojargas/sed.sf.net/blob/master/local/docs/emulating_unix.txt


Miscellaneous compiler tips:

To stop the gnu gcc compiler after the first error use:
-Wfatal-errors

To stop the gnu gcc compiler after the N errors use:
-fmax-errors=N
So for three errors add the following to the command line when invoking gcc:
-fmax-errors=3


My favorite preprocessor tips:

You can use a C preprocessor to generate templates.
Here's an example to generate web pages using the preprocessor and templates:
http://www.distasis.com/cpp/mingw.htm#makeprograms

For my build system, I need a more functionality than the standard C preprocessor could offer.
Rather than reinventing the wheel and writing my own preprocessor, I found gpp has just enough capabilities beyond a standard preprocessor to handle the task.
The gpp preprocessor is available from:
https://logological.org/gpp


Know of some other preprocessor or makefile tips? Have written an article or blog post with your tips on these topics? Please share them. They may get included in this list.

MinGW

May. 5th, 2016 12:29 pm
There are now several forks of MinGW and each has its pros and cons. However, there are now enough negatives to using them, that I've found it necessary to build MinGW from scratch myself. The MinGW64 project uses a later version of gcc, has better compatibility for building Open Source projects and has its own thread library instead of using Red Hat's pthreads-w32. Some custom builds of MinGW64 even have POSIX threading set as the default instead of Win32 threading. That means better compatibility for C++ thread related code (since the GNU C++ library relies on POSIX threading for parts of its implementation). The MinGW project has always been more careful about licensing and making sure that the code it was using was properly licensed and legal for usage. The MinGW project did follow the example of the MinGW64 project in one key area. They switched from public domain to a MIT license for their runtime library and Win32 API. When they did so without clearly indicating that an exception could be made similar to the GNU gcc runtime license exception, I felt it was time to stop using that version of the MinGW compiler.

I'm currently working with gcc 4.9.2 compiled from source. I'm still using the older public domain APIs, but I've made several modifications for compatibility with the Win32 API (including some modifications that aren't available in the MinGW64 libraries). I have a minimal thread library that was custom written for portability. It's based on C11 thread support and includes POSIX functionality. The gnu compiler is built with POSIX threads as the default so C++ threading works as expected.

So far, I've had no reason to want to work with any other MinGW forks. The version I have does everything I need and supports all the programs I want to compile on Windows. My particular fork is continually evolving. I continue to add support for new Win32 API changes, Win32 API omissions, new C/C++ features as I need them. At some point, I hope to completely replace the runtime library with code that better supports internationalization (better UTF-8 support), C standard compatibility and other useful features.

If anyone else is finding limitations with the compilers maintained by the various MinGW and MinGW64 projects or other related forks based on these projects, I highly recommending building the GNU compiler from source on your own with the options you need most. If you're interested in discussing the GNU compiler further or want to know more about my modifications, you're welcome to use the CppDesign mailing list ( http://groups.yahoo.com/group/CppDesign ) as a forum for further discussion.

July 2025

S M T W T F S
  12345
67891011 12
13141516171819
20212223242526
2728293031  

Syndicate

RSS Atom

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Aug. 4th, 2025 02:22 am
Powered by Dreamwidth Studios