Makefile

Sun, 28 Nov 2010 23:07:17 +0000

author
Philip Pemberton <philpem@philpem.me.uk>
date
Sun, 28 Nov 2010 23:07:17 +0000
changeset 14
7a98c853715e
parent 13
973a377aa562
child 18
320dc6206f52
permissions
-rw-r--r--

sync Makefile with MakefileTemplate v1.9

philpem@0 1 # Phil's multiplatform makefile template
philpem@0 2 # With auto-incrementing build number and automatic version.h generation
philpem@14 3 # Version 1.9, 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@14 87 # 1.9 - Bugfix -- if CFLAGS contained a forward-slash, sed would fall over.
philpem@14 88 # Also added SDL support and fixed the date/time formats. To use SDL,
philpem@14 89 # set ENABLE_SDL to "yes".
philpem@0 90 # 1.8 - Now supports the use of the wxWidgets GUI framework. To turn
philpem@0 91 # this on, set ENABLE_WX to "yes".
philpem@0 92 # 1.7 - Now creates a basic Hgignore file and directory keepers for the
philpem@0 93 # dep and obj directories.
philpem@0 94 # 1.6 - Added CFLAGS and CXXFLAGS to the command-lines for the dependency
philpem@0 95 # building commands. This was causing issues with C99 / C++0x mode.
philpem@0 96 # 1.5 - Added support for Mercurial revision (changeset ID) display
philpem@0 97 # Fixed a few issues with Subversion support (svn: and version 0 would
philpem@0 98 # be displayed for exported code)
philpem@0 99 #
philpem@0 100
philpem@0 101 ####
philpem@0 102 # Build configuration
philpem@0 103 ####
philpem@0 104
philpem@0 105 # version information -- major.minor.extra
philpem@0 106 # note that VER_EXTRA can be overridden on the command line, e.g.:
philpem@0 107 # make VER_EXTRA=12345 all
philpem@0 108 VER_MAJOR = 0
philpem@0 109 VER_MINOR = 0
philpem@0 110 VER_EXTRA ?=
philpem@0 111
philpem@0 112 # build platform: win32 or linux
philpem@0 113 PLATFORM ?= linux
philpem@0 114 # build type: release or debug
philpem@0 115 BUILD_TYPE ?= debug
philpem@0 116
philpem@0 117 # target executable
philpem@6 118 TARGET = freebee
philpem@0 119
philpem@0 120 # source files that produce object files
philpem@9 121 SRC = main.c musashi/m68kcpu.c musashi/m68kdasm.c musashi/m68kops.c musashi/m68kopac.c musashi/m68kopdm.c musashi/m68kopnz.c
philpem@0 122
philpem@0 123 # source type - either "c" or "cpp" (C or C++)
philpem@0 124 SRC_TYPE = c
philpem@0 125
philpem@0 126 # additional object files that don't necessarily include source
philpem@0 127 EXT_OBJ =
philpem@0 128 # libraries to link in -- these will be specified as "-l" parameters, the -l
philpem@0 129 # is prepended automatically
philpem@3 130 LIB =
philpem@0 131 # library paths -- where to search for the above libraries
philpem@3 132 LIBPATH =
philpem@0 133 # include paths -- where to search for #include files (in addition to the
philpem@0 134 # standard paths
philpem@3 135 INCPATH =
philpem@0 136 # garbage files that should be deleted on a 'make clean' or 'make tidy'
philpem@0 137 GARBAGE = obj/musashi/m68kmake obj/musashi/m68kmake.exe obj/musashi/m68kmake.o
philpem@0 138
philpem@0 139 # extra dependencies - files that we don't necessarily know how to build, but
philpem@0 140 # that are required for building the application; e.g. object files or
philpem@0 141 # libraries in sub or parent directories
philpem@0 142 EXTDEP =
philpem@0 143
philpem@0 144 # Extra libraries
philpem@0 145 # wxWidgets: set to "yes" to enable, anything else to disable
philpem@0 146 ENABLE_WX = no
philpem@0 147 # wxWidgets: list of wxWidgets libraries to enable
philpem@0 148 WX_LIBS = std
philpem@3 149 # SDL: set to "yes" to enable, anything else to disable
philpem@3 150 ENABLE_SDL = yes
philpem@0 151
philpem@0 152 ####
philpem@0 153 # Win32 target-specific settings
philpem@0 154 ####
philpem@0 155 ifeq ($(strip $(PLATFORM)),win32)
philpem@0 156 # windows executables have a .exe suffix
philpem@0 157 TARGET := $(addsuffix .exe,$(TARGET))
philpem@0 158 # console mode application
philpem@0 159 EXT_CFLAGS = -mconsole
philpem@0 160 endif
philpem@0 161
philpem@0 162
philpem@0 163 ####
philpem@0 164 # Tool setup
philpem@0 165 ####
philpem@0 166 MAKE = make
philpem@0 167 CC = gcc
philpem@0 168 CXX = g++
philpem@0 169 CFLAGS = -Wall -pedantic -std=gnu99 $(EXT_CFLAGS)
philpem@0 170 CXXFLAGS= -Wall -pedantic -std=gnu++0x $(EXT_CXXFLAGS)
philpem@0 171 LDFLAGS = $(EXT_LDFLAGS)
philpem@0 172 RM = rm
philpem@0 173 STRIP = strip
philpem@0 174
philpem@0 175 ###############################################################################
philpem@0 176 # You should not need to touch anything below here, unless you're adding a new
philpem@0 177 # platform or build type (or changing the version string format)
philpem@0 178 ###############################################################################
philpem@0 179
philpem@0 180 ####
philpem@0 181 # A quick sanity check on the platform type
philpem@0 182 ####
philpem@0 183 ifneq ($(PLATFORM),linux)
philpem@0 184 ifneq ($(PLATFORM),win32)
philpem@0 185 $(error Platform '$(PLATFORM)' not supported. Supported platforms are: linux, win32)
philpem@0 186 endif
philpem@0 187 endif
philpem@0 188
philpem@0 189 ####
philpem@0 190 # Version info generation
philpem@0 191 ####
philpem@0 192 # get the current build number
philpem@0 193 VER_BUILDNUM = $(shell cat .buildnum)
philpem@0 194
philpem@0 195 #### --- begin Subversion revision grabber ---
philpem@0 196 # there are two ways to get the SVN revision - use svnversion, or use svn info
philpem@0 197 # then pipe through awk. which one you use is up to you.
philpem@0 198 VER_SVNREV = $(shell LANG=C svn info 2>/dev/null || echo 'Revision: exported' | awk '/^Revision:/ { print$$2 }' )
philpem@0 199 #VER_SVNREV = $(shell svnversion .)
philpem@0 200
philpem@0 201 # if the version string is "exported", then the CSD was not checked out of SVN
philpem@0 202 # note that if the CSD is not an SVN checkout, then @@svnrev@@ will be set to
philpem@0 203 # zero.
philpem@0 204 ifeq ($(VER_SVNREV),exported)
philpem@0 205 VER_VCS = none
philpem@0 206 VER_VCSREV = 0
philpem@0 207 else
philpem@0 208 VER_VCS = svn
philpem@0 209 VER_VCSREV = $(VER_SVNREV)
philpem@0 210 endif
philpem@0 211
philpem@0 212 #### --- begin Mercurial revision grabber ---
philpem@0 213 # If SVN didn't give us a revision, try Mercurial instead
philpem@0 214 ifeq ($(VER_VCS),none)
philpem@0 215 # get the current Mercurial changeset number
philpem@0 216 VER_HGREV=$(shell ((hg tip --template "{node|short}") || echo "000000000000") 2>/dev/null)
philpem@0 217 ifneq ($(VER_HGREV),000000000000)
philpem@0 218 # a non-empty repo
philpem@0 219 VER_VCS = hg
philpem@0 220 VER_VCSREV = $(VER_HGREV)
philpem@0 221 else
philpem@0 222 # either an empty Hg repo, or no repo at all
philpem@0 223 VER_VCS = none
philpem@0 224 VER_VCSREV = 0
philpem@0 225 endif
philpem@0 226 endif
philpem@0 227
philpem@0 228 #### --- end version grabbers ---
philpem@0 229
philpem@0 230 # start creating the revision string
philpem@0 231 VER_FULLSTR = $(VER_MAJOR).$(VER_MINOR).$(VER_BUILDNUM)$(VER_EXTRA)
philpem@0 232
philpem@0 233 # if this is a VCS release, include the SVN revision in the version string
philpem@0 234 # also create a revision string that is either "svn:12345", "hg:12345" or
philpem@0 235 # blank
philpem@0 236 ifneq ($(VER_VCS),none)
philpem@0 237 VER_FULLSTR += ($(VER_VCS) $(VER_VCSREV))
philpem@0 238 VER_VCSSTR = $(VER_VCS):$(VER_VCSREV)
philpem@0 239 else
philpem@0 240 VER_VCSSTR =
philpem@0 241 endif
philpem@0 242
philpem@0 243
philpem@0 244 ####
philpem@0 245 # Build-type specific configuration
philpem@0 246 ####
philpem@0 247 ifeq ($(BUILD_TYPE),debug)
philpem@0 248 CFLAGS += -g -ggdb -DDEBUG
philpem@0 249 CXXFLAGS += -g -ggdb -DDEBUG
philpem@0 250 else
philpem@0 251 ifeq ($(BUILD_TYPE),release)
philpem@0 252 CFLAGS += -O2
philpem@0 253 CXXFLAGS += -O2
philpem@0 254 else
philpem@0 255 $(error Unsupported build type: '$(BUILD_TYPE)')
philpem@0 256 endif
philpem@0 257 endif
philpem@0 258
philpem@0 259 ####
philpem@0 260 # wxWidgets support
philpem@0 261 ####
philpem@0 262 ifeq ($(ENABLE_WX),yes)
philpem@0 263 ifeq ($(BUILD_TYPE),debug)
philpem@0 264 LIBLNK += `wx-config --debug --libs $(WX_LIBS)`
philpem@0 265 CFLAGS += `wx-config --debug --cflags $(WX_LIBS)`
philpem@0 266 CXXFLAGS += `wx-config --debug --cxxflags $(WX_LIBS)`
philpem@0 267 CPPFLAGS += `wx-config --debug --cppflags $(WX_LIBS)`
philpem@0 268 else
philpem@0 269 ifeq ($(BUILD_TYPE),release)
philpem@0 270 LIBLNK += `wx-config --libs $(WX_LIBS)`
philpem@0 271 CFLAGS += `wx-config --cflags $(WX_LIBS)`
philpem@0 272 CPPFLAGS += `wx-config --cppflags $(WX_LIBS)`
philpem@0 273 CXXFLAGS += `wx-config --cxxflags $(WX_LIBS)`
philpem@0 274 else
philpem@0 275 $(error Unsupported build type: '$(BUILD_TYPE)')
philpem@0 276 endif
philpem@0 277 endif
philpem@0 278 endif
philpem@0 279
philpem@0 280 ####
philpem@3 281 # SDL support
philpem@3 282 ####
philpem@3 283 ifeq ($(ENABLE_SDL),yes)
philpem@13 284 LIBLNK += $(shell sdl-config --libs)
philpem@13 285 CFLAGS += $(shell sdl-config --cflags)
philpem@3 286 endif
philpem@3 287
philpem@3 288
philpem@3 289 ####
philpem@0 290 # rules
philpem@0 291 ####
philpem@0 292
philpem@0 293 # object files
philpem@0 294 OBJ = $(addprefix obj/, $(addsuffix .o, $(basename $(SRC))) $(EXT_OBJ)) $(addsuffix .o, $(basename $(EXTSRC)))
philpem@0 295
philpem@0 296 # dependency files
philpem@0 297 DEPFILES = $(addprefix dep/, $(addsuffix .d, $(basename $(SRC))) $(EXT_OBJ)) $(addsuffix .d, $(basename $(EXTSRC)))
philpem@0 298
philpem@0 299 # path commands
philpem@0 300 LIBLNK += $(addprefix -l, $(LIB))
philpem@0 301 LIBPTH += $(addprefix -L, $(LIBPATH))
philpem@0 302 INCPTH += $(addprefix -I, $(INCPATH))
philpem@0 303
philpem@0 304 CPPFLAGS += $(INCPTH)
philpem@0 305
philpem@0 306 ####
philpem@0 307 # Make sure there is at least one object file to be linked in
philpem@0 308 ####
philpem@0 309 ifeq ($(strip $(OBJ)),)
philpem@0 310 $(error Unable to build: no object or source files specified in Makefile)
philpem@0 311 endif
philpem@0 312
philpem@0 313 ####
philpem@0 314 # targets
philpem@0 315 ####
philpem@0 316 .PHONY: default all update-revision versionheader clean-versioninfo init cleandep clean tidy
philpem@0 317
philpem@0 318 all: update-revision
philpem@0 319 @$(MAKE) versionheader
philpem@0 320 $(MAKE) $(TARGET)
philpem@0 321
philpem@0 322 # increment the current build number
philpem@0 323 NEWBUILD=$(shell expr $(VER_BUILDNUM) + 1)
philpem@0 324 update-revision:
philpem@0 325 @echo $(NEWBUILD) > .buildnum
philpem@0 326
philpem@0 327 versionheader:
philpem@13 328 @sed -e 's/@@datetime@@/$(shell LC_ALL=C date +"%a %d-%b-%Y %T %Z")/g' \
philpem@13 329 -e 's/@@date@@/$(shell LC_ALL=C date +"%a %d-%b-%Y")/g' \
philpem@13 330 -e 's/@@time@@/$(shell LC_ALL=C date +"%T %Z")/g' \
philpem@0 331 -e 's/@@whoami@@/$(shell whoami)/g' \
philpem@0 332 -e 's/@@hostname@@/$(shell hostname)/g' \
philpem@0 333 -e 's|@@compiler@@|$(shell $(CC) $(CFLAGS) -v 2>&1 | tail -n 1 | sed -e "s;|;/;")|g' \
philpem@0 334 -e 's/@@majorver@@/$(VER_MAJOR)/g' \
philpem@0 335 -e 's/@@minorver@@/$(VER_MINOR)/g' \
philpem@0 336 -e 's/@@extraver@@/$(subst \",,$(VER_EXTRA))/g' \
philpem@0 337 -e 's/@@buildnum@@/$(VER_BUILDNUM)/g' \
philpem@0 338 -e 's/@@buildtype@@/$(BUILD_TYPE)/g' \
philpem@0 339 -e 's/@@vcs@@/$(VER_VCS)/g' \
philpem@0 340 -e 's/@@vcsrev@@/$(VER_VCSREV)/g' \
philpem@0 341 -e 's/@@vcsstr@@/$(VER_VCSSTR)/g' \
philpem@0 342 -e 's/@@fullverstr@@/$(VER_FULLSTR)/g' \
philpem@14 343 -e 's#@@cflags@@#$(CFLAGS)#g' \
philpem@0 344 < src/version.h.in > src/version.h
philpem@0 345
philpem@0 346 # version.h creation stuff based on code from the Xen makefile
philpem@0 347 clean-versioninfo:
philpem@0 348 @if [ ! -r src/version.h -o -O src/version.h ]; then \
philpem@0 349 rm -f src/version.h; \
philpem@0 350 fi
philpem@0 351 @echo 0 > .buildnum
philpem@0 352
philpem@0 353 # initialise the build system for a new project
philpem@0 354 init:
philpem@0 355 @mkdir -p src dep obj
philpem@0 356 @echo "This file is a directory-keeper. Do not delete it." > dep/.keepme
philpem@0 357 @echo "This file is a directory-keeper. Do not delete it." > obj/.keepme
philpem@0 358 @echo 0 > .buildnum
philpem@0 359 @echo 'syntax: glob' > .hgignore
philpem@0 360 @echo 'obj/*.o' >> .hgignore
philpem@0 361 @echo 'dep/*.d' >> .hgignore
philpem@0 362 @echo '*~' >> .hgignore
philpem@0 363 @echo '.*.sw?' >> .hgignore
philpem@13 364 @echo '#define VER_COMPILE_DATETIME "@@datetime@@"' > src/version.h.in
philpem@14 365 @echo '#define VER_COMPILE_DATE "@@date@@"' >> src/version.h.in
philpem@14 366 @echo '#define VER_COMPILE_TIME "@@time@@"' >> src/version.h.in
philpem@14 367 @echo '#define VER_COMPILE_BY "@@whoami@@"' >> src/version.h.in
philpem@14 368 @echo '#define VER_COMPILE_HOST "@@hostname@@"' >> src/version.h.in
philpem@14 369 @echo '#define VER_COMPILER "@@compiler@@"' >> src/version.h.in
philpem@14 370 @echo '#define VER_BUILD_TYPE "@@buildtype@@"' >> src/version.h.in
philpem@14 371 @echo '#define VER_CFLAGS "@@cflags@@"' >> src/version.h.in
philpem@14 372 @echo '' >> src/version.h.in
philpem@14 373 @echo '#define VER_MAJOR @@majorver@@' >> src/version.h.in
philpem@14 374 @echo '#define VER_MINOR @@minorver@@' >> src/version.h.in
philpem@14 375 @echo '#define VER_BUILDNUM @@buildnum@@' >> src/version.h.in
philpem@14 376 @echo '#define VER_EXTRA "@@extraver@@"' >> src/version.h.in
philpem@14 377 @echo '#define VER_VCSREV "@@vcsstr@@"' >> src/version.h.in
philpem@14 378 @echo '' >> src/version.h.in
philpem@14 379 @echo '#define VER_FULLSTR "@@fullverstr@@"' >> src/version.h.in
philpem@14 380 @echo '' >> src/version.h.in
philpem@0 381 @echo Build system initialised
philpem@0 382
philpem@0 383 # remove the dependency files
philpem@0 384 cleandep:
philpem@0 385 -rm $(DEPFILES)
philpem@0 386
philpem@0 387 # remove the dependency files and any target or intermediate build files
philpem@0 388 clean: cleandep clean-versioninfo
philpem@0 389 -rm $(OBJ) $(TARGET) $(GARBAGE)
philpem@0 390
philpem@0 391 # remove any dependency or intermediate build files
philpem@0 392 tidy: cleandep clean-versioninfo
philpem@0 393 -rm $(OBJ) $(GARBAGE)
philpem@0 394
philpem@0 395 #################################
philpem@0 396
philpem@0 397 $(TARGET): $(OBJ) $(EXTDEP)
philpem@0 398 ifeq ($(SRC_TYPE),c)
philpem@0 399 $(CC) $(CXXFLAGS) $(LDFLAGS) $(OBJ) $(LIBPTH) $(LIBLNK) -o $@
philpem@0 400 else
philpem@0 401 $(CXX) $(CXXFLAGS) $(LDFLAGS) $(OBJ) $(LIBPTH) $(LIBLNK) -o $@
philpem@0 402 endif
philpem@0 403 ifeq ($(BUILD_TYPE),release)
philpem@0 404 $(STRIP) $(TARGET)
philpem@0 405 endif
philpem@0 406
philpem@0 407 ###
philpem@0 408 # extra rules
philpem@0 409 # example:
philpem@0 410 #src/parser.c: src/parser.h
philpem@0 411
philpem@0 412
philpem@0 413 ####
philpem@0 414 ## musashi build rules
philpem@0 415 # 68k CPU builder
philpem@0 416 obj/musashi/m68kmake: obj/musashi/m68kmake.o
philpem@0 417 $(CC) $(CFLAGS) $(CPPFLAGS) obj/musashi/m68kmake.o -o $@
philpem@0 418 # 68k CPU sources
philpem@3 419 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 420 ./obj/musashi/m68kmake src/musashi src/musashi/m68k_in.c
philpem@0 421
philpem@0 422 ####
philpem@0 423 # make object files from C source files
philpem@0 424 obj/%.o: src/%.c
philpem@0 425 $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
philpem@0 426
philpem@0 427 ##
philpem@0 428 # make object files from C++ source files
philpem@0 429 obj/%.o: src/%.cc
philpem@0 430 $(CXX) -c $(CXXFLAGS) $(CPPFLAGS) $< -o $@
philpem@0 431
philpem@0 432 obj/%.o: src/%.cpp
philpem@0 433 $(CXX) -c $(CXXFLAGS) $(CPPFLAGS) $< -o $@
philpem@0 434
philpem@0 435 ###
philpem@0 436 # make C files from yacc/bison source
philpem@0 437 src/%.h src/%.c: src/%.y
philpem@0 438 $(YACC) $(YFLAGS) -d $<
philpem@0 439 mv -f y.tab.c $*.c
philpem@0 440 mv -f y.tab.h $*.h
philpem@0 441
philpem@0 442 ###
philpem@0 443 # make C files from lex/flex source
philpem@0 444 src/%.c: src/%.l
philpem@0 445 $(LEX) $(LFLAGS) -o$@ $<
philpem@0 446
philpem@0 447 ###
philpem@0 448 # make dependencies for our source files
philpem@0 449 dep/%.d: src/%.c
philpem@0 450 $(CC) -MM $(CFLAGS) $(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/%.cpp
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 dep/%.d: src/%.cc
philpem@0 460 $(CXX) -MM $(CXXFLAGS) $(CPPFLAGS) $< > $@.$$$$; \
philpem@0 461 sed 's,\($*\)\.o[ :]*,obj/\1.o $@ : ,g' < $@.$$$$ > $@; \
philpem@0 462 rm -f $@.$$$$
philpem@0 463
philpem@0 464 ####
philpem@0 465 # pull in the dependency files, but only for 'make $(TARGET)'
philpem@0 466 ####
philpem@0 467
philpem@0 468 ifeq ($(MAKECMDGOALS),$(TARGET))
philpem@0 469 -include $(DEPFILES)
philpem@0 470 endif