summaryrefslogtreecommitdiff
path: root/Makefile
blob: f3abfb716646326ed065abe077c67ee71812c659 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81

CC=gcc
LD=ld
AR=ar
TAR=tar
BINEXT=
TOOLS=lxGcc64

ifndef PROJECT_VERSION
	# We just provide a primitive version string so we can see which build
	# we're using while debugging. For a release we will override the version
	# by providing it from cli args to 'make' as in:
	#     make clean package PROJECT_VERSION=1.2.3
	PROJECT_VERSION=$(shell date +0.0.0-%Y%m%d.%H%M%S)
endif

CFLAGS= --std=c99                                                             \
	-Wall -Wextra -Werror -fmax-errors=3                                      \
	-Wno-error=unused-function -Wno-error=unused-label                        \
	-Wno-error=unused-variable -Wno-error=unused-parameter                    \
	-Wno-error=unused-const-variable                                          \
	-Werror=implicit-fallthrough=1                                            \
	-Wno-error=unused-but-set-variable                                        \
	-Wno-unused-function -Wno-unused-parameter                                \
	-DPROJECT_VERSION=$(PROJECT_VERSION)

LDFLAGS= -Wl,--no-demangle,--fatal-warnings

INCDIRS= -Isrc/bulk_ln -Isrc/common

ifndef NDEBUG
	CFLAGS := $(CFLAGS) -ggdb -O0 -g3
else
	CFLAGS := $(CFLAGS) -ffunction-sections -fdata-sections -Os "-DNDEBUG=1"
	LDFLAGS := $(LDFLAGS) -Wl,--gc-sections,--as-needed
endif


default: link package

.PHONY: clean
clean:
	@echo "\n[INFO ] Clean"
	rm -rf build dist

.PHONY: link
link: build/bin/bulk-ln$(BINEXT)

build/obj/%.o: src/%.c
	@echo "\n[INFO ] Compile '$@'"
	@mkdir -p $(shell dirname build/obj/$*)
	$(CC) -c -o $@ $< $(CFLAGS) $(INCDIRS)

build/bin/bulk-ln$(BINEXT): \
		build/obj/bulk_ln/bulk_ln.o \
		build/obj/bulk_ln/bulk_ln_main.o
	@echo "\n[INFO ] Link '$@'"
	@mkdir -p $(shell dirname $@)
	$(CC) -o $@ $(LDFLAGS) $^ $(LIBSDIR)

.PHONY: package
package: link
	@echo "\n[INFO ] Package"
	@rm -rf build/dist-* dist
	@mkdir dist
	@echo
	@bash -c 'if [[ -n `git status --porcelain` ]]; then echo "[ERROR] Worktree not clean as it should be (see: git status)"; exit 1; fi'
	@# Create Executable bundle.
	@rm -rf build/dist-bin && mkdir -p build/dist-bin
	@cp -t build/dist-bin \
		README*
	@mkdir build/dist-bin/bin
	@cp -t build/dist-bin/bin \
		build/bin/*$(BINEXT)
	@(cd build/dist-bin && find . -type f -not -name MD5SUM -exec md5sum -b {} \;) > build/MD5SUM
	@mv build/MD5SUM build/dist-bin/.
	@(cd build/dist-bin && $(TAR) --owner=0 --group=0 -czf ../../dist/BulkLn-$(PROJECT_VERSION)-$(TOOLS).tgz *)
	@echo "\n[INFO ] DONE: Artifacts created and placed in 'dist'."
	@echo
	@echo See './dist/' for result.