Makefile

Sun, 28 Nov 2010 03:17:08 +0000

author
Philip Pemberton <philpem@philpem.me.uk>
date
Sun, 28 Nov 2010 03:17:08 +0000
changeset 5
6a0c1ee6f6ca
parent 3
916a2c764bde
child 6
5dc2f3565377
permissions
-rw-r--r--

update hgignore

philpem@0 1 # Phil's multiplatform makefile template
philpem@0 2 # With auto-incrementing build number and automatic version.h generation
philpem@0 3 # Version 1.8, 2010-02-15
philpem@0 4 #
philpem@0 5 # The latest version of this Makefile can be found at http://www.philpem.me.uk/
philpem@0 6 #
philpem@0 7 #
philpem@0 8 # Copyright (c) 2010 Philip Pemberton <code@philpem.me.uk>
philpem@0 9 #
philpem@0 10 # Permission is hereby granted, free of charge, to any person obtaining a copy
philpem@0 11 # of this software and associated documentation files (the "Software"), to deal
philpem@0 12 # in the Software without restriction, including without limitation the rights
philpem@0 13 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
philpem@0 14 # copies of the Software, and to permit persons to whom the Software is
philpem@0 15 # furnished to do so, subject to the following conditions:
philpem@0 16 #
philpem@0 17 # The above copyright notice and this permission notice shall be included in
philpem@0 18 # all copies or substantial portions of the Software.
philpem@0 19 #
philpem@0 20 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
philpem@0 21 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
philpem@0 22 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
philpem@0 23 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
philpem@0 24 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
philpem@0 25 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
philpem@0 26 # THE SOFTWARE.
philpem@0 27 #
philpem@0 28 #
philpem@0 29 # Instructions for use:
philpem@0 30 # Run 'make init' to create the required directories
philpem@0 31 # Add your source files to the 'SOURCES' list, and change the TARGET filename
philpem@0 32 # Set the desired build type and platform in the BUILD_TYPE and PLATFORM
philpem@0 33 # variables respectively
philpem@0 34 # Set your project type (C only, or C++) in the SRC_TYPE variable
philpem@0 35 # Add any libraries you need to link against to the 'LIB' list
philpem@0 36 # Run 'make'
philpem@0 37 #
philpem@0 38 # Object files are created in the 'obj' subdirectory, from source code in the
philpem@0 39 # 'src' directory. Dependency files are created in the 'dep' directory from
philpem@0 40 # the same source code the object files are created from.
philpem@0 41 #
philpem@0 42 # Supported targets are:
philpem@0 43 # all Build everything.
philpem@0 44 # update-revision Increment the build number without building anything.
philpem@0 45 # clean-versioninfo Delete src/version.h (will be rebuilt on the next
philpem@0 46 # 'make all').
philpem@0 47 # init Initialise the build system for a new project.
philpem@0 48 # WARNING: overwrites .buildnum and src/version.h.in!
philpem@0 49 # cleandep Delete all dependency files.
philpem@0 50 # clean Delete all dependency, intermediate and target files.
philpem@0 51 # tidy Delete all dependency and intermediate files, leaving
philpem@0 52 # the target file intact.
philpem@0 53 #
philpem@0 54 # If you want to reset the build number to zero, delete '.buildnum'. This
philpem@0 55 # should be done whenever the major or minor version changes. Excluding
philpem@0 56 # .buildnum from version control may also be a good idea, depending on how
philpem@0 57 # you want your build numbers to work.
philpem@0 58 #
philpem@0 59 # The BUILD_TYPE variable contains the current build type. There are two
philpem@0 60 # supported build types:
philpem@0 61 # debug Debug mode - object files are compiled with debug information
philpem@0 62 # and the target is left unstripped.
philpem@0 63 # release Release mode - object files are not compiled with debug info,
philpem@0 64 # and the target is fed through strip to remove redundant
philpem@0 65 # data.
philpem@0 66 #
philpem@0 67 # The PLATFORM variable contains the current target platform. There are two
philpem@0 68 # supported platforms:
philpem@0 69 # linux GNU/Linux with GNU Compiler Collection
philpem@0 70 # win32 Windows 32-bit with MinGW
philpem@0 71 #
philpem@0 72 # The EXTSRC variable is used to specify other files to build. It is typically
philpem@0 73 # used to specify platform or build-type specific source files, e.g.
philpem@0 74 #
philpem@0 75 # ifeq ($(BUILD_TYPE),debug-memwatch)
philpem@0 76 # CFLAGS += -g -ggdb
philpem@0 77 # CPPFLAGS += -DMEMWATCH
philpem@0 78 # INCPATH += ./memwatch
philpem@0 79 # EXTSRC += memwatch/memwatch.c
philpem@0 80 # endif
philpem@0 81 #
philpem@0 82 # (example taken from one of my projects that allowed the use of Memwatch to
philpem@0 83 # track down memory allocation/deallocation bugs)
philpem@0 84 #
philpem@0 85 #
philpem@0 86 # Change history:
philpem@0 87 # 1.8 - Now supports the use of the wxWidgets GUI framework. To turn
philpem@0 88 # this on, set ENABLE_WX to "yes".
philpem@0 89 # 1.7 - Now creates a basic Hgignore file and directory keepers for the
philpem@0 90 # dep and obj directories.
philpem@0 91 # 1.6 - Added CFLAGS and CXXFLAGS to the command-lines for the dependency
philpem@0 92 # building commands. This was causing issues with C99 / C++0x mode.
philpem@0 93 # 1.5 - Added support for Mercurial revision (changeset ID) display
philpem@0 94 # Fixed a few issues with Subversion support (svn: and version 0 would
philpem@0 95 # be displayed for exported code)
philpem@0 96 #
philpem@0 97
philpem@0 98 ####
philpem@0 99 # Build configuration
philpem@0 100 ####
philpem@0 101
philpem@0 102 # version information -- major.minor.extra
philpem@0 103 # note that VER_EXTRA can be overridden on the command line, e.g.:
philpem@0 104 # make VER_EXTRA=12345 all
philpem@0 105 VER_MAJOR = 0
philpem@0 106 VER_MINOR = 0
philpem@0 107 VER_EXTRA ?=
philpem@0 108
philpem@0 109 # build platform: win32 or linux
philpem@0 110 PLATFORM ?= linux
philpem@0 111 # build type: release or debug
philpem@0 112 BUILD_TYPE ?= debug
philpem@0 113
philpem@0 114 # target executable
philpem@0 115 TARGET = 3b1emu
philpem@0 116
philpem@0 117 # source files that produce object files
philpem@3 118 SRC = main.c musashi/m68kcpu.c musashi/m68kops.c musashi/m68kopac.c musashi/m68kopdm.c musashi/m68kopnz.c
philpem@0 119
philpem@0 120 # source type - either "c" or "cpp" (C or C++)
philpem@0 121 SRC_TYPE = c
philpem@0 122
philpem@0 123 # additional object files that don't necessarily include source
philpem@0 124 EXT_OBJ =
philpem@0 125 # libraries to link in -- these will be specified as "-l" parameters, the -l
philpem@0 126 # is prepended automatically
philpem@3 127 LIB =
philpem@0 128 # library paths -- where to search for the above libraries
philpem@3 129 LIBPATH =
philpem@0 130 # include paths -- where to search for #include files (in addition to the
philpem@0 131 # standard paths
philpem@3 132 INCPATH =
philpem@0 133 # garbage files that should be deleted on a 'make clean' or 'make tidy'
philpem@0 134 GARBAGE = obj/musashi/m68kmake obj/musashi/m68kmake.exe obj/musashi/m68kmake.o
philpem@0 135
philpem@0 136 # extra dependencies - files that we don't necessarily know how to build, but
philpem@0 137 # that are required for building the application; e.g. object files or
philpem@0 138 # libraries in sub or parent directories
philpem@0 139 EXTDEP =
philpem@0 140
philpem@0 141 # Extra libraries
philpem@0 142 # wxWidgets: set to "yes" to enable, anything else to disable
philpem@0 143 ENABLE_WX = no
philpem@0 144 # wxWidgets: list of wxWidgets libraries to enable
philpem@0 145 WX_LIBS = std
philpem@3 146 # SDL: set to "yes" to enable, anything else to disable
philpem@3 147 ENABLE_SDL = yes
philpem@0 148
philpem@0 149 ####
philpem@0 150 # Win32 target-specific settings
philpem@0 151 ####
philpem@0 152 ifeq ($(strip $(PLATFORM)),win32)
philpem@0 153 # windows executables have a .exe suffix
philpem@0 154 TARGET := $(addsuffix .exe,$(TARGET))
philpem@0 155 # console mode application
philpem@0 156 EXT_CFLAGS = -mconsole
philpem@0 157 endif
philpem@0 158
philpem@0 159
philpem@0 160 ####
philpem@0 161 # Tool setup
philpem@0 162 ####
philpem@0 163 MAKE = make
philpem@0 164 CC = gcc
philpem@0 165 CXX = g++
philpem@0 166 CFLAGS = -Wall -pedantic -std=gnu99 $(EXT_CFLAGS)
philpem@0 167 CXXFLAGS= -Wall -pedantic -std=gnu++0x $(EXT_CXXFLAGS)
philpem@0 168 LDFLAGS = $(EXT_LDFLAGS)
philpem@0 169 RM = rm
philpem@0 170 STRIP = strip
philpem@0 171
philpem@0 172 ###############################################################################
philpem@0 173 # You should not need to touch anything below here, unless you're adding a new
philpem@0 174 # platform or build type (or changing the version string format)
philpem@0 175 ###############################################################################
philpem@0 176
philpem@0 177 ####
philpem@0 178 # A quick sanity check on the platform type
philpem@0 179 ####
philpem@0 180 ifneq ($(PLATFORM),linux)
philpem@0 181 ifneq ($(PLATFORM),win32)
philpem@0 182 $(error Platform '$(PLATFORM)' not supported. Supported platforms are: linux, win32)
philpem@0 183 endif
philpem@0 184 endif
philpem@0 185
philpem@0 186 ####
philpem@0 187 # Version info generation
philpem@0 188 ####
philpem@0 189 # get the current build number
philpem@0 190 VER_BUILDNUM = $(shell cat .buildnum)
philpem@0 191
philpem@0 192 #### --- begin Subversion revision grabber ---
philpem@0 193 # there are two ways to get the SVN revision - use svnversion, or use svn info
philpem@0 194 # then pipe through awk. which one you use is up to you.
philpem@0 195 VER_SVNREV = $(shell LANG=C svn info 2>/dev/null || echo 'Revision: exported' | awk '/^Revision:/ { print$$2 }' )
philpem@0 196 #VER_SVNREV = $(shell svnversion .)
philpem@0 197
philpem@0 198 # if the version string is "exported", then the CSD was not checked out of SVN
philpem@0 199 # note that if the CSD is not an SVN checkout, then @@svnrev@@ will be set to
philpem@0 200 # zero.
philpem@0 201 ifeq ($(VER_SVNREV),exported)
philpem@0 202 VER_VCS = none
philpem@0 203 VER_VCSREV = 0
philpem@0 204 else
philpem@0 205 VER_VCS = svn
philpem@0 206 VER_VCSREV = $(VER_SVNREV)
philpem@0 207 endif
philpem@0 208
philpem@0 209 #### --- begin Mercurial revision grabber ---
philpem@0 210 # If SVN didn't give us a revision, try Mercurial instead
philpem@0 211 ifeq ($(VER_VCS),none)
philpem@0 212 # get the current Mercurial changeset number
philpem@0 213 VER_HGREV=$(shell ((hg tip --template "{node|short}") || echo "000000000000") 2>/dev/null)
philpem@0 214 ifneq ($(VER_HGREV),000000000000)
philpem@0 215 # a non-empty repo
philpem@0 216 VER_VCS = hg
philpem@0 217 VER_VCSREV = $(VER_HGREV)
philpem@0 218 else
philpem@0 219 # either an empty Hg repo, or no repo at all
philpem@0 220 VER_VCS = none
philpem@0 221 VER_VCSREV = 0
philpem@0 222 endif
philpem@0 223 endif
philpem@0 224
philpem@0 225 #### --- end version grabbers ---
philpem@0 226
philpem@0 227 # start creating the revision string
philpem@0 228 VER_FULLSTR = $(VER_MAJOR).$(VER_MINOR).$(VER_BUILDNUM)$(VER_EXTRA)
philpem@0 229
philpem@0 230 # if this is a VCS release, include the SVN revision in the version string
philpem@0 231 # also create a revision string that is either "svn:12345", "hg:12345" or
philpem@0 232 # blank
philpem@0 233 ifneq ($(VER_VCS),none)
philpem@0 234 VER_FULLSTR += ($(VER_VCS) $(VER_VCSREV))
philpem@0 235 VER_VCSSTR = $(VER_VCS):$(VER_VCSREV)
philpem@0 236 else
philpem@0 237 VER_VCSSTR =
philpem@0 238 endif
philpem@0 239
philpem@0 240
philpem@0 241 ####
philpem@0 242 # Build-type specific configuration
philpem@0 243 ####
philpem@0 244 ifeq ($(BUILD_TYPE),debug)
philpem@0 245 CFLAGS += -g -ggdb -DDEBUG
philpem@0 246 CXXFLAGS += -g -ggdb -DDEBUG
philpem@0 247 else
philpem@0 248 ifeq ($(BUILD_TYPE),release)
philpem@0 249 CFLAGS += -O2
philpem@0 250 CXXFLAGS += -O2
philpem@0 251 else
philpem@0 252 $(error Unsupported build type: '$(BUILD_TYPE)')
philpem@0 253 endif
philpem@0 254 endif
philpem@0 255
philpem@0 256 ####
philpem@0 257 # wxWidgets support
philpem@0 258 ####
philpem@0 259 ifeq ($(ENABLE_WX),yes)
philpem@0 260 ifeq ($(BUILD_TYPE),debug)
philpem@0 261 LIBLNK += `wx-config --debug --libs $(WX_LIBS)`
philpem@0 262 CFLAGS += `wx-config --debug --cflags $(WX_LIBS)`
philpem@0 263 CXXFLAGS += `wx-config --debug --cxxflags $(WX_LIBS)`
philpem@0 264 CPPFLAGS += `wx-config --debug --cppflags $(WX_LIBS)`
philpem@0 265 else
philpem@0 266 ifeq ($(BUILD_TYPE),release)
philpem@0 267 LIBLNK += `wx-config --libs $(WX_LIBS)`
philpem@0 268 CFLAGS += `wx-config --cflags $(WX_LIBS)`
philpem@0 269 CPPFLAGS += `wx-config --cppflags $(WX_LIBS)`
philpem@0 270 CXXFLAGS += `wx-config --cxxflags $(WX_LIBS)`
philpem@0 271 else
philpem@0 272 $(error Unsupported build type: '$(BUILD_TYPE)')
philpem@0 273 endif
philpem@0 274 endif
philpem@0 275 endif
philpem@0 276
philpem@0 277 ####
philpem@3 278 # SDL support
philpem@3 279 ####
philpem@3 280 ifeq ($(ENABLE_SDL),yes)
philpem@3 281 LIBLNK += `sdl-config --libs`
philpem@3 282 CFLAGS += `sdl-config --cflags`
philpem@3 283 endif
philpem@3 284
philpem@3 285
philpem@3 286 ####
philpem@0 287 # rules
philpem@0 288 ####
philpem@0 289
philpem@0 290 # object files
philpem@0 291 OBJ = $(addprefix obj/, $(addsuffix .o, $(basename $(SRC))) $(EXT_OBJ)) $(addsuffix .o, $(basename $(EXTSRC)))
philpem@0 292
philpem@0 293 # dependency files
philpem@0 294 DEPFILES = $(addprefix dep/, $(addsuffix .d, $(basename $(SRC))) $(EXT_OBJ)) $(addsuffix .d, $(basename $(EXTSRC)))
philpem@0 295
philpem@0 296 # path commands
philpem@0 297 LIBLNK += $(addprefix -l, $(LIB))
philpem@0 298 LIBPTH += $(addprefix -L, $(LIBPATH))
philpem@0 299 INCPTH += $(addprefix -I, $(INCPATH))
philpem@0 300
philpem@0 301 CPPFLAGS += $(INCPTH)
philpem@0 302
philpem@0 303 ####
philpem@0 304 # Make sure there is at least one object file to be linked in
philpem@0 305 ####
philpem@0 306 ifeq ($(strip $(OBJ)),)
philpem@0 307 $(error Unable to build: no object or source files specified in Makefile)
philpem@0 308 endif
philpem@0 309
philpem@0 310 ####
philpem@0 311 # targets
philpem@0 312 ####
philpem@0 313 .PHONY: default all update-revision versionheader clean-versioninfo init cleandep clean tidy
philpem@0 314
philpem@0 315 all: update-revision
philpem@0 316 @$(MAKE) versionheader
philpem@0 317 $(MAKE) $(TARGET)
philpem@0 318
philpem@0 319 # increment the current build number
philpem@0 320 NEWBUILD=$(shell expr $(VER_BUILDNUM) + 1)
philpem@0 321 update-revision:
philpem@0 322 @echo $(NEWBUILD) > .buildnum
philpem@0 323
philpem@0 324 versionheader:
philpem@0 325 @sed -e 's/@@date@@/$(shell LC_ALL=C date)/g' \
philpem@0 326 -e 's/@@time@@/$(shell LC_ALL=C date +%T)/g' \
philpem@0 327 -e 's/@@whoami@@/$(shell whoami)/g' \
philpem@0 328 -e 's/@@hostname@@/$(shell hostname)/g' \
philpem@0 329 -e 's|@@compiler@@|$(shell $(CC) $(CFLAGS) -v 2>&1 | tail -n 1 | sed -e "s;|;/;")|g' \
philpem@0 330 -e 's/@@majorver@@/$(VER_MAJOR)/g' \
philpem@0 331 -e 's/@@minorver@@/$(VER_MINOR)/g' \
philpem@0 332 -e 's/@@extraver@@/$(subst \",,$(VER_EXTRA))/g' \
philpem@0 333 -e 's/@@buildnum@@/$(VER_BUILDNUM)/g' \
philpem@0 334 -e 's/@@buildtype@@/$(BUILD_TYPE)/g' \
philpem@0 335 -e 's/@@vcs@@/$(VER_VCS)/g' \
philpem@0 336 -e 's/@@vcsrev@@/$(VER_VCSREV)/g' \
philpem@0 337 -e 's/@@vcsstr@@/$(VER_VCSSTR)/g' \
philpem@0 338 -e 's/@@fullverstr@@/$(VER_FULLSTR)/g' \
philpem@0 339 -e 's/@@cflags@@/$(CFLAGS)/g' \
philpem@0 340 < src/version.h.in > src/version.h
philpem@0 341
philpem@0 342 # version.h creation stuff based on code from the Xen makefile
philpem@0 343 clean-versioninfo:
philpem@0 344 @if [ ! -r src/version.h -o -O src/version.h ]; then \
philpem@0 345 rm -f src/version.h; \
philpem@0 346 fi
philpem@0 347 @echo 0 > .buildnum
philpem@0 348
philpem@0 349 # initialise the build system for a new project
philpem@0 350 init:
philpem@0 351 @mkdir -p src dep obj
philpem@0 352 @echo "This file is a directory-keeper. Do not delete it." > dep/.keepme
philpem@0 353 @echo "This file is a directory-keeper. Do not delete it." > obj/.keepme
philpem@0 354 @echo 0 > .buildnum
philpem@0 355 @echo 'syntax: glob' > .hgignore
philpem@0 356 @echo 'obj/*.o' >> .hgignore
philpem@0 357 @echo 'dep/*.d' >> .hgignore
philpem@0 358 @echo '*~' >> .hgignore
philpem@0 359 @echo '.*.sw?' >> .hgignore
philpem@0 360 @echo '#define VER_COMPILE_DATE "@@date@@"' > src/version.h.in
philpem@0 361 @echo '#define VER_COMPILE_TIME "@@time@@"' >> src/version.h.in
philpem@0 362 @echo '#define VER_COMPILE_BY "@@whoami@@"' >> src/version.h.in
philpem@0 363 @echo '#define VER_COMPILE_HOST "@@hostname@@"' >> src/version.h.in
philpem@0 364 @echo '#define VER_COMPILER "@@compiler@@"' >> src/version.h.in
philpem@0 365 @echo '#define VER_BUILD_TYPE "@@buildtype@@"' >> src/version.h.in
philpem@0 366 @echo '#define VER_CFLAGS "@@cflags@@"' >> src/version.h.in
philpem@0 367 @echo '' >> src/version.h.in
philpem@0 368 @echo '#define VER_MAJOR @@majorver@@' >> src/version.h.in
philpem@0 369 @echo '#define VER_MINOR @@minorver@@' >> src/version.h.in
philpem@0 370 @echo '#define VER_BUILDNUM @@buildnum@@' >> src/version.h.in
philpem@0 371 @echo '#define VER_EXTRA "@@extraver@@"' >> src/version.h.in
philpem@0 372 @echo '#define VER_VCSREV "@@vcsstr@@"' >> src/version.h.in
philpem@0 373 @echo '' >> src/version.h.in
philpem@0 374 @echo '#define VER_FULLSTR "@@fullverstr@@"' >> src/version.h.in
philpem@0 375 @echo '' >> src/version.h.in
philpem@0 376 @echo Build system initialised
philpem@0 377
philpem@0 378 # remove the dependency files
philpem@0 379 cleandep:
philpem@0 380 -rm $(DEPFILES)
philpem@0 381
philpem@0 382 # remove the dependency files and any target or intermediate build files
philpem@0 383 clean: cleandep clean-versioninfo
philpem@0 384 -rm $(OBJ) $(TARGET) $(GARBAGE)
philpem@0 385
philpem@0 386 # remove any dependency or intermediate build files
philpem@0 387 tidy: cleandep clean-versioninfo
philpem@0 388 -rm $(OBJ) $(GARBAGE)
philpem@0 389
philpem@0 390 #################################
philpem@0 391
philpem@0 392 $(TARGET): $(OBJ) $(EXTDEP)
philpem@0 393 ifeq ($(SRC_TYPE),c)
philpem@0 394 $(CC) $(CXXFLAGS) $(LDFLAGS) $(OBJ) $(LIBPTH) $(LIBLNK) -o $@
philpem@0 395 else
philpem@0 396 $(CXX) $(CXXFLAGS) $(LDFLAGS) $(OBJ) $(LIBPTH) $(LIBLNK) -o $@
philpem@0 397 endif
philpem@0 398 ifeq ($(BUILD_TYPE),release)
philpem@0 399 $(STRIP) $(TARGET)
philpem@0 400 endif
philpem@0 401
philpem@0 402 ###
philpem@0 403 # extra rules
philpem@0 404 # example:
philpem@0 405 #src/parser.c: src/parser.h
philpem@0 406
philpem@0 407
philpem@0 408 ####
philpem@0 409 ## musashi build rules
philpem@0 410 # 68k CPU builder
philpem@0 411 obj/musashi/m68kmake: obj/musashi/m68kmake.o
philpem@0 412 $(CC) $(CFLAGS) $(CPPFLAGS) obj/musashi/m68kmake.o -o $@
philpem@0 413 # 68k CPU sources
philpem@3 414 src/musashi/m68kops.h src/musashi/m68kops.c src/musashi/m68kopac.c src/musashi/m68kopdm.c src/musashi/m68kopnz.c: obj/musashi/m68kmake src/musashi/m68k_in.c
philpem@0 415 ./obj/musashi/m68kmake src/musashi src/musashi/m68k_in.c
philpem@0 416
philpem@0 417 ####
philpem@0 418 # make object files from C source files
philpem@0 419 obj/%.o: src/%.c
philpem@0 420 $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
philpem@0 421
philpem@0 422 ##
philpem@0 423 # make object files from C++ source files
philpem@0 424 obj/%.o: src/%.cc
philpem@0 425 $(CXX) -c $(CXXFLAGS) $(CPPFLAGS) $< -o $@
philpem@0 426
philpem@0 427 obj/%.o: src/%.cpp
philpem@0 428 $(CXX) -c $(CXXFLAGS) $(CPPFLAGS) $< -o $@
philpem@0 429
philpem@0 430 ###
philpem@0 431 # make C files from yacc/bison source
philpem@0 432 src/%.h src/%.c: src/%.y
philpem@0 433 $(YACC) $(YFLAGS) -d $<
philpem@0 434 mv -f y.tab.c $*.c
philpem@0 435 mv -f y.tab.h $*.h
philpem@0 436
philpem@0 437 ###
philpem@0 438 # make C files from lex/flex source
philpem@0 439 src/%.c: src/%.l
philpem@0 440 $(LEX) $(LFLAGS) -o$@ $<
philpem@0 441
philpem@0 442 ###
philpem@0 443 # make dependencies for our source files
philpem@0 444 dep/%.d: src/%.c
philpem@0 445 $(CC) -MM $(CFLAGS) $(CPPFLAGS) $< > $@.$$$$; \
philpem@0 446 sed 's,\($*\)\.o[ :]*,obj/\1.o $@ : ,g' < $@.$$$$ > $@; \
philpem@0 447 rm -f $@.$$$$
philpem@0 448
philpem@0 449 dep/%.d: src/%.cpp
philpem@0 450 $(CXX) -MM $(CXXFLAGS) $(CPPFLAGS) $< > $@.$$$$; \
philpem@0 451 sed 's,\($*\)\.o[ :]*,obj/\1.o $@ : ,g' < $@.$$$$ > $@; \
philpem@0 452 rm -f $@.$$$$
philpem@0 453
philpem@0 454 dep/%.d: src/%.cc
philpem@0 455 $(CXX) -MM $(CXXFLAGS) $(CPPFLAGS) $< > $@.$$$$; \
philpem@0 456 sed 's,\($*\)\.o[ :]*,obj/\1.o $@ : ,g' < $@.$$$$ > $@; \
philpem@0 457 rm -f $@.$$$$
philpem@0 458
philpem@0 459 ####
philpem@0 460 # pull in the dependency files, but only for 'make $(TARGET)'
philpem@0 461 ####
philpem@0 462
philpem@0 463 ifeq ($(MAKECMDGOALS),$(TARGET))
philpem@0 464 -include $(DEPFILES)
philpem@0 465 endif