Search notes:

Detect operating system (Windows vs Linux) with a Makefile

The following Makefile uses $(OS) to determine the OS and uses ifeq to either assign a.exe (Windows) or a.out (Linux) to a variable that stores the name of the executable.
ifeq ($(OS), Windows_NT)
	EXECUTABLE=a.exe
else
	EXECUTABLE=a.out
endif


$(EXECUTABLE): prog.c
	gcc prog.c
Github repository about-Makefile, path: /detect-os/Makefile
For completness' sake, here's a minimal c program, too:
int main() {
    return 42;
}
Github repository about-Makefile, path: /detect-os/prog.c

See also

make

Index