Subject: Re: [boost] mkmakefile
From: Seth (bugs_at_[hidden])
Date: 2018-04-05 02:30:28
On 01-04-18 17:13, Ggh via Boost wrote:
> wondering...if I'm reinventing the wheel ( again as many do)....I
> guess there's loads of similar stuff
Similar to what? Shell scripts that write a makefile?
Also, your link was broken. The fixed link leads to incomplete code (
YouÂ don't state the target implementations (just GNU make? what
versions?), features required, features already supported, etc.
I think what I've seen is trivial. I'm not at all convinced that
cramming the options all on some command line to be parsed by a ...
questionable script is better than writing the equivalent makefile (or
Makefile.am, m4 template or CMakeLists.txt, ... if you intend to
generate the makefile).
The code is... what I'd call bad code. You should probably have posted
it for review instead (https://codereview.stackexchange.com/ e.g.).
It fails to use all the conventions in place to make Makefiles
maintainable. You subvert default variable naming (CC for CXX, really?).
Here's the same program converted to actual C++ - in 306 lines of code
(instead of the incomplete 560 lines):
Now note that *LOTS* of things have been fixed with respect to quoting
of path names, but lots of things still don't work (no way to pass
compiler/linker flags, static libraries aren't built (because the target
rule was wrong), static libraries cannot link (because it needs position
indepent code, but, again, compiler flags cannot be passed), the linker
is always using `g++` instead of `gcc` even if all source files were
compiled with the C compiler etc.
To fix things, I cleaned things up **A LOT** MORE:
Now the code is 351 lines of code, but actually organized (you could
split headers and implementations here), it has actually working
Â Â Â
Â Â Â Â - STATICLIBTARGET and LIBTARGET
Â Â Â Â - much simplified rules
Â Â Â Â - dependency detection / creation
Â Â Â Â - using OBJS instead of hardcoding names and even `*.o` (ugh)
Â Â Â Â - separating discover_sourcefiles, generate_makefile, run_make
Â Â Â Â - deduceLinker (instead of using g++ to link C programs...)
Â Â Â Â - allow for compiler flags
Â Â Â Â - don't repeat includes and libraries with each (intermediate) target
A screenshot of interactively bootstrapping the program using itself:
https://imgur.com/a/AlYRz, using the command line:
./bootstrap/mymakemaker -hd -t mymakemaker -cxxflags -std=c++1z -tt exe
-wd bootstrap -mk -cc 'clang++' -i ~/custom/boost -L
~/custom/boost/stage/lib/ -l boost_program_options -l stdc++fs
Reading directory:Â Â Â "bootstrap"
Creating makefile:Â Â Â makefile.mk
"clang++"Â -I"/home/sehe/custom/boost" -MMDÂ Â Â -std=c++1z -c test.cpp -o
"clang++"Â -I"/home/sehe/custom/boost" -MMDÂ Â Â -std=c++1z "./test.o"Â Â
-l"stdc++fs" -o "mymakemaker"
The resulting generated makefile looks like
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk