Makefile 4.51 KB
Newer Older
1 2
# Install Configuration

3 4 5 6 7 8 9
# Your C compiler
CC=gcc
#CC=clang

# Compiler options
CFLAGS = -g -O0 -Wall

10 11
# Normally minipro is installed to /usr/local.  If you want to put it
# somewhere else, define that location here.
12 13
PREFIX ?= /usr/local
MANDIR ?= $(PREFIX)/share/man
14

15 16
# Some older releases of MacOS need some extra library flags.
#EXTRA_LIBS += "-framework Foundation -framework IOKit"
17 18


19 20 21 22 23
#########################################################################
# This section is where minipro is actually built.
# Under normal circumstances, nothing below this point should be changed.
##########################################################################

24
NAME = minipro
25
VERSION = 0.4dev
26

27 28
# If we're working from git, we have access to proper variables. If
# not, make it clear that we're working from a release.
29
#
30 31 32 33 34
GIT_DIR ?= .git
ifneq ($(and $(wildcard $(GIT_DIR)),$(shell which git)),)
        GIT_BRANCH = $(shell git rev-parse --abbrev-ref HEAD)
        GIT_HASH = $(shell git rev-parse HEAD)
        GIT_HASH_SHORT = $(shell git rev-parse --short HEAD)
35
	GIT_DATE = $(shell git show -s --format=%ci)
36
else
37 38 39 40
        GIT_BRANCH = $(shell echo "$Format:%D$" | sed s/^.*\>\\s*//)
        GIT_HASH = "$Format:%H$"
        GIT_HASH_SHORT = "$Format:%h$"
        GIT_DATE = "$Format:%ci$"
41
endif
42
BUILD_DATE = $(shell date "+%Y-%m-%d %H:%M:%S %z")
43 44
VERSION_HEADER = version.h
VERSION_STRINGS = version.c
45

46 47 48 49 50
PKG_CONFIG := $(shell which pkg-config 2>/dev/null)
ifeq ($(PKG_CONFIG),)
        ERROR := $(error "pkg-config utility not found")
endif

51
COMMON_OBJECTS=byte_utils.o database.o minipro.o tl866a.o tl866iiplus.o fuses.o easyconfig.o version.o
52 53
OBJECTS=$(COMMON_OBJECTS) main.o
PROGS=minipro
54
MINIPRO=minipro
55
MINIPROHEX=miniprohex
56 57
TESTS=$(wildcard tests/test_*.c);
OBJCOPY=objcopy
58

59
DIST_DIR = $(MINIPRO)-$(VERSION)
60 61
BIN_INSTDIR=$(DESTDIR)$(PREFIX)/bin
MAN_INSTDIR=$(DESTDIR)$(PREFIX)/share/man/man1
Valentin Dudouyt's avatar
Valentin Dudouyt committed
62

63
UDEV_DIR=$(shell $(PKG_CONFIG) --define-variable=prefix=$(PREFIX) --silence-errors --variable=udevdir udev)
64 65
UDEV_RULES_INSTDIR=$(DESTDIR)$(UDEV_DIR)/rules.d

66
COMPLETIONS_DIR=$(shell $(PKG_CONFIG) --define-variable=prefix=$(PREFIX) --silence-errors --variable=completionsdir bash-completion)
67 68
COMPLETIONS_INSTDIR=$(DESTDIR)$(COMPLETIONS_DIR)

69 70
libusb_CFLAGS := $(shell $(PKG_CONFIG) --cflags libusb-1.0)
libusb_LIBS := $(shell $(PKG_CONFIG) --libs libusb-1.0)
71

72 73 74 75
ifeq ($(libusb_LIBS),)
        ERROR := $(error "libusb-1.0 not found")
endif

76
override CFLAGS += $(libusb_CFLAGS)
77
override LIBS += $(libusb_LIBS) $(EXTRA_LIBS)
78

79
all: $(PROGS)
80

81 82
version_header: $(VERSION_HEADER)
$(VERSION_HEADER):
83
	@echo "Creating $@"
84 85 86
	@echo "/*" > $@
	@echo " * This file is automatically generated.  Do not edit." >> $@
	@echo " */" >> $@
87
	@echo "extern const char build_timestamp[];" >> $@
88
	@echo "#define VERSION \"$(VERSION)\"" >> $@
89
	@echo "#define GIT_BRANCH \"$(GIT_BRANCH)\"" >> $@
90 91
	@echo "#define GIT_HASH \"$(GIT_HASH)\"" >> $@
	@echo "#define GIT_HASH_SHORT \"$(GIT_HASH_SHORT)\"" >> $@
92
	@echo "#define GIT_DATE \"$(GIT_DATE)\"" >> $@
93

94 95 96 97 98 99 100 101
version_strings: $(VERSION_STRINGS)
$(VERSION_STRINGS):
	@echo "Creating $@"
	@echo "/*" > $@
	@echo " * This file is automatically generated.  Do not edit." >> $@
	@echo " */" >> $@
	@echo "#include \"minipro.h\"" >> $@
	@echo "#include \"version.h\"" >> $@
102
	@echo "const char build_timestamp[] = \"$(BUILD_DATE)\";" >> $@
103 104

minipro: $(VERSION_HEADER) $(VERSION_STRINGS) $(COMMON_OBJECTS) main.o
105
	$(CC) $(COMMON_OBJECTS) main.o $(LIBS) -o $(MINIPRO)
106

107
clean:
108
	rm -f $(OBJECTS) $(PROGS)
109
	rm -f version.h version.c version.o
110 111

distclean: clean
112
	rm -rf $(DIST_DIR)*
113

Valentin Dudouyt's avatar
Valentin Dudouyt committed
114
install:
115 116 117 118 119
	mkdir -p $(BIN_INSTDIR)
	mkdir -p $(MAN_INSTDIR)
	cp $(MINIPRO) $(BIN_INSTDIR)/
	cp $(MINIPROHEX) $(BIN_INSTDIR)/
	cp man/minipro.1 $(MAN_INSTDIR)/
120 121 122 123 124 125 126 127
	if [ -n "$(UDEV_DIR)" ]; then \
		mkdir -p $(UDEV_RULES_INSTDIR); \
		cp udev/rules.d/80-minipro.rules $(UDEV_RULES_INSTDIR)/; \
	fi
	if [ -n "$(COMPLETIONS_DIR)" ]; then \
		mkdir -p $(COMPLETIONS_INSTDIR); \
		cp bash_completion.d/minipro $(COMPLETIONS_INSTDIR)/; \
	fi
128 129

uninstall:
130 131 132
	rm -f $(BIN_INSTDIR)/$(MINIPRO)
	rm -f $(BIN_INSTDIR)/$(MINIPROHEX)
	rm -f $(MAN_INSTDIR)/minipro.1
133 134
	if [ -n "$(UDEV_DIR)" ]; then rm -f $(UDEV_RULES_INSTDIR)/80-minipro.rules; fi
	if [ -n "$(COMPLETIONS_DIR)" ]; then rm -f $(COMPLETIONS_INSTDIR)/minipro; fi
135

136 137
dist:
ifneq ($(and $(wildcard $(GIT_DIR)),$(shell which git)),)
138 139
	git archive --format=tgz --prefix $(DIST_DIR)/ HEAD -o $(DIST_DIR).tar.gz
	@echo Created $(DIST_DIR).tar.gz
140 141 142
else
	@echo "Not in a git repository or git command not found.  Cannot make a tarball."
endif
143 144 145


.PHONY: all dist distclean clean install test version-info