Use the same makefile for make (Linux) and nmake (Windows)

前端 未结 8 1309
星月不相逢
星月不相逢 2020-12-13 19:26

I have a simple C program (one source file) which I want to compile on Linux and on Windows via make and nmake, respectively. Is there a possibility to accomplish this with

8条回答
  •  温柔的废话
    2020-12-13 20:17

    Yes, you can do this with a single Makefile. The best source for this material is the O'Reilly book:

    Managing Projects with GNU Make, Third Edition By Robert Mecklenburg

    See chapter 7: Portable Makefiles.

    In summary, the technique is to test the environment variable ComSpec which says if the Windows command interpreter is present:

    ifdef COMSPEC
      MV ?= move
      RM ?= del
    else
      MV ?= mv -f
      RM ?= rm -f
    endif
    

    I wrap this with a portable shell script which uses sed to edit the makefile for Nmake or GNU make...

提交回复
热议问题