1.1 diff -r 000000000000 -r 8bf1bf91a36d Makefile 1.2 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.3 +++ b/Makefile Sat Nov 27 01:13:12 2010 +0000 1.4 @@ -0,0 +1,454 @@ 1.5 +# Phil's multiplatform makefile template 1.6 +# With auto-incrementing build number and automatic version.h generation 1.7 +# Version 1.8, 2010-02-15 1.8 +# 1.9 +# The latest version of this Makefile can be found at http://www.philpem.me.uk/ 1.10 +# 1.11 +# 1.12 +# Copyright (c) 2010 Philip Pemberton <code@philpem.me.uk> 1.13 +# 1.14 +# Permission is hereby granted, free of charge, to any person obtaining a copy 1.15 +# of this software and associated documentation files (the "Software"), to deal 1.16 +# in the Software without restriction, including without limitation the rights 1.17 +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 1.18 +# copies of the Software, and to permit persons to whom the Software is 1.19 +# furnished to do so, subject to the following conditions: 1.20 +# 1.21 +# The above copyright notice and this permission notice shall be included in 1.22 +# all copies or substantial portions of the Software. 1.23 +# 1.24 +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1.25 +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1.26 +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1.27 +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 1.28 +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 1.29 +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 1.30 +# THE SOFTWARE. 1.31 +# 1.32 +# 1.33 +# Instructions for use: 1.34 +# Run 'make init' to create the required directories 1.35 +# Add your source files to the 'SOURCES' list, and change the TARGET filename 1.36 +# Set the desired build type and platform in the BUILD_TYPE and PLATFORM 1.37 +# variables respectively 1.38 +# Set your project type (C only, or C++) in the SRC_TYPE variable 1.39 +# Add any libraries you need to link against to the 'LIB' list 1.40 +# Run 'make' 1.41 +# 1.42 +# Object files are created in the 'obj' subdirectory, from source code in the 1.43 +# 'src' directory. Dependency files are created in the 'dep' directory from 1.44 +# the same source code the object files are created from. 1.45 +# 1.46 +# Supported targets are: 1.47 +# all Build everything. 1.48 +# update-revision Increment the build number without building anything. 1.49 +# clean-versioninfo Delete src/version.h (will be rebuilt on the next 1.50 +# 'make all'). 1.51 +# init Initialise the build system for a new project. 1.52 +# WARNING: overwrites .buildnum and src/version.h.in! 1.53 +# cleandep Delete all dependency files. 1.54 +# clean Delete all dependency, intermediate and target files. 1.55 +# tidy Delete all dependency and intermediate files, leaving 1.56 +# the target file intact. 1.57 +# 1.58 +# If you want to reset the build number to zero, delete '.buildnum'. This 1.59 +# should be done whenever the major or minor version changes. Excluding 1.60 +# .buildnum from version control may also be a good idea, depending on how 1.61 +# you want your build numbers to work. 1.62 +# 1.63 +# The BUILD_TYPE variable contains the current build type. There are two 1.64 +# supported build types: 1.65 +# debug Debug mode - object files are compiled with debug information 1.66 +# and the target is left unstripped. 1.67 +# release Release mode - object files are not compiled with debug info, 1.68 +# and the target is fed through strip to remove redundant 1.69 +# data. 1.70 +# 1.71 +# The PLATFORM variable contains the current target platform. There are two 1.72 +# supported platforms: 1.73 +# linux GNU/Linux with GNU Compiler Collection 1.74 +# win32 Windows 32-bit with MinGW 1.75 +# 1.76 +# The EXTSRC variable is used to specify other files to build. It is typically 1.77 +# used to specify platform or build-type specific source files, e.g. 1.78 +# 1.79 +# ifeq ($(BUILD_TYPE),debug-memwatch) 1.80 +# CFLAGS += -g -ggdb 1.81 +# CPPFLAGS += -DMEMWATCH 1.82 +# INCPATH += ./memwatch 1.83 +# EXTSRC += memwatch/memwatch.c 1.84 +# endif 1.85 +# 1.86 +# (example taken from one of my projects that allowed the use of Memwatch to 1.87 +# track down memory allocation/deallocation bugs) 1.88 +# 1.89 +# 1.90 +# Change history: 1.91 +# 1.8 - Now supports the use of the wxWidgets GUI framework. To turn 1.92 +# this on, set ENABLE_WX to "yes". 1.93 +# 1.7 - Now creates a basic Hgignore file and directory keepers for the 1.94 +# dep and obj directories. 1.95 +# 1.6 - Added CFLAGS and CXXFLAGS to the command-lines for the dependency 1.96 +# building commands. This was causing issues with C99 / C++0x mode. 1.97 +# 1.5 - Added support for Mercurial revision (changeset ID) display 1.98 +# Fixed a few issues with Subversion support (svn: and version 0 would 1.99 +# be displayed for exported code) 1.100 +# 1.101 + 1.102 +#### 1.103 +# Build configuration 1.104 +#### 1.105 + 1.106 +# version information -- major.minor.extra 1.107 +# note that VER_EXTRA can be overridden on the command line, e.g.: 1.108 +# make VER_EXTRA=12345 all 1.109 +VER_MAJOR = 0 1.110 +VER_MINOR = 0 1.111 +VER_EXTRA ?= 1.112 + 1.113 +# build platform: win32 or linux 1.114 +PLATFORM ?= linux 1.115 +# build type: release or debug 1.116 +BUILD_TYPE ?= debug 1.117 + 1.118 +# target executable 1.119 +TARGET = 3b1emu 1.120 + 1.121 +# source files that produce object files 1.122 +SRC = main.c musashi/m68kcpu.c musashi/m68kops.c 1.123 + 1.124 +# source type - either "c" or "cpp" (C or C++) 1.125 +SRC_TYPE = c 1.126 + 1.127 +# additional object files that don't necessarily include source 1.128 +EXT_OBJ = 1.129 +# libraries to link in -- these will be specified as "-l" parameters, the -l 1.130 +# is prepended automatically 1.131 +LIB = sdl 1.132 +# library paths -- where to search for the above libraries 1.133 +LIBPATH = musashi 1.134 +# include paths -- where to search for #include files (in addition to the 1.135 +# standard paths 1.136 +INCPATH = musashi 1.137 +# garbage files that should be deleted on a 'make clean' or 'make tidy' 1.138 +GARBAGE = obj/musashi/m68kmake obj/musashi/m68kmake.exe obj/musashi/m68kmake.o 1.139 + 1.140 +# extra dependencies - files that we don't necessarily know how to build, but 1.141 +# that are required for building the application; e.g. object files or 1.142 +# libraries in sub or parent directories 1.143 +EXTDEP = 1.144 + 1.145 +# Extra libraries 1.146 +# wxWidgets: set to "yes" to enable, anything else to disable 1.147 +ENABLE_WX = no 1.148 +# wxWidgets: list of wxWidgets libraries to enable 1.149 +WX_LIBS = std 1.150 + 1.151 +#### 1.152 +# Win32 target-specific settings 1.153 +#### 1.154 +ifeq ($(strip $(PLATFORM)),win32) 1.155 + # windows executables have a .exe suffix 1.156 + TARGET := $(addsuffix .exe,$(TARGET)) 1.157 + # console mode application 1.158 + EXT_CFLAGS = -mconsole 1.159 +endif 1.160 + 1.161 + 1.162 +#### 1.163 +# Tool setup 1.164 +#### 1.165 +MAKE = make 1.166 +CC = gcc 1.167 +CXX = g++ 1.168 +CFLAGS = -Wall -pedantic -std=gnu99 $(EXT_CFLAGS) 1.169 +CXXFLAGS= -Wall -pedantic -std=gnu++0x $(EXT_CXXFLAGS) 1.170 +LDFLAGS = $(EXT_LDFLAGS) 1.171 +RM = rm 1.172 +STRIP = strip 1.173 + 1.174 +############################################################################### 1.175 +# You should not need to touch anything below here, unless you're adding a new 1.176 +# platform or build type (or changing the version string format) 1.177 +############################################################################### 1.178 + 1.179 +#### 1.180 +# A quick sanity check on the platform type 1.181 +#### 1.182 +ifneq ($(PLATFORM),linux) 1.183 +ifneq ($(PLATFORM),win32) 1.184 + $(error Platform '$(PLATFORM)' not supported. Supported platforms are: linux, win32) 1.185 +endif 1.186 +endif 1.187 + 1.188 +#### 1.189 +# Version info generation 1.190 +#### 1.191 +# get the current build number 1.192 +VER_BUILDNUM = $(shell cat .buildnum) 1.193 + 1.194 +#### --- begin Subversion revision grabber --- 1.195 +# there are two ways to get the SVN revision - use svnversion, or use svn info 1.196 +# then pipe through awk. which one you use is up to you. 1.197 +VER_SVNREV = $(shell LANG=C svn info 2>/dev/null || echo 'Revision: exported' | awk '/^Revision:/ { print$$2 }' ) 1.198 +#VER_SVNREV = $(shell svnversion .) 1.199 + 1.200 +# if the version string is "exported", then the CSD was not checked out of SVN 1.201 +# note that if the CSD is not an SVN checkout, then @@svnrev@@ will be set to 1.202 +# zero. 1.203 +ifeq ($(VER_SVNREV),exported) 1.204 + VER_VCS = none 1.205 + VER_VCSREV = 0 1.206 +else 1.207 + VER_VCS = svn 1.208 + VER_VCSREV = $(VER_SVNREV) 1.209 +endif 1.210 + 1.211 +#### --- begin Mercurial revision grabber --- 1.212 +# If SVN didn't give us a revision, try Mercurial instead 1.213 +ifeq ($(VER_VCS),none) 1.214 + # get the current Mercurial changeset number 1.215 + VER_HGREV=$(shell ((hg tip --template "{node|short}") || echo "000000000000") 2>/dev/null) 1.216 + ifneq ($(VER_HGREV),000000000000) 1.217 + # a non-empty repo 1.218 + VER_VCS = hg 1.219 + VER_VCSREV = $(VER_HGREV) 1.220 + else 1.221 + # either an empty Hg repo, or no repo at all 1.222 + VER_VCS = none 1.223 + VER_VCSREV = 0 1.224 + endif 1.225 +endif 1.226 + 1.227 +#### --- end version grabbers --- 1.228 + 1.229 +# start creating the revision string 1.230 +VER_FULLSTR = $(VER_MAJOR).$(VER_MINOR).$(VER_BUILDNUM)$(VER_EXTRA) 1.231 + 1.232 +# if this is a VCS release, include the SVN revision in the version string 1.233 +# also create a revision string that is either "svn:12345", "hg:12345" or 1.234 +# blank 1.235 +ifneq ($(VER_VCS),none) 1.236 + VER_FULLSTR += ($(VER_VCS) $(VER_VCSREV)) 1.237 + VER_VCSSTR = $(VER_VCS):$(VER_VCSREV) 1.238 +else 1.239 + VER_VCSSTR = 1.240 +endif 1.241 + 1.242 + 1.243 +#### 1.244 +# Build-type specific configuration 1.245 +#### 1.246 +ifeq ($(BUILD_TYPE),debug) 1.247 + CFLAGS += -g -ggdb -DDEBUG 1.248 + CXXFLAGS += -g -ggdb -DDEBUG 1.249 +else 1.250 + ifeq ($(BUILD_TYPE),release) 1.251 + CFLAGS += -O2 1.252 + CXXFLAGS += -O2 1.253 + else 1.254 + $(error Unsupported build type: '$(BUILD_TYPE)') 1.255 + endif 1.256 +endif 1.257 + 1.258 +#### 1.259 +# wxWidgets support 1.260 +#### 1.261 +ifeq ($(ENABLE_WX),yes) 1.262 + ifeq ($(BUILD_TYPE),debug) 1.263 + LIBLNK += `wx-config --debug --libs $(WX_LIBS)` 1.264 + CFLAGS += `wx-config --debug --cflags $(WX_LIBS)` 1.265 + CXXFLAGS += `wx-config --debug --cxxflags $(WX_LIBS)` 1.266 + CPPFLAGS += `wx-config --debug --cppflags $(WX_LIBS)` 1.267 + else 1.268 + ifeq ($(BUILD_TYPE),release) 1.269 + LIBLNK += `wx-config --libs $(WX_LIBS)` 1.270 + CFLAGS += `wx-config --cflags $(WX_LIBS)` 1.271 + CPPFLAGS += `wx-config --cppflags $(WX_LIBS)` 1.272 + CXXFLAGS += `wx-config --cxxflags $(WX_LIBS)` 1.273 + else 1.274 + $(error Unsupported build type: '$(BUILD_TYPE)') 1.275 + endif 1.276 + endif 1.277 +endif 1.278 + 1.279 +#### 1.280 +# rules 1.281 +#### 1.282 + 1.283 +# object files 1.284 +OBJ = $(addprefix obj/, $(addsuffix .o, $(basename $(SRC))) $(EXT_OBJ)) $(addsuffix .o, $(basename $(EXTSRC))) 1.285 + 1.286 +# dependency files 1.287 +DEPFILES = $(addprefix dep/, $(addsuffix .d, $(basename $(SRC))) $(EXT_OBJ)) $(addsuffix .d, $(basename $(EXTSRC))) 1.288 + 1.289 +# path commands 1.290 +LIBLNK += $(addprefix -l, $(LIB)) 1.291 +LIBPTH += $(addprefix -L, $(LIBPATH)) 1.292 +INCPTH += $(addprefix -I, $(INCPATH)) 1.293 + 1.294 +CPPFLAGS += $(INCPTH) 1.295 + 1.296 +#### 1.297 +# Make sure there is at least one object file to be linked in 1.298 +#### 1.299 +ifeq ($(strip $(OBJ)),) 1.300 + $(error Unable to build: no object or source files specified in Makefile) 1.301 +endif 1.302 + 1.303 +#### 1.304 +# targets 1.305 +#### 1.306 +.PHONY: default all update-revision versionheader clean-versioninfo init cleandep clean tidy 1.307 + 1.308 +all: update-revision 1.309 + @$(MAKE) versionheader 1.310 + $(MAKE) $(TARGET) 1.311 + 1.312 +# increment the current build number 1.313 +NEWBUILD=$(shell expr $(VER_BUILDNUM) + 1) 1.314 +update-revision: 1.315 + @echo $(NEWBUILD) > .buildnum 1.316 + 1.317 +versionheader: 1.318 + @sed -e 's/@@date@@/$(shell LC_ALL=C date)/g' \ 1.319 + -e 's/@@time@@/$(shell LC_ALL=C date +%T)/g' \ 1.320 + -e 's/@@whoami@@/$(shell whoami)/g' \ 1.321 + -e 's/@@hostname@@/$(shell hostname)/g' \ 1.322 + -e 's|@@compiler@@|$(shell $(CC) $(CFLAGS) -v 2>&1 | tail -n 1 | sed -e "s;|;/;")|g' \ 1.323 + -e 's/@@majorver@@/$(VER_MAJOR)/g' \ 1.324 + -e 's/@@minorver@@/$(VER_MINOR)/g' \ 1.325 + -e 's/@@extraver@@/$(subst \",,$(VER_EXTRA))/g' \ 1.326 + -e 's/@@buildnum@@/$(VER_BUILDNUM)/g' \ 1.327 + -e 's/@@buildtype@@/$(BUILD_TYPE)/g' \ 1.328 + -e 's/@@vcs@@/$(VER_VCS)/g' \ 1.329 + -e 's/@@vcsrev@@/$(VER_VCSREV)/g' \ 1.330 + -e 's/@@vcsstr@@/$(VER_VCSSTR)/g' \ 1.331 + -e 's/@@fullverstr@@/$(VER_FULLSTR)/g' \ 1.332 + -e 's/@@cflags@@/$(CFLAGS)/g' \ 1.333 + < src/version.h.in > src/version.h 1.334 + 1.335 +# version.h creation stuff based on code from the Xen makefile 1.336 +clean-versioninfo: 1.337 + @if [ ! -r src/version.h -o -O src/version.h ]; then \ 1.338 + rm -f src/version.h; \ 1.339 + fi 1.340 + @echo 0 > .buildnum 1.341 + 1.342 +# initialise the build system for a new project 1.343 +init: 1.344 + @mkdir -p src dep obj 1.345 + @echo "This file is a directory-keeper. Do not delete it." > dep/.keepme 1.346 + @echo "This file is a directory-keeper. Do not delete it." > obj/.keepme 1.347 + @echo 0 > .buildnum 1.348 + @echo 'syntax: glob' > .hgignore 1.349 + @echo 'obj/*.o' >> .hgignore 1.350 + @echo 'dep/*.d' >> .hgignore 1.351 + @echo '*~' >> .hgignore 1.352 + @echo '.*.sw?' >> .hgignore 1.353 + @echo '#define VER_COMPILE_DATE "@@date@@"' > src/version.h.in 1.354 + @echo '#define VER_COMPILE_TIME "@@time@@"' >> src/version.h.in 1.355 + @echo '#define VER_COMPILE_BY "@@whoami@@"' >> src/version.h.in 1.356 + @echo '#define VER_COMPILE_HOST "@@hostname@@"' >> src/version.h.in 1.357 + @echo '#define VER_COMPILER "@@compiler@@"' >> src/version.h.in 1.358 + @echo '#define VER_BUILD_TYPE "@@buildtype@@"' >> src/version.h.in 1.359 + @echo '#define VER_CFLAGS "@@cflags@@"' >> src/version.h.in 1.360 + @echo '' >> src/version.h.in 1.361 + @echo '#define VER_MAJOR @@majorver@@' >> src/version.h.in 1.362 + @echo '#define VER_MINOR @@minorver@@' >> src/version.h.in 1.363 + @echo '#define VER_BUILDNUM @@buildnum@@' >> src/version.h.in 1.364 + @echo '#define VER_EXTRA "@@extraver@@"' >> src/version.h.in 1.365 + @echo '#define VER_VCSREV "@@vcsstr@@"' >> src/version.h.in 1.366 + @echo '' >> src/version.h.in 1.367 + @echo '#define VER_FULLSTR "@@fullverstr@@"' >> src/version.h.in 1.368 + @echo '' >> src/version.h.in 1.369 + @echo Build system initialised 1.370 + 1.371 +# remove the dependency files 1.372 +cleandep: 1.373 + -rm $(DEPFILES) 1.374 + 1.375 +# remove the dependency files and any target or intermediate build files 1.376 +clean: cleandep clean-versioninfo 1.377 + -rm $(OBJ) $(TARGET) $(GARBAGE) 1.378 + 1.379 +# remove any dependency or intermediate build files 1.380 +tidy: cleandep clean-versioninfo 1.381 + -rm $(OBJ) $(GARBAGE) 1.382 + 1.383 +################################# 1.384 + 1.385 +$(TARGET): $(OBJ) $(EXTDEP) 1.386 +ifeq ($(SRC_TYPE),c) 1.387 + $(CC) $(CXXFLAGS) $(LDFLAGS) $(OBJ) $(LIBPTH) $(LIBLNK) -o $@ 1.388 +else 1.389 + $(CXX) $(CXXFLAGS) $(LDFLAGS) $(OBJ) $(LIBPTH) $(LIBLNK) -o $@ 1.390 +endif 1.391 +ifeq ($(BUILD_TYPE),release) 1.392 + $(STRIP) $(TARGET) 1.393 +endif 1.394 + 1.395 +### 1.396 +# extra rules 1.397 +# example: 1.398 +#src/parser.c: src/parser.h 1.399 + 1.400 + 1.401 +#### 1.402 +## musashi build rules 1.403 +# 68k CPU builder 1.404 +obj/musashi/m68kmake: obj/musashi/m68kmake.o 1.405 + $(CC) $(CFLAGS) $(CPPFLAGS) obj/musashi/m68kmake.o -o $@ 1.406 +# 68k CPU sources 1.407 +src/musashi/m68kops.h src/musashi/m68kops.c: obj/musashi/m68kmake src/musashi/m68k_in.c 1.408 + ./obj/musashi/m68kmake src/musashi src/musashi/m68k_in.c 1.409 + 1.410 +#### 1.411 +# make object files from C source files 1.412 +obj/%.o: src/%.c 1.413 + $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@ 1.414 + 1.415 +## 1.416 +# make object files from C++ source files 1.417 +obj/%.o: src/%.cc 1.418 + $(CXX) -c $(CXXFLAGS) $(CPPFLAGS) $< -o $@ 1.419 + 1.420 +obj/%.o: src/%.cpp 1.421 + $(CXX) -c $(CXXFLAGS) $(CPPFLAGS) $< -o $@ 1.422 + 1.423 +### 1.424 +# make C files from yacc/bison source 1.425 +src/%.h src/%.c: src/%.y 1.426 + $(YACC) $(YFLAGS) -d $< 1.427 + mv -f y.tab.c $*.c 1.428 + mv -f y.tab.h $*.h 1.429 + 1.430 +### 1.431 +# make C files from lex/flex source 1.432 +src/%.c: src/%.l 1.433 + $(LEX) $(LFLAGS) -o$@ $< 1.434 + 1.435 +### 1.436 +# make dependencies for our source files 1.437 +dep/%.d: src/%.c 1.438 + $(CC) -MM $(CFLAGS) $(CPPFLAGS) $< > $@.$$$$; \ 1.439 + sed 's,\($*\)\.o[ :]*,obj/\1.o $@ : ,g' < $@.$$$$ > $@; \ 1.440 + rm -f $@.$$$$ 1.441 + 1.442 +dep/%.d: src/%.cpp 1.443 + $(CXX) -MM $(CXXFLAGS) $(CPPFLAGS) $< > $@.$$$$; \ 1.444 + sed 's,\($*\)\.o[ :]*,obj/\1.o $@ : ,g' < $@.$$$$ > $@; \ 1.445 + rm -f $@.$$$$ 1.446 + 1.447 +dep/%.d: src/%.cc 1.448 + $(CXX) -MM $(CXXFLAGS) $(CPPFLAGS) $< > $@.$$$$; \ 1.449 + sed 's,\($*\)\.o[ :]*,obj/\1.o $@ : ,g' < $@.$$$$ > $@; \ 1.450 + rm -f $@.$$$$ 1.451 + 1.452 +#### 1.453 +# pull in the dependency files, but only for 'make $(TARGET)' 1.454 +#### 1.455 + 1.456 +ifeq ($(MAKECMDGOALS),$(TARGET)) 1.457 + -include $(DEPFILES) 1.458 +endif