File: Makefile

package info (click to toggle)
libwhereami 0.0~git20200503.e07bc35-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 264 kB
  • sloc: ansic: 185; makefile: 166
file content (129 lines) | stat: -rw-r--r-- 3,839 bytes parent folder | download | duplicates (5)
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
.PHONY: build clean

# directories
ifeq ($(realpath .),)
  $(error your version of Make doesn't support $$(realpath names...) - please use GNU Make 3.81 or later)
endif

ifeq ($(platform),)
  __uname_s := $(shell sh -c 'uname -s 2>/dev/null | tr [A-Z] [a-z] || echo unknown-platform')
  __uname_m := $(shell sh -c 'uname -m 2>/dev/null | tr [A-Z] [a-z] || echo unknown-architecture')

  ifeq ($(__uname_s),linux)
    override platform := linux
    override architecture := $(__uname_m)
  endif
  ifeq ($(__uname_s),darwin)
    override platform := mac
    override architecture := $(__uname_m)
  endif
  ifeq ($(findstring mingw,$(__uname_s)),mingw)
    override platform := windows
    override architecture := $(if $(findstring MINGW32,$(MSYSTEM)),i686,$(if $(findstring MINGW64,$(MSYSTEM)),x86_64,))
    ifeq ($(CC),cc)
      override CC := gcc
    endif
  endif
  ifeq ($(__uname_s),freebsd)
    override platform := freebsd
    override architecture := $(__uname_m)
  endif
	ifeq ($(findstring cygwin,$(__uname_s)),cygwin)
		override platform := cygwin
		override architecture := $(__uname_m)
	endif
endif
ifeq ($(architecture),)
  override architecture := unknown-architecture
endif

prefix := $(realpath ..)
srcdir := $(realpath ../src)
exampledir := $(realpath ../example)
testdir := $(realpath ../test)
buildir := $(realpath .)/build
binsubdir := $(platform)-$(architecture)
bindir := $(prefix)/bin/$(binsubdir)

override CFLAGS += -O2 -g -Wall -pedantic -Werror -Wshadow -std=c99
override CXXFLAGS += -O2 -g -Wall -pedantic -Werror -Wshadow

ifeq ($(shell printf "int main(int argc, char* argv[]) { return 0; }\n" | $(CXX) -x c++ -o /dev/null -Wuseless-cast -Werror - 2> /dev/null && echo 'ok'),ok)
  override CXXFLAGS += -Wuseless-cast
endif

ifeq ($(platform),linux)
override LDFLAGS += -ldl
override CFLAGS += -D_XOPEN_SOURCE=500 -fpic
override CXXFLAGS += -fpic
endif
ifeq ($(platform),mac)
override CFLAGS += -D_DARWIN_C_SOURCE
endif
ifeq ($(platform),freebsd)
override CFLAGS += -fpic
override CXXFLAGS += -fpic
endif
ifeq ($(platform),cygwin)
override LDFLAGS += -ldl
override CFLAGS += -D_XOPEN_SOURCE=500 -fpic
override CXXFLAGS += -fpic
endif
ifeq ($(platform),android)
override CFLAGS += -fpie -pie
override CXXFLAGS += -fpie -pie
endif

ifeq ($(platform),mac)
libsuffix := .dylib
endif
ifeq ($(platform),linux)
libsuffix := .so
endif
ifeq ($(platform),windows)
libsuffix := .dll
endif
ifeq ($(platform),freebsd)
libsuffix := .so
endif
ifeq ($(platform),cygwin)
libsuffix := .dll
endif
ifeq ($(platform),android)
libsuffix := .so
endif
ifeq ($(platform),linux)
libsuffix := .so
endif

.PHONY: build-executable
build: build-executable
build-executable: $(bindir)/executable $(bindir)/executable-cpp

$(bindir)/executable: $(srcdir)/whereami.c $(srcdir)/whereami.h $(exampledir)/executable.c
	mkdir -p $(@D)
	$(CC) -I $(srcdir) $(CPPFLAGS) $(CFLAGS) $(filter-out %.h,$^) $(LDFLAGS) -o $@
	$(if $(postbuild),$(postbuild) $@)

$(bindir)/executable-cpp: $(srcdir)/whereami.c $(srcdir)/whereami.h $(exampledir)/executable.c
	mkdir -p $(@D)
	$(CXX) -x c++ -I $(srcdir) $(CPPFLAGS) $(CXXFLAGS) $(filter-out %.h,$^) $(LDFLAGS) -o $@
	$(if $(postbuild),$(postbuild) $@)

.PHONY: build-library
build: build-library
build-library: $(bindir)/library$(libsuffix) $(bindir)/library-cpp$(libsuffix)

$(bindir)/library$(libsuffix): $(srcdir)/whereami.c $(srcdir)/whereami.h $(exampledir)/library.c
	mkdir -p $(@D)
	$(CC) -I $(srcdir) $(CPPFLAGS) $(CFLAGS) $(filter-out %.h,$^) $(LDFLAGS) -shared -o $@
	$(if $(postbuild),$(postbuild) $@)

$(bindir)/library-cpp$(libsuffix): $(srcdir)/whereami.c $(srcdir)/whereami.h $(exampledir)/library.c
	mkdir -p $(@D)
	$(CXX) -x c++ -I $(srcdir) $(CPPFLAGS) $(CXXFLAGS) $(filter-out %.h,$^) $(LDFLAGS) -shared -o $@
	$(if $(postbuild),$(postbuild) $@)

clean:
	rm -rf $(buildir)
	rm -rf $(bindir)