3 ms·
Usability.
by jplayer01 8y ago
Usability.
- enriquto 8y agoI find gnu make very usable and very clear on its purpose. Sometimes I have used cmake and it was uglier, more complicated, and harder to understand. What would you suggest as a modern, usable build system?
- jcelerier 8y ago> Sometimes I have used cmake and it was uglier, more complicated, and harder to understand. okay, please provide a makefile which: * detects if, say, libpng is available * compile a library, an executable and a unit test if that's the case * links the executable to the library and the library to libpng * does so for mac, windows, linux, creates a .app for mac, an installer for windows, a .deb package for linux * can be used from IDEs, with IDEs understanding where your code has to be fetched, what the includes are, etc here's more-or-less the CMake version : project(myapp) find_package(PNG REQUIRED) add_library(mylib lib.c) add_executable(myapp MACOS_BUNDLE WIN32 app.c) target_link_libraries(mylib PRIVATE PNG::PNG) target_link_libraries(myapp PRIVATE mylib) install( TARGETS myapp mylib RUNTIME DESTINATION bin ARCHIVE DESTINATION lib) include(CPack) you can't seriously say that this (which covers an immense part of software project needs) is easier to do in make, right ?
- enriquto 8y ago> * detects if, say, libpng is available You just compile with -lpng. If libpng is available, it will work, otherwise it will fail with a clear error message. What else do you need? > * links the executable to the library and the library to libpng LDLIBS = -lpng BIN = foo bar baz OBJ = lib1.o lib2.o lib3.o LIB = libmine.a default : $(BIN) $(LIB) $(BIN) : $(OBJ) $(LIB) : $(LIB)($(OBJ)) clean : ; $(RM) $(BIN) $(LIB) $(OBJ) check : $(BIN) ; ./foo -test This will compile the code from lib*.c into libmine.a, and then compile the source code of a few test executables from foo.c, bar.c and baz.c The .a is useless often, but there you have it just in case. Otherwise, just remove all references to $(LIB) and get a shorter makefile. > you can't seriously say that this (which covers an immense part of software project needs) is easier to do in make, right ? This is rather subjective. In my case the makefile seems easier. It will work for all unices, but probably not for windows, and will not create an "app" package, your are right about that. But the makefile covers indeed all my personal needs, and it is much more powerful and easier to use than the cmake/make combo. For example, you can test multiple compilers and compiler options with a shell loop: # test all compilers in debug and release modes for i in gcc clang tcc icc; do for m in "-O3 -DNDEBUG" "-g"; do make clean check CC=$i CFLAGS=$m done done doing that in cmake would be a nightmare, wouldn't it?
- jcelerier 8y ago> You just compile with -lpng. If libpng is available, it will work, otherwise it will fail with a clear error message. What else do you need? well, no you don't "just compile", because one of the most used compilers out there does not support "-l". Also because you may have multiple libpng versions on your machine - debug, with special testing flags, in your ~/work/libpng_build, etc. Also, you may have libpng.so but not the headers. You may be compiling on Nix or GoboLinux or whatever system which does not respect the FHS. It won't work as is on OS X because you have to add -L/usr/local/lib. Users won't know what to do when they see whatever missing include error the compiler spits out. > doing that in cmake would be a nightmare, wouldn't it? .. it would be mostly the same than your example ? just tested and this works fine (normal practice with cmake is to build outside of src which helps): for i in gcc clang; do for m in "-DCMAKE_BUILD_TYPE=Debug" "-DCMAKE_BUILD_TYPE=Release"; do #not using -g because that's something compiler-specific rm -rf ** ; CC=$i cmake ../ $m ; cmake --build . done done
- enriquto 8y agoThanks for your answer, I see that cmake is not as cumbersome as I thought. > Also, you may have libpng.so but not the headers. Then how on earth are you supposed to compile it? You write the definitions verbatim on your code? > It won't work as is on OS X because you have to add -L/usr/local/lib. For that case it is better to not mess with compiler options and set up the compiling environment so that -lpng works, e.g. by setting LIBRARY_PATH=/usr/local/lib, and similarly for C_INCLUDE_PATH. These variables are recognized by all unix linkers and compilers that I care about. Of course, this attitude may not be appropriate for everyone. Yet, I am in the happy position to be able to say say "this program requires gcc, clang, tcc or icc to be compiled, otherwise, please edit the makefile to suit your needs". Are there really other C compilers around? (notice that visual studio is not a C compiler, and cannot compile modern C code, so it does not enter into the discussion if you are a C programmer).
- jcelerier 8y ago> Then how on earth are you supposed to compile it? You write the definitions verbatim on your code? what I mean is that an user might download your source archive, run `make`, and have hard-to-understand failures because of this.