OpenMiner/Makefile
2013-03-10 16:15:24 +01:00

115 lines
4.5 KiB
Makefile
Executable File

#---------------------------------------------------------------------------------
# Compiler executables
#---------------------------------------------------------------------------------
CC := gcc
CXX := g++
#---------------------------------------------------------------------------------
# Options for code generation
#---------------------------------------------------------------------------------
CFLAGS := -g -Wall
CXXFLAGS:= $(CFLAGS) --std=c++0x
LDFLAGS := -g -Wl
#---------------------------------------------------------------------------------
# Any extra libraries you wish to link with your project
#---------------------------------------------------------------------------------
LIBS := -lGLEW -lGL -lGLU -lSDL -lXrandr
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS :=
#---------------------------------------------------------------------------------
# Source folders and executable name
#---------------------------------------------------------------------------------
TARGET := $(shell basename $(CURDIR))
BUILD := build
SOURCES := source
INCLUDES:= source include
#---------------------------------------------------------------------------------
# Source files
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------
export OUTPUT := $(CURDIR)/$(TARGET)
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir))
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
#---------------------------------------------------------------------------------
# Use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
export LD := $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
export LD := $(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------
export OFILES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o)
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir))
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
#---------------------------------------------------------------------------------
.PHONY: $(BUILD) clean install uninstall
#------------------------------------------------------------------------------
$(BUILD):
@[ -d $@ ] || mkdir -p $@
@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) $(TARGET)
#---------------------------------------------------------------------------------
install:
@cp -u $(TARGET) /usr/bin/$(TARGET)
@echo installed.
#---------------------------------------------------------------------------------
uninstall:
@rm -f /usr/bin/$(TARGET)
@echo uninstalled.
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
# Makefile targets
#---------------------------------------------------------------------------------
all: $(OUTPUT)
#---------------------------------------------------------------------------------
$(OUTPUT): $(OFILES)
@echo built ... $(notdir $@)
@$(LD) $(LDFLAGS) $(OFILES) $(LIBS) -o $@
#---------------------------------------------------------------------------------
%.o: %.c
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@
#---------------------------------------------------------------------------------
%.o: %.cpp
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(CXX) $(CXXFLAGS) $(INCLUDE) -c $< -o $@
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------