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

It's probably not impossible, but most likely so hard that it would be easier to write two makefiles anyway.

Both GNU make (used in Linux) and nmake have include directives though, so some common things can be put in a common makefile that is included by the main makefile.


You should look at using CMake for this. With one source file, it should be quite easy. Here is how you could set up a simple project:

cmake_minimum_required(VERSION 3.10)

# set the project name
project(Hello)

# add the executable
add_executable(Hello hello.c)

To build the simple project, you would do the following (this assumes your source and CMakeLists.txt files are in the same directory as the source file hello.c:

mkdir build
cd build
cmake ..
cmake --build .

Tags:

C

Makefile

Nmake