Thread: Makefiles
View Single Post
  #3   (View Single Post)  
Old 18th October 2008
mdh's Avatar
mdh mdh is offline
Real Name: Matt D. Harris
FreeBSD 2.2.6 User
 
Join Date: Oct 2008
Location: West Virginia
Posts: 139
Default

Here's the template Makefile I use for small stuff that doesn't require any sort of templating such as autoconf:
Code:
# CONFIG
CC=gcc
CFLAGS=-O -march=CHANGEME -pipe -I/usr/local/include
DFLAGS=-Wall -Wno-long-long -Wno-unused-variable -Wno-unused-value -ggdb
#DFLAGS=-Wno-long-long -Wno-pointer-sign
ENV=FREEBSD
LIBS=
BINARY=X
# /CONFIG

SRC=X1.c X2.c
OBJ=${SRC:%.c=%.o}

.c.o:
        $(CC) $(CFLAGS) $(DFLAGS) -DOS_$(ENV) -c $<

all:    $(OBJ)
        $(CC) $(CFLAGS) $(DFLAGS) -o $(BINARY) $(OBJ) $(LIBS)

build:  all

clean:
        rm -f $(OBJ) $(BINARY)

X1.o:       X1.c X1.h proj.h
X2.o:         X2.c X2.h proj.h
This will produce an application binary ``X'' from C source code files `X1.c' and `X2.c'. Just change CC to g++ and the .c to .cpp, then add lines for your files (at the bottom) plus add them to the SRC variable (whitespace delimited).

Hope this helps.
Reply With Quote