Skip to content
Snippets Groups Projects
Makefile 1.65 KiB
Newer Older
  • Learn to ignore specific revisions
  • toole1's avatar
    toole1 committed
    CC = g++
    
    toole1's avatar
    toole1 committed
    CFLAGS = -Wall -Wshadow
    
    toole1's avatar
    toole1 committed
    EXENAME = monad
    
    CCMONAD = ccmonad
    
    toole1's avatar
    toole1 committed
    OBJS = $(EXENAME).o help.o util.o monad_shared.o
    
    CCOBJS = $(CCMONAD).o util.o monad_shared.o
    
    toole1's avatar
    toole1 committed
    IDFILE = .monadid
    OPTIMIZE = off
    
    ifeq ($(strip $(OPTIMIZE)),on)
    CFLAGS += -O2 -DOPTIMIZE
    else ifeq ($(strip $(OPTIMIZE)),off)
    CFLAGS += -g -O0
    else
    $(warning Invalid value specified for OPTIMIZE. Should be on or off)
    CFLAGS += -g -O0
    endif
    
    
    toole1's avatar
    toole1 committed
    LIBS:=
    IS_LIBRT:=$(shell echo "int main(){}" | g++ -o /dev/null -x c++ - -lrt &>/dev/null ; echo $$?)
    IS_LIBPNG:=$(shell echo "int main(){}" | g++ -o /dev/null -x c++ - -lpng &>/dev/null ; echo $$?)
    
    toole1's avatar
    toole1 committed
    ifeq ($(IS_LIBRT),0)
    
    toole1's avatar
    toole1 committed
    LIBS+= -lrt
    endif
    ifeq ($(IS_LIBPNG),0)
    LIBS+= -lpng 
    
    toole1's avatar
    toole1 committed
    endif
    
    
    all: $(EXENAME) $(CCMONAD) $(IDFILE)
    
    toole1's avatar
    toole1 committed
    
    $(IDFILE): $(OBJS)
    	echo -e '$(EXENAME) identification file\n'\
    'This file is used for $(EXENAME) directory identification\n'\
    'Built by' `whoami` 'on' `hostname`'\n'\
    'Build Date:' `date`> $(IDFILE)
    
    $(EXENAME): $(OBJS) $(IDFILE)
    
    toole1's avatar
    toole1 committed
    	$(CC) $(CFLAGS) $(LIBS) $(OBJS) -o $@
    
    toole1's avatar
    toole1 committed
    
    
    $(CCMONAD): $(CCOBJS) $(IDFILE)
    
    toole1's avatar
    toole1 committed
    	$(CC) $(CFLAGS) $(LIBS) $(CCOBJS) -o $@
    
    toole1's avatar
    toole1 committed
    help.o: help.cpp $(wildcard *.h) README.cgo README_config.cgo README_tests.cgo LICENSE.cgo quotes.cga
    
    toole1's avatar
    toole1 committed
    
    
    toole1's avatar
    toole1 committed
    CONVERT_TXT_TO_CGO=sed -e 's/"/\\"/g' -e 's/^/    << "/' -e 's/$$/" << endl/'
    CONVERT_TXT_TO_CGA=sed -e 's/"/\\"/g' -e 's/^/"/' -e 's/$$/",/'
    
    toole1's avatar
    toole1 committed
    
    
    toole1's avatar
    toole1 committed
    %.cgo: %.txt
    	$(CONVERT_TXT_TO_CGO) $(@:.cgo=.txt) > $@
    
    toole1's avatar
    toole1 committed
    
    
    toole1's avatar
    toole1 committed
    %.cga: %.txt
    	$(CONVERT_TXT_TO_CGA) $(@:.cga=.txt) > $@
    
    toole1's avatar
    toole1 committed
    
    
    toole1's avatar
    toole1 committed
    %.o : %.cpp $(wildcard *.h)
    
    toole1's avatar
    toole1 committed
    	$(CC) $(CFLAGS) -c $(@:.o=.cpp) -o $@
    
    .PHONY: clean
    clean:
    
    	rm -f $(wildcard *.o) $(wildcard *.cgo) $(wildcard *.cga) $(EXENAME) $(CCMONAD) $(IDFILE) $(wildcard $(EXENAME)$(EXENAME)*)
    
    toole1's avatar
    toole1 committed
    
    .PHONY: clean.sh
    clean.sh: $(EXENAME)
    	./clean.sh