1# Install Configuration 2 3# Your C compiler 4CC?=gcc 5#CC=gcc 6 7# Compiler options 8CFLAGS ?= -g -O0 -Wall 9 10# Normally minipro is installed to /usr/local. If you want to put it 11# somewhere else, define that location here. 12PREFIX ?= /usr/local 13MANDIR ?= $(PREFIX)/man 14 15# Some older releases of MacOS need some extra library flags. 16#EXTRA_LIBS += "-framework Foundation -framework IOKit" 17 18 19######################################################################### 20# This section is where minipro is actually built. 21# Under normal circumstances, nothing below this point should be changed. 22########################################################################## 23 24NAME = minipro 25VERSION = 0.3 26 27# If we're working from git, we have access to proper variables. If 28# not, make it clear that we're working from a release. 29# 30GIT_DIR ?= .git 31ifneq ($(and $(wildcard $(GIT_DIR)),$(shell which git)),) 32 GIT_BRANCH = $(shell git rev-parse --abbrev-ref HEAD) 33 GIT_HASH = $(shell git rev-parse HEAD) 34 GIT_HASH_SHORT = $(shell git rev-parse --short HEAD) 35 GIT_DATE = $(shell git show -s --format=%ci) 36else 37 GIT_BRANCH = $(shell echo "tag: 0.3, refs/keep-around/e6fb06822e6685886a045ae98c3c82d832bd8e9c" | sed s/^.*\>\\s*//) 38 GIT_HASH = "e6fb06822e6685886a045ae98c3c82d832bd8e9c" 39 GIT_HASH_SHORT = "e6fb068" 40 GIT_DATE = "2019-02-26 22:19:06 -0800" 41endif 42BUILD_DATE = $(shell date "+%Y-%m-%d %H:%M:%S %z") 43VERSION_HEADER = version.h 44VERSION_STRINGS = version.c 45 46PKG_CONFIG := $(shell which pkg-config 2>/dev/null) 47ifeq ($(PKG_CONFIG),) 48 ERROR := $(error "pkg-config utility not found") 49endif 50 51COMMON_OBJECTS=byte_utils.o database.o minipro.o tl866a.o tl866iiplus.o fuses.o easyconfig.o version.o 52OBJECTS=$(COMMON_OBJECTS) main.o 53PROGS=minipro 54MINIPRO=minipro 55MINIPROHEX=miniprohex 56TESTS=$(wildcard tests/test_*.c); 57OBJCOPY=objcopy 58 59DIST_DIR = $(MINIPRO)-$(VERSION) 60BIN_INSTDIR=$(DESTDIR)$(PREFIX)/bin 61MAN_INSTDIR=$(DESTDIR)$(PREFIX)/man/man1 62 63UDEV_DIR=$(shell $(PKG_CONFIG) --define-variable=prefix=$(PREFIX) --silence-errors --variable=udevdir udev) 64UDEV_RULES_INSTDIR=$(DESTDIR)$(UDEV_DIR)/rules.d 65 66COMPLETIONS_DIR=$(shell $(PKG_CONFIG) --define-variable=prefix=$(PREFIX) --silence-errors --variable=completionsdir bash-completion) 67COMPLETIONS_INSTDIR=$(DESTDIR)$(COMPLETIONS_DIR) 68 69libusb_CFLAGS := $(shell $(PKG_CONFIG) --cflags libusb-1.0) 70libusb_LIBS := $(shell $(PKG_CONFIG) --libs libusb-1.0) 71 72ifeq ($(libusb_LIBS),) 73 ERROR := $(error "libusb-1.0 not found") 74endif 75 76override CFLAGS += $(libusb_CFLAGS) 77override LIBS += $(libusb_LIBS) $(EXTRA_LIBS) 78 79all: $(PROGS) 80 81version_header: $(VERSION_HEADER) 82$(VERSION_HEADER): 83 @echo "Creating $@" 84 @echo "/*" > $@ 85 @echo " * This file is automatically generated. Do not edit." >> $@ 86 @echo " */" >> $@ 87 @echo "extern const char build_timestamp[];" >> $@ 88 @echo "#define VERSION \"$(VERSION)\"" >> $@ 89 @echo "#define GIT_BRANCH \"$(GIT_BRANCH)\"" >> $@ 90 @echo "#define GIT_HASH \"$(GIT_HASH)\"" >> $@ 91 @echo "#define GIT_HASH_SHORT \"$(GIT_HASH_SHORT)\"" >> $@ 92 @echo "#define GIT_DATE \"$(GIT_DATE)\"" >> $@ 93 94version_strings: $(VERSION_STRINGS) 95$(VERSION_STRINGS): 96 @echo "Creating $@" 97 @echo "/*" > $@ 98 @echo " * This file is automatically generated. Do not edit." >> $@ 99 @echo " */" >> $@ 100 @echo "#include \"minipro.h\"" >> $@ 101 @echo "#include \"version.h\"" >> $@ 102 @echo "const char build_timestamp[] = \"$(BUILD_DATE)\";" >> $@ 103 104minipro: $(VERSION_HEADER) $(VERSION_STRINGS) $(COMMON_OBJECTS) main.o 105 $(CC) $(COMMON_OBJECTS) main.o $(LIBS) -o $(MINIPRO) 106 107clean: 108 rm -f $(OBJECTS) $(PROGS) 109 rm -f version.h version.c version.o 110 111distclean: clean 112 rm -rf $(DIST_DIR)* 113 114install: 115 mkdir -p $(BIN_INSTDIR) 116 mkdir -p $(MAN_INSTDIR) 117 cp $(MINIPRO) $(BIN_INSTDIR)/ 118 cp $(MINIPROHEX) $(BIN_INSTDIR)/ 119 cp man/minipro.1 $(MAN_INSTDIR)/ 120 if [ -n "$(UDEV_DIR)" ]; then \ 121 mkdir -p $(UDEV_RULES_INSTDIR); \ 122 cp udev/rules.d/80-minipro.rules $(UDEV_RULES_INSTDIR)/; \ 123 fi 124 if [ -n "$(COMPLETIONS_DIR)" ]; then \ 125 mkdir -p $(COMPLETIONS_INSTDIR); \ 126 cp bash_completion.d/minipro $(COMPLETIONS_INSTDIR)/; \ 127 fi 128 129uninstall: 130 rm -f $(BIN_INSTDIR)/$(MINIPRO) 131 rm -f $(BIN_INSTDIR)/$(MINIPROHEX) 132 rm -f $(MAN_INSTDIR)/minipro.1 133 if [ -n "$(UDEV_DIR)" ]; then rm -f $(UDEV_RULES_INSTDIR)/80-minipro.rules; fi 134 if [ -n "$(COMPLETIONS_DIR)" ]; then rm -f $(COMPLETIONS_INSTDIR)/minipro; fi 135 136dist: 137ifneq ($(and $(wildcard $(GIT_DIR)),$(shell which git)),) 138 git archive --format=tgz --prefix $(DIST_DIR)/ HEAD -o $(DIST_DIR).tar.gz 139 @echo Created $(DIST_DIR).tar.gz 140else 141 @echo "Not in a git repository or git command not found. Cannot make a tarball." 142endif 143 144 145.PHONY: all dist distclean clean install test version-info 146