title: Makefiles and cross platform development
body: <p>I have been trying to figure out how to create a C program that can be compiled for all of the major operating systems. I have considered using makefiles so I would just have to change the target OS, but I have a few problems. My first problem is that I cannot figure out how to change the target OS so I can compile on one OS but use the application on all OS's. My second issue is that I cannot figure out how to make it automatically compile all .c files in the src directory, so I do not have to modify the makefile every time I add a new file. Does anybody know how to do this stuff?</p>
  
  <p>My current makefile (currently unmodified from <a href="http://mrbook.org/tutorials/make/" rel="noreferrer">here</a>)</p>
  
  <pre><code>CC=gcc
  CFLAGS=-c -Wall
  LDFLAGS=
  SOURCES=main.cpp hello.cpp factorial.cpp
  OBJECTS=$(SOURCES:.cpp=.o)
  EXECUTABLE=hello
  
  all: $(SOURCES) $(EXECUTABLE)
  
  $(EXECUTABLE): $(OBJECTS) 
      $(CC) $(LDFLAGS) $(OBJECTS) -o $@
  
  .cpp.o:
      $(CC) $(CFLAGS) $&lt; -o $@q2
  </code></pre>