aboutsummaryrefslogtreecommitdiffstats
path: root/build.mk
blob: a8f46525c524c7226a9153ad3381d3823bc670ac (plain) (blame)
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/make -f
# default target
all:

# output directory can be set with O:=dir
ifeq ($(O),)
  O := .
endif
srcdir := src
include src/Makefile.am
mpd_SRC := $(addprefix src/,$(filter %.c,$(mpd_SOURCES)))
mpd_HDR := $(addprefix src/,$(filter %.h,$(mpd_SOURCES)))
mpd_OBJ := $(subst .c,.o,$(addprefix $(O)/,$(mpd_SRC)))
mpd_DEP := $(subst .o,.d,$(mpd_OBJ))

-include $(mpd_DEP)

uname_s := $(shell uname -s | tr A-Z a-z 2>/dev/null || echo unknown)
uname_m := $(shell uname -m | tr A-Z a-z 2>/dev/null || echo unknown)

# build: the machine type this builds on
# HOST: the machine this runs on
build := $(uname_s)-$(uname_m)
HOST ?= $(build)
-include $(O)/config.mk
-include $(O)/config_detected.mk
include bs/deps-audio.mk
include bs/deps-input.mk
include bs/deps-misc.mk
include bs/deps-conflicts.mk

RANLIB ?= ranlib
ifneq ($(HOST),$(build))
  ifeq ($(origin CC),default)
    CC := $(HOST)-$(CC)
  endif
  ifeq ($(origin RANLIB),default)
    RANLIB := $(HOST)-$(RANLIB)
  endif
  ifeq ($(origin AR),default)
    AR := $(HOST)-$(AR)
  endif
endif

mpd_CFLAGS += -I$(O)/src -I$(O)
mpd_LDFLAGS += -lm
mpd_DIRS := $(O)/src/inputPlugins $(O)/src/audioOutputs

STRIP ?= strip
export O CC CPPFLAGS CFLAGS HOST SHELL

defconfig: $(O)/config.mk

$(O)/config.mk:
	@test -d "$(@D)" || $(SHELL) ./bs/mkdir_p.sh "$(@D)"
	@if ! test -e $@; then \
		sed -e 's/@@HOST@@/$(HOST)/g' \
		  < bs/config.mk.default > $@+ && mv $@+ $@ && \
		  echo Please edit $(O)/config.mk to your liking; fi
	@touch $@

$(O)/src/../config.h: $(O)/config.h
$(O)/config.h: $(O)/config.mk $(O)/config_detected.h
	$(MAKE) -f bs/mkconfig.h.mk $(O)/config.h

$(O)/config_detected.h:
	@test -d "$(@D)" || $(SHELL) ./bs/mkdir_p.sh "$(@D)"
	> $@+ && $(SHELL) ./bs/mkconfig-header.sh >> $@+ && \
		$(SHELL) ./bs/cross-arch.sh >> $@+ && mv $@+ $@

all: $(O)/src/mpd
	@echo OK $<
strip: $(O)/src/mpd
	$(STRIP) $(STRIP_OPTS) $<
$(O)/src/mpd: $(mpd_OBJ)
	$(CC) -o $@ $^ $(CFLAGS) $(mpd_CFLAGS) $(LDFLAGS) $(mpd_LDFLAGS)
$(O)/src/%.o: src/%.c $(O)/config.h
	@HDR_DEP_HACK="$(O)/config.h $(mpd_HDR)" \
		CFLAGS="$(CFLAGS) $(mpd_CFLAGS)" \
		$(SHELL) ./bs/mkdep.sh $< $(dir $<) $(subst .o,.d,$@)
	$(CC) $(CPPFLAGS) $(CFLAGS) $(mpd_CFLAGS) -c -o $@ $<
$(mpd_SRC): $(O)/config.h
clean:
	$(RM) $(O)/src/mpd $(mpd_OBJ)
reallyclean: clean
	$(RM) $(mpd_DEP) $(O)/depmode $(O)/config.h

# in case a .d file had a dep on a deleted file, we have this:
src/%.h src/%.c::
	@true
# we only do static linking in bs (since our main goal is cross-compiling),
# if you want dynamic linking, use autotools
$(O)/%.a::
	$(RM) $@
	$(AR) cru $@ $^
	$(RANLIB) $@
dist:
	$(SHELL) ./bs/mkdist.sh

.PHONY: clean reallyclean defconfig all
.PRECIOUS: $(O)/%.h
.SUFFIXES:
.SUFFIXES: .c .o .h .d