Red Antigua Logo
Yet another piece of web.
Ads by Goooooogle
Search this site (by Google)
Tools    (top)
Your IP
Check a site for broken links
(W3C)

Perl modules    (top)
Tree::Numbered::Tools
(CPAN)
Perl tutorials    (top)
Perl modules
HTML::Template
CGI::Application
Mail::POP3Client
Mail::Send
MIME::Tools
Cookies with CGI::Application
Upload files with CGI::Application
Download files with CGI::Application
Redirect with CGI::Application
CPAN shell
Install DBD::mysql from the CPAN shell
Perl trim function
Validate an IP with Perl
Run suid Perl scripts under Apache
Perl taint mode
Perl date functions with Date::Calc

In Spanish
Curso de Perl

C tutorials    (top)
C - Introduction
C - Absolute beginner's Emacs
C - Examples for beginners
C - Makefile examples
C - Autotools examples
Server configurations    (top)
DNS
Apache
Apache Authentication and Access Control
mod_perl on FreeBSD
MySQL
MySQL add account
phpMyAdmin
Squid
DHCP

UNIX on Windows    (top)
Apache setup on Windows
MySQL setup on Windows
PHP setup on Windows
Perl setup on Windows
Emacs setup on Windows
UnxUtils
PuTTY
WinSCP
GIMP on Windows
MinGW - gcc on Windows
MSYS - UNIX-styled shell on Windows
msysDTK - autotools on Windows
GDB for MinGW on Windows

Misc. FreeBSD/UNIX    (top)
CD and DVD creation on FreeBSD using 'k3b' on FreeBSD
'portupgrade' on FreeBSD
'ipf' on FreeBSD
'pf' on FreeBSD
'su' on FreeBSD
Mount an ISO image under FreeBSD
Load the correct sound driver under FreeBSD without knowing what sound card you are using
Simultaneous sound channels on FreeBSD
FreeBSD network stuff
DOS-to-UNIX file conversion
favicon.ico on UNIX
Emacs tips
Sendmail tips
GKrellm
Command Line Calculator
Save multimedia streams with 'mplayer'
xargs - solution to 'Argument list too long'
Process multiple images from the command line using 'ImageMagick'
Turn the system bell off under X Windows
Process each line in an input file from the command line (or in a shell script)
How to keep a program running in the background using 'nohup'
How to remove symbolic links in the current directory using 'find' and 'rm'
How to remove Emacs backup files in the current directory and all subdirectories using 'find' and 'rm'
How to execute .profile without logging in
Configure X to handle non-English characters
How to move /var to /usr/var

Redirect a web page    (top)
Redirect to another web page
Apache redirect
C redirect
Perl redirect
PHP redirect
HTML redirect
JavaScript redirect

Javascript    (top)
Trim function
Login form
Register form
Popup window

Virus list    (top)
Latest 10 viruses - Sophos

Off topic    (top)
Personal home links

A platform portable Makefile example
A portable Makefile example, which autodetects the platform, and which is both BSD and GNU make compatible.
Currently supported platforms are FreeBSD, Linux, MS Windows (MinGW), and Mac OSX (not tested on Mac OSX, though).
IndexPreviousNext

The Makefile compiles some sample audio applications, so you need to modify it to fit your needs.
# This is a Makefile trying to be platform-independent, and has been tested both with GNU and BSD Make syntax.
# The Makefile syntax in this file is very basic, which works for small and simple projects like this one, and is used to avoid the overhead of using tools such as autoconf/automake.
# However, projects which requires more advanced Makefile features should probably either use tools as autoconf/automake, or create and distribute a platform-specific Makefile (using either GNU or BSD syntax) for each platform target.


# APPLICATION
PROG = loopback
OBJS = \
loopback.o
HEADERS = dbg.h loopback.h

# APPLICATION 2
PROG_MATH2WAV = math2wav
OBJS_MATH2WAV = \
dbg.o \
byte.o \
void.o \
buf.o \
mathwave.o \
math2wav.o \
audiofreq.o 
HEADERS_MATH2WAV = \
dbg.h \
byte.h \
void.h \
buf.h \
mathwave.h \
math2wav.h \
audiofreq.h 

# APPLICATION 3
PROG_NEWWAVE = newwave
OBJS_NEWWAVE = \
dbg.o \
byte.o \
mathwave.o \
void.o \
buf.o \
newwave.o
HEADERS_NEWWAVE = \
newwave.h

# PROGRAMS
CC    = gcc
CPP   = g++
ETAGS = etags
ETAGS_ARGS = find . -name "*.[ch]"
ETAGS_ARGS_CPP = find . -name "*.cpp"


# CFLAGS
DEBUGFLAGS = -g -DDEBUG
LANGFLAGS = -ansi -pedantic-errors
# While debugging, do not optimize.
# OPT_FLAGS = -O2
OPTFLAGS = 


# PLATFORM SPECIFIC

# --------------------------------------------------------------------------------
# FreeBSD
# --------------------------------------------------------------------------------
# OBJS_FREEBSD = playwav_oss.o
# HEADERS_FREEBSD = playwav_oss.h
INC_PATH_FREEBSD =
LIB_PATH_FREEBSD =
# http://gcc.gnu.org/onlinedocs/gcc-4.2.2/gcc/Warning-Options.html#Warning-Options
#WARNFLAGS_NOT_INCLUDED = -Wsystem-headers
# TODO: FIX -Wmissing-prototypes AND CHECK FOLLOWING FLAGS
# WARNFLAGS_FREEBSD = -Werror -Wall -Wextra -fno-strict-aliasing -pipe -Wno-format-y2k -Wextra -Wno-unused-parameter -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow -Wcast-align -Wunused-parameter -Wno-pointer-sign
WARNFLAGS_FREEBSD = -Wall -Wextra -Werror -fno-strict-aliasing -pipe
CFLAGS_FREEBSD = ${INC_PATH_FREEBSD}$(DEBUGFLAGS) $(LANGFLAGS) $(OPTFLAGS) $(WARNFLAGS_FREEBSD)
LDFLAGS_FREEBSD = ${LIB_PATH_FREEBSD} -lm # TEMP! none needed!
# --------------------------------------------------------------------------------

# Set FreeBSD as default CFLAGS and LDFLAGS
CFLAGS = $(CFLAGS_FREEBSD)
LDFLAGS = $(LDFLAGS_FREEBSD)

# --------------------------------------------------------------------------------
# Linux
# --------------------------------------------------------------------------------
OBJS_LINUX = playwav_alsa.o
HEADERS_LINUX = playwav_alsa.h
ALSA_PATH      = /usr/local
INC_PATH_LINUX = -I$(ALSA_PATH)/include
LIB_PATH_LINUX = -L${ALSA_PATH}/lib
WARNFLAGS_LINUX = -Werror
CFLAGS_LINUX   = ${INC_PATH_LINUX}  $(DEBUGFLAGS) $(LANGFLAGS) $(OPTFLAGS) $(WARNFLAGS_LINUX)
LDFLAGS_LINUX   = ${LIB_PATH_LINUX} -lalsa # TEMP! check!
# --------------------------------------------------------------------------------


# --------------------------------------------------------------------------------
# MinGW
# --------------------------------------------------------------------------------
OBJS_MINGW = playwav_dsound.o
HEADERS_MINGW = playwav_dsound.h
# Use these headers and libraries (shipped with application).
DSOUND_PATH_MINGW = /c/Documents\ and\ Settings/Johan\ Kuuse/My\ Documents/src/audio/dx
INC_PATH_MINGW    = -I$(DSOUND_PATH_MINGW)/include
LIB_PATH_MINGW    = -L${DSOUND_PATH_MINGW}/lib
# Only use these headers and libraries if DirectX SDK is installed.
# DSOUND_PATH_MS = C:\Program Files\Microsoft DirectX SDK (March 2009)
# INC_PATH_MINGW = -I"$(DSOUND_PATH_MS)\Include"
# LIB_PATH_MINGW = -L"$(DSOUND_PATH_MS)\Lib\x86"
# dsound.h contains lots of // comments, not valid for ANSI C.
# With -pedantic, but without -ansi, dsound.h compiles with warnings but not with errors.
LANGFLAGS_MINGW = -pedantic
WARNFLAGS_MINGW = -Werror
CFLAGS_MINGW   = ${INC_PATH_MINGW}  $(DEBUGFLAGS) $(LANGFLAGS_MINGW) $(OPTFLAGS) $(WARNFLAGS_MINGW)
LDFLAGS_MINGW   = ${LIB_PATH_MINGW} -ldsound -lole32 -luuid
# --------------------------------------------------------------------------------


# --------------------------------------------------------------------------------
# Darwin
# --------------------------------------------------------------------------------
# TBD
# --------------------------------------------------------------------------------


# RULES

$(PROG): all

all: portable

# debug test
dbg:
        cc -g -DDEBUG -o dbg.o -c dbg.c
        cc -g --save-temps -o dbgtest.o -c dbgtest.c
        cc -o dbgtest dbg.o dbgtest.o

# non-debug test
nodbg:
        cc -g -o dbg.o -c dbg.c
        cc -g -o dbgtest.o -c dbgtest.c
        cc -o dbgtest dbg.o dbgtest.o

# non-debug test
bufdump: bufdump.o
        $(CC) bufdump.o -o bufdump ${LDFLAGS}

# Use `uname -s` to get the platform-specific target.
# We use only the 7 first characters (cut -c 1-7) which returns 'MINGW32' instead of 'MINGW32_NT-5.1', the complete platform name.
# Other platforms are not affected by 'cut -c 1-7'. 
# Backticks are valid both in GNU make and BSD make to invoke a shell command.
portable:
        @echo ------------------------
        @echo Compiling for `uname -s|cut -c 1-7`
        @echo ------------------------
        @${MAKE} `uname -s|cut -c 1-7`


# FreeBSD (OSS)
.PHONY: FreeBSD
FreeBSD: freebsd
.PHONY: freebsd
freebsd:
        @${MAKE} common CFLAGS="$(CFLAGS_FREEBSD)" LDFLAGS="$(LDFLAGS_FREEBSD)" OBJS="$(OBJS) $(OBJS_FREEBSD)"

# Linux (ALSA)
.PHONY: Linux
Linux: linux
.PHONY: linux
linux:
        @${MAKE} common CFLAGS="$(CFLAGS_LINUX)" LDFLAGS="$(LDFLAGS_LINUX)" OBJS="$(OBJS) $(OBJS_LINUX)"

# MinGW (DirectSound)
.PHONY: MINGW32
MINGW32: mingw
.PHONY: mingw
mingw:
        @${MAKE} common CFLAGS="$(CFLAGS_LINUX)" LDFLAGS="$(LDFLAGS_LINUX)" OBJS="$(OBJS) $(OBJS_LINUX)"

# Mac OSX (Core Audio)
.PHONY: Darwin
Darwin: darwin
.PHONY: darwin
darwin:
        @echo Warning: Core Audio source code not developed yet. 
#       $(CC) $(OBJS) $(OBJS_MACOSX) -o $(PROG) ${LDFLAGS_MACOSX}

# Common rule for all targets/platforms
# http://www.wgdd.de/?p=28
# $^ does not work as a substitute for prerequisites in BSD make, so we have to repeat the $(OBJS) variable in the command.
common: $(OBJS)
        $(CC) $(OBJS) -o $(PROG) ${LDFLAGS}

math2wav: $(OBJS_MATH2WAV)
        $(CC) $(OBJS_MATH2WAV) -o $(PROG_MATH2WAV) ${LDFLAGS}

newwave: $(OBJS_NEWWAVE)
        $(CC) $(OBJS_NEWWAVE) -o $(PROG_NEWWAVE) ${LDFLAGS}

# Modified implicit C rule to handle subdirectories.
.c.o:
        $(CC) $(CFLAGS) -c $(@D)/$(<F) -o $(@D)/$(@F)

# Modified implicit C++ rule to handle subdirectories.
.cpp.o:
        $(CPP) $(CFLAGS) $(INCLUDES_MINGW) -c $(@D)/$(<F) -o $(@D)/$(@F)

# Everything is rebuilt if this Makefile (which is hopefully named "Makefile") or any header changes.
$(OBJS): Makefile $(HEADERS)
$(OBJS_MATH2WAV): Makefile $(HEADERS_MATH2WAV)
$(OBJS_NEWWAVE): Makefile $(HEADERS_NEWWAVE)

clean:
        rm -f $(PROG) $(PROG).exe $(PROG_MATH2WAV) $(PROG_MATH2WAV).exe $(PROG_NEWWAVE) $(PROG_NEWWAVE).exe *.o *~ *.core core

# Print dependencies
dep: deps
deps:
        gcc -MM *.c

# Print make's internal database
macro: macros
macros:
        @echo | cpp -dM

# Emacs etags
etags:
        rm -rf TAGS
        etags `$(ETAGS_ARGS)` `$(ETAGS_ARGS_CPP)`

.PHONY: all clean etags

dsdebug:
        @cpp -dM IID_IDirectSoundBuffer8.cpp -I /c/Documents\ and\ Settings/Johan\ Kuuse/My\ Documents/src/audio/dx/include/ 

dsdebug2:
        @cpp -dM IID_IDirectSoundBuffer8.cpp -I /c/Documents\ and\ Settings/Johan\ Kuuse/My\ Documents/src/audio/dx/include/ | grep IID|grep Sound|grep -v cpp|grep -v FX|grep -v 3D 

dsdebugms:
        cpp -dM IID_IDirectSoundBuffer8.cpp -I${INC_PATH_DX_MINGW}

vars:
        @echo CFLAGS = $(CFLAGS)
        @echo LDFLAGS = ${LDFLAGS}
        @echo OBJS = ${OBJS}
        @echo INC_PATHS = ${INC_PATH_DX_MINGW} ${INC_PATH_DX}
        @echo LIB_PATHS = $(LIB_PATH_DX_MINGW) ${LIB_PATH_DX}

.DEFAULT:
        @echo This target \($@\) is currently not supported.
        @echo To add a new platform, add a corresponding target in the Makefile. 
        exit 1

IndexPreviousNext
Last modified: Fri Jun 19 20:00:11 CEST 2009