PROGRAM = hello_world
# Define the source files that will be distributed in the tarball
-SOURCE = *.cpp COPYING Makefile README
+SOURCE = *.c COPYING Makefile README
# Define a list of object files needed to link PROGRAM
OBJECTS = $(PROGRAM).o
# target: hello_world - compile the hello_world program
# Use GCC to link the program from object files.
$(PROGRAM): $(OBJECTS)
- $(CXX) $(LDFLAGS) -o $@ $^ $(LIBS)
+ $(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
# target: run - use the program for its intended purpose
# Here we just execute PROGRAM, but you could also use something like
# $ make CXX=/usr/local/bin/g++ CXXFLAGS=-Wall
%.o: %.cpp
$(CXX) $(CXXFLAGS) -c $<
+
+# Matching rule for compiling object files from C source
+# The comments from the C++ rule above also apply here
+%.o: %.c
+ $(CC) $(CFLAGS) -c $<
/*
-A simple "hello world" example in C++.
+A simple "hello world" example in C.
Copyright (C) 2012 W. Trevor King
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <iostream>
-
-using namespace std;
+#include <stdio.h>
int main() {
- cout << "hello, world\n";
+ printf("hello, world\n");
return 0;
}