Makefile 3.74 KB
Newer Older
1 2
# Install Configuration

3 4
# Normally minipro is installed to /usr/local.  If you want to put it
# somewhere else, define that location here.
5 6
PREFIX=/usr/local

7 8
# Some older releases of MacOS need some extra library flags.
#EXTRA_LIBS += "-framework Foundation -framework IOKit"
9 10


11 12 13 14 15
#########################################################################
# This section is where minipro is actually built.
# Under normal circumstances, nothing below this point should be changed.
##########################################################################

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
# If we're working from git, we have access to proper variables. If
# not, make it clear that we're working from a release.
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)
        GIT_TAG = $(shell git describe --abbrev=0 --tags)
else
        GIT_BRANCH = none
        GIT_HASH = none
        GIT_HASH_SHORT = none
        GIT_TAG = none
endif
BUILD_DATE_TIME = $(shell date +%Y%m%d.%k%M%S | sed s/\ //g)
31 32
VERSION_HEADER = version.h
VERSION_STRINGS = version.c
33

34 35 36 37 38
PKG_CONFIG := $(shell which pkg-config 2>/dev/null)
ifeq ($(PKG_CONFIG),)
        ERROR := $(error "pkg-config utility not found")
endif

39
COMMON_OBJECTS=byte_utils.o database.o minipro.o fuses.o easyconfig.o version.o
40 41
OBJECTS=$(COMMON_OBJECTS) main.o
PROGS=minipro
42
MINIPRO=minipro
43
MINIPROHEX=miniprohex
44 45
TESTS=$(wildcard tests/test_*.c);
OBJCOPY=objcopy
46

47
DIST_DIR = $(MINIPRO)-$(GIT_TAG)
48 49
BIN_INSTDIR=$(DESTDIR)$(PREFIX)/bin
MAN_INSTDIR=$(DESTDIR)$(PREFIX)/share/man/man1
Valentin Dudouyt's avatar
Valentin Dudouyt committed
50

51 52
libusb_CFLAGS := $(shell $(PKG_CONFIG) --cflags libusb-1.0)
libusb_LIBS := $(shell $(PKG_CONFIG) --libs libusb-1.0)
53

David Griffith's avatar
David Griffith committed
54
CFLAGS = -g -O0 -Wall
55
override CFLAGS += $(libusb_CFLAGS)
56
override LIBS += $(libusb_LIBS) $(EXTRA_LIBS)
57

58
all: $(PROGS)
59

60 61
version_header: $(VERSION_HEADER)
$(VERSION_HEADER):
62
	@echo "Creating $@"
63 64 65
	@echo "/*" > $@
	@echo " * This file is automatically generated.  Do not edit." >> $@
	@echo " */" >> $@
66
	@echo "extern const char build_timestamp[];" >> $@
67
	@echo "#define GIT_BRANCH \"$(GIT_BRANCH)\"" >> $@
68 69 70
	@echo "#define GIT_HASH \"$(GIT_HASH)\"" >> $@
	@echo "#define GIT_HASH_SHORT \"$(GIT_HASH_SHORT)\"" >> $@
	@echo "#define GIT_TAG \"$(GIT_TAG)\"" >> $@
71

72 73 74 75 76 77 78 79 80 81 82
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\"" >> $@
	@echo "const char build_timestamp[] = \"$(BUILD_DATE_TIME)\";" >> $@

minipro: $(VERSION_HEADER) $(VERSION_STRINGS) $(COMMON_OBJECTS) main.o
83
	$(CC) $(COMMON_OBJECTS) main.o $(LIBS) -o $(MINIPRO)
84

85
clean:
86
	rm -f $(OBJECTS) $(PROGS)
87
	rm -f version.h version.c version.o
88 89

distclean: clean
90
	rm -rf minipro-$(GIT_TAG)*
91

Valentin Dudouyt's avatar
Valentin Dudouyt committed
92
install:
93 94 95 96 97
	mkdir -p $(BIN_INSTDIR)
	mkdir -p $(MAN_INSTDIR)
	cp $(MINIPRO) $(BIN_INSTDIR)/
	cp $(MINIPROHEX) $(BIN_INSTDIR)/
	cp man/minipro.1 $(MAN_INSTDIR)/
98 99

uninstall:
100 101 102
	rm -f $(BIN_INSTDIR)/$(MINIPRO)
	rm -f $(BIN_INSTDIR)/$(MINIPROHEX)
	rm -f $(MAN_INSTDIR)/minipro.1
103

104
dist: distclean version-info
105 106 107 108 109 110 111 112
	git archive --format=tar --prefix=minipro-$(GIT_TAG)/ HEAD | tar xf -
	sed -i "s/GIT_BRANCH = none/GIT_BRANCH = $(GIT_BRANCH)/" minipro-$(GIT_TAG)/Makefile
	sed -i "s/GIT_HASH = none/GIT_HASH = $(GIT_HASH)/" minipro-$(GIT_TAG)/Makefile
	sed -i "s/GIT_HASH_SHORT = none/GIT_HASH_SHORT = $(GIT_HASH_SHORT)/" minipro-$(GIT_TAG)/Makefile
	sed -i "s/GIT_TAG = none/GIT_TAG = $(GIT_TAG)/" minipro-$(GIT_TAG)/Makefile
	tar zcf minipro-$(GIT_TAG).tar.gz minipro-$(GIT_TAG)
	rm -rf minipro-$(GIT_TAG)
	@echo Created minipro-$(GIT_TAG).tar.gz
113 114 115


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