82 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Makefile
		
	
	
	
	
	
			
		
		
	
	
			82 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Makefile
		
	
	
	
	
	
SHELL=/bin/bash
 | 
						|
 | 
						|
# configurable options
 | 
						|
 | 
						|
ifndef ($(SOURCES_DIR))
 | 
						|
	SOURCES_DIR := .
 | 
						|
endif
 | 
						|
 | 
						|
ifndef ($(TESTS_DIR))
 | 
						|
	TESTS_DIR := .
 | 
						|
endif
 | 
						|
 | 
						|
ifndef ($(BUILD_DIR))
 | 
						|
	BUILD_DIR := .
 | 
						|
endif
 | 
						|
 | 
						|
CC := gcc
 | 
						|
CXX := g++
 | 
						|
 | 
						|
NAME := opener
 | 
						|
 | 
						|
# dependencies
 | 
						|
 | 
						|
PACKAGE_NAMES :=
 | 
						|
 | 
						|
ifeq ($(TEST), 1)
 | 
						|
	#	PACKAGE_NAMES += check # TODO: use check?
 | 
						|
endif
 | 
						|
 | 
						|
 | 
						|
# set up cflags and libs
 | 
						|
 | 
						|
CFLAGS :=
 | 
						|
LDFLAGS :=
 | 
						|
 | 
						|
ifneq ($(PACKAGE_NAMES),)
 | 
						|
	CFLAGS += $(shell pkg-config --cflags $(PACKAGE_NAMES))
 | 
						|
	LDFLAGS += $(shell pkg-config --libs $(PACKAGE_NAMES))
 | 
						|
endif
 | 
						|
 | 
						|
ifeq ($(DEBUG),1)
 | 
						|
	CFLAGS += -O0 -pedantic -g -Wall -Wextra -Wcast-align \
 | 
						|
						-Wcast-qual -Wdisabled-optimization -Wformat=2 \
 | 
						|
						-Winit-self -Wlogical-op -Wmissing-declarations \
 | 
						|
						-Wmissing-include-dirs -Wredundant-decls -Wshadow \
 | 
						|
						-Wsign-conversion -Wstrict-overflow=5 \
 | 
						|
						-Wswitch-default -Wundef -Wno-unused
 | 
						|
	LDFLAGS += 
 | 
						|
else
 | 
						|
	CFLAGS += -O3
 | 
						|
	LDFLAGS +=
 | 
						|
endif
 | 
						|
 | 
						|
 | 
						|
# set up targets 
 | 
						|
 | 
						|
TARGETS := $(BUILD_DIR)/$(NAME)
 | 
						|
 | 
						|
ifeq ($(TEST), 1)
 | 
						|
	TARGETS += $(NAME)_test
 | 
						|
endif
 | 
						|
 | 
						|
 | 
						|
# build!
 | 
						|
 | 
						|
default: $(TARGETS)
 | 
						|
 | 
						|
.PHONY: clean $(NAME)_test
 | 
						|
 | 
						|
$(NAME)_test: $(BUILD_DIR)/$(NAME)
 | 
						|
	echo "No tests defined."
 | 
						|
	#$(BUILD_DIR)/$(NAME)
 | 
						|
 | 
						|
$(BUILD_DIR)/$(NAME): $(BUILD_DIR)/$(NAME).o
 | 
						|
	$(CC) $(CFLAGS) $^ $(LDFLAGS) -o $(BUILD_DIR)/$(NAME)
 | 
						|
 | 
						|
$(BUILD_DIR)/$(NAME).o: $(SOURCES_DIR)/$(NAME).c
 | 
						|
	$(CC) $(CFLAGS) -c $< $(LDFLAGS) -o $(BUILD_DIR)/$(NAME).o
 | 
						|
 | 
						|
clean:
 | 
						|
	rm $(BUILD_DIR)/*.o $(BUILD_DIR)/$(NAME)
 |