2015-03-05 19:15:02 +00:00
|
|
|
.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
|
2016-01-25 21:23:45 +00:00
|
|
|
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
|
2016-02-11 13:30:39 +00:00
|
|
|
ifeq ($(__uname_s),freebsd)
|
|
|
|
override platform := freebsd
|
|
|
|
override architecture := $(__uname_m)
|
|
|
|
endif
|
2017-02-06 20:53:22 +00:00
|
|
|
ifeq ($(findstring cygwin,$(__uname_s)),cygwin)
|
|
|
|
override platform := cygwin
|
|
|
|
override architecture := $(__uname_m)
|
|
|
|
endif
|
2015-03-05 19:15:02 +00:00
|
|
|
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)
|
|
|
|
|
2016-01-25 21:11:13 +00:00
|
|
|
CFLAGS := -O2 -g -Wall -pedantic -Werror -std=c99
|
2016-01-21 11:12:28 +00:00
|
|
|
CXXFLAGS := -O2 -g -Wall -pedantic -Werror
|
2015-03-05 19:15:02 +00:00
|
|
|
|
|
|
|
ifeq ($(platform),linux)
|
2016-02-11 13:30:39 +00:00
|
|
|
LDFLAGS += -ldl
|
2016-01-25 21:23:45 +00:00
|
|
|
CFLAGS += -D_XOPEN_SOURCE=500 -fpic
|
|
|
|
CXXFLAGS += -fpic
|
2016-01-25 21:11:13 +00:00
|
|
|
endif
|
|
|
|
ifeq ($(platform),mac)
|
2016-01-25 21:23:45 +00:00
|
|
|
CFLAGS += -D_DARWIN_C_SOURCE
|
2015-03-05 19:15:02 +00:00
|
|
|
endif
|
2016-02-11 13:30:39 +00:00
|
|
|
ifeq ($(platform),freebsd)
|
|
|
|
CFLAGS += -fpic
|
|
|
|
CXXFLAGS += -fpic
|
|
|
|
endif
|
2017-02-06 20:53:22 +00:00
|
|
|
ifeq ($(platform),cygwin)
|
|
|
|
LDFLAGS += -ldl
|
|
|
|
CFLAGS += -D_XOPEN_SOURCE=500 -fpic
|
|
|
|
CXXFLAGS += -fpic
|
|
|
|
endif
|
2015-03-05 19:15:02 +00:00
|
|
|
|
|
|
|
ifeq ($(platform),mac)
|
|
|
|
libsuffix := .dylib
|
2016-01-25 21:23:45 +00:00
|
|
|
endif
|
|
|
|
ifeq ($(platform),linux)
|
2015-03-05 19:15:02 +00:00
|
|
|
libsuffix := .so
|
|
|
|
endif
|
2016-01-25 21:23:45 +00:00
|
|
|
ifeq ($(platform),windows)
|
|
|
|
libsuffix := .dll
|
|
|
|
endif
|
2016-02-11 13:30:39 +00:00
|
|
|
ifeq ($(platform),freebsd)
|
|
|
|
libsuffix := .so
|
|
|
|
endif
|
2017-02-06 20:53:22 +00:00
|
|
|
ifeq ($(platform),cygwin)
|
|
|
|
libsuffix := .dll
|
|
|
|
endif
|
2015-03-05 19:15:02 +00:00
|
|
|
|
|
|
|
.PHONY: build-executable
|
|
|
|
build: build-executable
|
2015-12-28 15:19:52 +00:00
|
|
|
build-executable: $(bindir)/executable $(bindir)/executable-cpp
|
2015-03-05 19:15:02 +00:00
|
|
|
|
|
|
|
$(bindir)/executable: $(srcdir)/whereami.c $(srcdir)/whereami.h $(exampledir)/executable.c
|
|
|
|
mkdir -p $(@D)
|
2016-10-06 07:11:33 +00:00
|
|
|
$(CC) -I $(srcdir) $(CPPFLAGS) $(CFLAGS) $(filter-out %.h,$^) $(LDFLAGS) -o $@
|
2015-03-05 19:15:02 +00:00
|
|
|
$(if $(postbuild),$(postbuild) $@)
|
|
|
|
|
2015-12-28 15:19:52 +00:00
|
|
|
$(bindir)/executable-cpp: $(srcdir)/whereami.c $(srcdir)/whereami.h $(exampledir)/executable.c
|
|
|
|
mkdir -p $(@D)
|
2016-10-06 07:11:33 +00:00
|
|
|
$(CXX) -x c++ -I $(srcdir) $(CPPFLAGS) $(CXXFLAGS) $(filter-out %.h,$^) $(LDFLAGS) -o $@
|
2015-12-28 15:19:52 +00:00
|
|
|
$(if $(postbuild),$(postbuild) $@)
|
|
|
|
|
2015-03-05 19:15:02 +00:00
|
|
|
.PHONY: build-library
|
|
|
|
build: build-library
|
2015-12-28 15:19:52 +00:00
|
|
|
build-library: $(bindir)/library$(libsuffix) $(bindir)/library-cpp$(libsuffix)
|
2015-03-05 19:15:02 +00:00
|
|
|
|
|
|
|
$(bindir)/library$(libsuffix): $(srcdir)/whereami.c $(srcdir)/whereami.h $(exampledir)/library.c
|
|
|
|
mkdir -p $(@D)
|
2016-10-06 07:11:33 +00:00
|
|
|
$(CC) -I $(srcdir) $(CPPFLAGS) $(CFLAGS) $(filter-out %.h,$^) $(LDFLAGS) -shared -o $@
|
2015-03-05 19:15:02 +00:00
|
|
|
$(if $(postbuild),$(postbuild) $@)
|
|
|
|
|
2015-12-28 15:19:52 +00:00
|
|
|
$(bindir)/library-cpp$(libsuffix): $(srcdir)/whereami.c $(srcdir)/whereami.h $(exampledir)/library.c
|
|
|
|
mkdir -p $(@D)
|
2016-10-06 07:11:33 +00:00
|
|
|
$(CXX) -x c++ -I $(srcdir) $(CPPFLAGS) $(CXXFLAGS) $(filter-out %.h,$^) $(LDFLAGS) -shared -o $@
|
2015-12-28 15:19:52 +00:00
|
|
|
$(if $(postbuild),$(postbuild) $@)
|
|
|
|
|
2015-03-05 19:15:02 +00:00
|
|
|
clean:
|
|
|
|
rm -rf $(buildir)
|
|
|
|
rm -rf $(bindir)
|