[IPOL discuss] New tool to create Makefiles

Miguel Colom Miguel.Colom at cmla.ens-cachan.fr
Tue Oct 25 11:43:13 CEST 2011


> Good idea, I think it is helpful. Maybe mention it in the wiki?

Thank you very much for your improvements in the script, Nicolas.

I've also done the following over your modified code:
- Remove the CPPFLAGS variable.
- Use "find" command to search C/C++ files over sub-directories, instead
of simply on the current directory.
- Added a GNU/GPL header in the script, instead of doing so in the
generated Makefile.

The updated script can be downloaded:
http://dev.ipol.im/~colom/tools/create_makefile.sh

Best,
Miguel

> I want to suggest some modifications:
>
> * use default GNU make variables:
>   - CC and CXX as the compilers, not gcc and g++. CC and CXX are
>     always set to the default compilers, and can be redefined for
>     other compilers when we call make: make CC=clang
>   - CPPFLAGS for the C preprocessor options
>   - CFLAGS/CXXFLAGS for the C/C++ compiler options
>   - LDFLAGS for the link options
>   ->
> http://www.gnu.org/software/automake/manual/make/Implicit-Variables.html
>
> * for the default make target, only use standard compiler option. -Ox
>   works on every compiler I know, -fomit-frame-pointer doesn't. With
>   standard compiler options, it should work on any system (at least
>   Linux and Mac) without needing to touch the makefile.
>
> * handle the optimization flags in a specific variable, so I can
>   override it: make COPT="-O3 -ffast-math -fomit-frame-pointer"
>
> * put the "strict compilation flags" in another specific variable, and
>   only use them for a specific make target (I use "lint" in my
>   makefiles), because these options are note portable across
>   compilers
>
> * explicitely mention the output file name in every compiler
>   invocation
>
> * add the link flags (-lpng...) after the object names in the link
>   step, the order matters
>
> * use the C++ compiler to link the object files it there were some C++
>   source files, otherwise use the C compiler
>
> * "make clean" only removes the temporary files, "make distclean" also
>   removes the executable
>
> * use "default" as the default make target, and "all" as the "complete
>   build" make target
>
> * run this script with /bin/sh, /bin/bash is not required
>
> * I think that in your script, the user choices for the compiler
>   options are not used (cf. lines 60 and 61)
>
> * I think shell command capture is easier to understand with
>   $(parenthesis) than with `backquotes`, but it's probably just a
>   matter of personal taste
>
> * I also think you should include a license statement for your script,
>   not for the makefiles generated by your script.
>
> I wrote all that (excepted the license part) in an updated version
> proposed in attachment to this message.
>
> 8<----------8<----------8<----------8<----------8<----------8<----------
>
> I also attach a generic Makefile that does similar things. It is
> not as user-friendly as your script, because one has to understand the
> make syntax to customize it, and it uses lots of make shortcuts to
> avoid redundancy, but it can help people who know this syntax to start
> with their projects.
>
> The C/C++ source files are detected with the $(wildcard ...) GNU make
> command. The dependencies are automatically generated with $(CC) -MM[1].
> The default targets should work with any compiler. Two special targets
> are available:
> - make lint, to check the ANSI compliance of your code
> - make debug, to generate an executable with debugging info
>
> You will need to customize at least two variables: BIN (your
> executable output) and LDLIBS (external libraries). Then use it with
> these invocations (can be used combined):
>
> - build/rebuild the program
>   make
>
> - force rebuild
>   make -B
>
> - cleanup everything
>   make distclean
>
> - build with another compiler and options
>   make CC=my_c_compiler CFLAGS="my_c_flags"
>
> - build with optimization options
>   make CC=gcc COPT="-O3 -ffast-math -ftree-vectorize-ftree -funroll-loops"
>
> - build for debugging
>   make debug
>
> - check the source
>   make lint
>
> Hidden bonus: you can add "make -B lint; make distclean" in your git
> hooks (.git/hooks/pre-commit) to automatically check all the code you
> record in git.
>
> [1] This option is understood by gcc-compatible compilers, including
> icc and clang, but not by suncc.
>
> --
> Nicolas LIMARE - CMLA - ENS Cachan
> http://www.cmla.ens-cachan.fr/~limare/
> IPOL - image processing on line
> http://www.ipol.im/
> _______________________________________________
> discuss mailing list
> discuss at list.ipol.im
> http://tools.ipol.im/mailman/listinfo/discuss




More information about the discuss mailing list