1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
|
# nsnake Makefile
# (2013) Alexandre Dantas <eu@alexdantas.net>
#
# This is a rather complex Makefile, sorry about that.
# It supports the following targets:
#
# make all Builds the package
# make run Builds and runs the program
# make install Installs the package on your system
# make uninstall Uninstalls the package from your system
# make clean Cleans results of building process
# make dist Creates source code "tarball"
# make doc Generates the documentation with doxygen
# make docclean Removes the documentation
#
# Also, the following commandline arguments customize
# default actions:
#
# V Verbose mode, off by default.
# To turn on for the current command,
# add `V=1` when calling `make`.
# To turn on permanently, uncomment the line
# specified below
# DESTDIR Installs the package on a custom root directory
# (other than `/`). For example `DESTDIR=~/`.
# PREFIX Installs the package on a custom directory
# (overwrites root)
# CFLAGS Changes the C flags used on compilation
# CDEBUG If you wish to build on debug mode, add 'CDEBUG=-g'
# CFLAGS_PLATFORM
# User specified compiler flags
# LDFLAGS_PLATFORM
# User specified linker flags
#
# Uncomment line below to tun on verbose mode permanently
#V = 1;
# General Info
PACKAGE = nsnake
VERSION = 3.0.0
DATE = $(shell date "+%b%Y")
# Install dirs
PREFIX = /usr
EXEC_PREFIX = $(PREFIX)
DATAROOTDIR = $(PREFIX)/share
BINDIR = $(EXEC_PREFIX)/games
# Misc stuff
PNGDIR = $(DATAROOTDIR)/icons/hicolor
XPMDIR = $(DATAROOTDIR)/pixmaps
DESKTOPDIR = $(DATAROOTDIR)/applications
LEVELDIR = $(DATAROOTDIR)/games/nsnake/levels
# Things for the man page
MANROOT = $(DATAROOTDIR)/man
MANDIR = $(MANROOT)/man$(MANNUMBER)
MANNUMBER = 6
MANFILE = $(PACKAGE).$(MANNUMBER)
MANPAGE = doc/man/$(MANFILE)
# Build info
EXE = $(PACKAGE)
CDEBUG = -O2
CXXFLAGS += $(CDEBUG) -Wall -Wextra $(CFLAGS_PLATFORM)
LDFLAGS += -lncurses $(LDFLAGS_PLATFORM)
INCLUDESDIR = -I"src/" -I"deps/"
LIBSDIR =
# All source files
CFILES = $(shell find src -type f -name '*.c')
CXXFILES = $(shell find src -type f -name '*.cpp')
OBJECTS = $(CFILES:.c=.o) \
$(CXXFILES:.cpp=.o)
DEFINES = -DVERSION=\""$(VERSION)"\" \
-DPACKAGE=\""$(PACKAGE)"\" \
-DDATE=\""$(DATE)"\" \
-DSYSTEM_LEVEL_DIR=\""$(LEVELDIR)"\"
# commander stuff
COMMANDERDIR = deps/commander
COMMANDER_CFLAGS = -O2 -Wall -Wextra $(CFLAGS_PLATFORM)
COMMANDER_OBJS = $(COMMANDERDIR)/commander.o
# Distribution tarball
TARNAME = $(PACKAGE)
DISTDIR = $(TARNAME)-$(VERSION)
# Verbose mode check
ifdef V
MUTE =
VTAG = -v
else
MUTE = @
endif
ifdef DESTDIR
ROOT = -
else
ROOT =
endif
ifdef DEBUG
CDEBUG = -D_NSNAKE_DEBUG
else
CDEBUG =
endif
# Make targets
all: dirs $(EXE)
# Build successful!
install: all
# Installing...
$(MUTE)install -pdm755 $(DESTDIR)$(BINDIR)
$(MUTE)install -pm755 bin/$(EXE) $(DESTDIR)$(BINDIR)
-$(MUTE)cat $(MANPAGE) | sed -e "s|DATE|$(DATE)|g" -e "s|VERSION|$(VERSION)|g" >$(MANFILE)
$(MUTE)install -pdm755 $(DESTDIR)$(MANDIR)
$(MUTE)install -pm644 $(MANFILE) $(DESTDIR)$(MANDIR)
$(MUTE)rm -f $(MANFILE)
$(MUTE)install -pdm755 $(DESTDIR)$(LEVELDIR)
$(MUTE)install -pm644 levels/* $(DESTDIR)$(LEVELDIR)
$(MUTE)install -pdm755 $(DESTDIR)$(PNGDIR)/16x16/apps/
$(MUTE)install -pm644 misc/nsnake16.png $(DESTDIR)$(PNGDIR)/16x16/apps/nsnake.png
$(MUTE)install -pdm755 $(DESTDIR)$(PNGDIR)/32x32/apps/
$(MUTE)install -pm644 misc/nsnake32.png $(DESTDIR)$(PNGDIR)/32x32/apps/nsnake.png
$(MUTE)install -pdm755 $(DESTDIR)$(XPMDIR)
$(MUTE)install -pm644 misc/nsnake32.xpm $(DESTDIR)$(XPMDIR)/nsnake.xpm
$(MUTE)install -pdm755 $(DESTDIR)$(DESKTOPDIR)
$(MUTE)install -pm644 misc/nsnake.desktop $(DESTDIR)$(DESKTOPDIR)
# $(PACKAGE) successfuly installed!
uninstall:
# Uninstalling...
$(MUTE)rm -f $(DESTDIR)$(BINDIR)/$(EXE)
$(MUTE)rm -f $(DESTDIR)$(MANDIR)/$(MANFILE)
$(MUTE)rm -f $(DESTDIR)$(PNGDIR)/16x16/apps/nsnake.png
$(MUTE)rm -f $(DESTDIR)$(PNGDIR)/32x32/apps/nsnake.png
$(MUTE)rm -f $(DESTDIR)$(XPMDIR)/nsnake.xpm
$(MUTE)rm -f $(DESTDIR)$(DESKTOPDIR)/nsnake.desktop
$(EXE): $(OBJECTS) $(COMMANDER_OBJS)
# Linking...
$(MUTE)$(CXX) $(CPPFLAGS) $(CFLAGS) $(CXXFLAGS) $(OBJECTS) $(COMMANDER_OBJS) -o bin/$(EXE) $(LIBSDIR) $(LDFLAGS)
src/%.o: src/%.cpp
# Compiling $<...
$(MUTE)$(CXX) $(CPPFLAGS) $(CFLAGS) $(CXXFLAGS) $(CDEBUG) $< -c -o $@ $(DEFINES) $(INCLUDESDIR)
dist: clean $(DISTDIR).tar.gz
# This creates a tarball with all the files
# versioned by GIT.
$(DISTDIR).tar.gz: $(DISTDIR)
$(MUTE)tar czf $(DISTDIR).tar.gz $(DISTDIR)
$(MUTE)rm -rf $(DISTDIR)
$(MUTE)cp $(DISTDIR).tar.gz ..
$(MUTE)rm -f $(DISTDIR).tar.gz
# Created ../$(DISTDIR).tar.gz!
# This copies all the source code files into a
# subdirectory called $(DISTDIR).
#
# It uses `git ls-files` to create the directory
# tree and copy everything to their respective
# places.
#
$(DISTDIR):
# Compressing source code...
$(MUTE)mkdir -p $(DISTDIR)
-$(MUTE)git ls-files | xargs -L 1 dirname | sed -e 's|^|$(DISTDIR)/|' | xargs -L 1 mkdir -p
-$(MUTE)git ls-files | sed -e 's|\(.*\)|\0 $(DISTDIR)/\0|' | xargs -L 1 cp
-$(MUTE)rm -f $(DISTDIR)/.gitignore
run: all
# Running...
$(MUTE)./bin/$(EXE)
clean:
# Cleaning files...
$(MUTE)rm $(VTAG) -f $(OBJECTS) $(COMMANDER_OBJS)
$(MUTE)rm $(VTAG) -f bin/$(EXE)
dirs:
$(MUTE)mkdir -p bin
doc:
# Generating documentation...
$(MUTE)doxygen Doxyfile
docclean:
# Removing documentation...
-$(MUTE)rm $(VTAG) -rf doc/html
.PHONY: clean dirs doc docclean uninstall
# commander stuff
$(COMMANDERDIR)/commander.o: $(COMMANDERDIR)/commander.c
# Compiling $<...
$(MUTE)$(CC) $(CPPFLAGS) $(CFLAGS) $(COMMANDER_CFLAGS) $< -c -o $@
|