####### Compile Flags # Compiler CC= gcc # Compiler flags CFLAGS= -Wall -std=c99 -ggdb # Libraries CLIBS= `sdl-config --cflags` -lSDL -lSDL_ttf -lGL ####### Commands RM= rm -r MKDIR= mkdir -p ####### Directories SRCDIR= src DOCDIR= doc OUTDIR= bin OBJDIR= $(OUTDIR)/objects ####### Project # file extension for object and source files OBJEND= o SRCEND= c # name of programm (and executable) NAME= adventgame VERSION= 0.1 # path to executable EXE = $(OUTDIR)/$(NAME) # execute shell command "ls -1 src/*.c" for a listing of all source files SRCS = $(shell ls -1 $(SRCDIR)/*.$(SRCEND)) # substitude /$(SRCDIR)(.*)$(SRCEND)/$(OBJDIR)\1$(OBJEND)/ BINS = $(SRCS:$(SRCDIR)%.$(SRCEND)=$(OBJDIR)%.$(OBJEND)) # default task depends on compile all: init compile # create object-folder init: $(MKDIR) $(OBJDIR) # compile depends on object files and executable compile: $(BINS) $(EXE) # executable depends on all object files $(EXE): $(BINS) $(CC) -o $(OUTDIR)/$(NAME) -export-dynamic $(BINS) $(CLIBS) $(CFLAGS) # each file in OBJDIR/*.o depends on corresponding source file in SRCDIR # $@ = name of target (*.o) # $< = first dependency (*.c) $(OBJDIR)/%.o: $(SRCDIR)/%.$(SRCEND) $(CC) -c $< -o $@ $(CLIBS) $(CFLAGS) # delete OUTDIR # don't raise an error if directory not exists clean: $(RM) $(OUTDIR) || true # start programm run: $(OUTDIR)/$(NAME) ./$(OUTDIR)/$(NAME) -v man: $(DOCDIR)/$(NAME).6 cat $(DOCDIR)/$(NAME).6 | gzip - > $(OUTDIR)/$(NAME).6.gz man-test: $(DOCDIR)/$(NAME).6 groff -man -Tascii $(DOCDIR)/$(NAME).6 install: compile man cp $(OUTDIR)/$(NAME) /usr/local/bin/ cp $(OUTDIR)/$(NAME).6.gz /usr/local/man/ uninstall: rm /usr/local/bin/adventgame || true rm /usr/local/man/adventgame.6.gz || true export: clean mkdir -p $(OUTDIR)/adventgame-$(VERSION)/ cp -r src/ doc/ dist/ Makefile $(OUTDIR)/adventgame-$(VERSION)/ cp README.rdoc $(OUTDIR)/adventgame-$(VERSION)/README tar cjf $(OUTDIR)/adventgame-$(VERSION).tar.bz2 -C $(OUTDIR)/ adventgame-$(VERSION) # execute clean every time .PHONY: clean # don't show command in run target .SILENT: run