-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
160 lines (124 loc) · 5.1 KB
/
Makefile
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License") 1.1!
# You may not use this file except in compliance with the License.
#
# See https://spdx.org/licenses/CDDL-1.1.html for the specific
# language governing permissions and limitations under the License.
#
# Copyright 2021 Jens Elkner (jel+ipmimex-src@cs.ovgu.de)
VERSION = "1.0.0"
PREFIX ?= /usr
BINDIR ?= sbin
MANDIR ?= share/man/man8
# you probably want to append something like '/64', '/x86_64', '/amd64'
LIBDIR ?= lib
ISSUES_URL = https://github.com/jelmd/ipmimex/issues
#DEBUG_FLAGS = -DDEBUG_IPMI_IF
OS := $(shell uname -s)
MACH ?= 64
INSTALL_SunOS = ginstall
INSTALL_Linux = install
IF_SunOS = bmc
IF_Linux = openipmi
CC_SunOS = cc
CC_Linux = gcc
INSTALL ?= $(INSTALL_$(OS))
IF_DEV ?= $(IF_$(OS))
USE_CC ?= $(CC_$(OS))
# Since make sets CC automagically, we have to use the USE_CC kludge.
CC = $(USE_CC)
# If CC is set to 'cc', *_cc flags (Sun studio compiler) will be used.
# If set to 'gcc', the corresponding GNU C flags (*_gcc) will be used.
# For all others one needs to add corresponding rules.
OPTIMZE_cc ?= -xO3
OPTIMZE_gcc ?= -O3
OPTIMZE ?= $(OPTIMZE_$(CC)) -DNDEBUG
CFLAGS_cc = -xcode=pic32
CFLAGS_cc += -errtags -erroff=%none,E_UNRECOGNIZED_PRAGMA_IGNORED,E_ATTRIBUTE_UNKNOWN,E_NONPORTABLE_BIT_FIELD_TYPE -errwarn=%all -D_XOPEN_SOURCE=600 -D__EXTENSIONS__=1
CFLAGS_cc += -pedantic -v
CFLAGS_gcc = -fPIC -fsigned-char -pipe -Wno-unknown-pragmas -Wno-unused-result
CFLAGS_gcc += -fdiagnostics-show-option -Wall -Werror
CFLAGS_gcc += -pedantic -Wpointer-arith -Wwrite-strings -Wstrict-prototypes -Wnested-externs -Winline -Wextra -Wdisabled-optimization -Wformat=2 -Winit-self -Wlogical-op -Wmissing-include-dirs -Wredundant-decls -Wshadow -Wundef -Wunused -Wno-variadic-macros -Wno-parentheses -Wcast-align -Wcast-qual
CFLAGS_gcc += -Wno-unused-function -Wno-multistatement-macros
CFLAGS_Linux =
CFLAGS_SunOS = -I/usr/include/microhttpd -D_MHD_DEPR_MACRO -D__EXTENSIONS__
CFLAGS_libprom ?= $(shell [ -d /usr/include/libprom ] && printf -- '-I/usr/include/libprom' )
#CFLAGS_libprom += $(shell [ -d ../libprom/prom/include ] && printf -- '-I../libprom/prom/include' )
CFLAGS ?= -m$(MACH) $(CFLAGS_$(CC)) $(CFLAGS_libprom) $(OPTIMZE) -g
CFLAGS += -std=c11 -DVERSION=\"$(VERSION)\"
CFLAGS += -DPROM_LOG_ENABLE -D_XOPEN_SOURCE=600
CFLAGS += $(CFLAGS_$(OS)) $(DEBUG_FLAGS) -DISSUES_URL=\"$(ISSUES_URL)\"
LIBS_SunOS = -lsocket -lnsl -lm
LIBS_Linux = -lm
#LIBS_libprom += $(shell [ -d ../libprom/prom/build ] && printf -- '-L ../libprom/prom/build' )
LIBS ?= $(LIBS_$(OS)) $(LIBS_libprom)
LIBS += -lmicrohttpd -lprom
SHARED_cc := -G
SHARED_gcc := -shared
LDFLAGS_cc := -zdefs -Bdirect -zdiscard-unused=dependencies $(LIBS)
LDFLAGS_gcc := -zdefs -Wl,--as-needed $(LIBS)
SONAME_OPT_cc := -h
SONAME_OPT_gcc := -Wl,-soname,
RPATH_OPT_cc := -R
RPATH_OPT_gcc := -Wl,-rpath=
LDFLAGS ?= -m$(MACH) $(LDFLAGS_$(CC))
SHARED := $(SHARED_$(CC))
SONAME_OPT := $(SONAME_OPT_$(CC))
RPATH_OPT := $(RPATH_OPT_$(CC))
LIBCFLAGS = $(CFLAGS) $(SHARED) $(LDFLAGS) -lc
PROGS= ipmimex ipmilist
DYNLIBEXT= .so
DYNLIB_MAJOR= 1
DYNLIB_MINOR= 0
LIBRARY= ipmimex
SOBN= lib$(LIBRARY)$(DYNLIBEXT)
SONAME= $(SOBN).$(DYNLIB_MAJOR)
# uncomment to get a lib
#DYNLIB= $(SONAME).$(DYNLIB_MINOR)
LIBSRCS= hexdump.c $(IF_DEV).c ipmi_sdr_convert.c ipmi_sdr.c
LIBOBJS= $(LIBSRCS:%.c=%.o)
PROGSRCS = $(LIBSRCS)
PROGOBJS = $(PROGSRCS:%.c=%.o)
LISTOBJS = ipmilist.o
MEXOBJS = init.o prom_ipmi.o main.o
all: $(PROGS)
lib: $(DYNLIB)
$(PROGS): LDFLAGS += $(RPATH_OPT)\$$ORIGIN:\$$ORIGIN/../$(LIBDIR)
%.so: %.c %.h $(DYNLIB)
$(CC) -o $@ $< $(DYNLIB) $(LIBCFLAGS)
$(DYNLIB): Makefile $(LIBOBJS)
$(CC) -o $@ $(SHARED) $(SONAME_OPT)$(SONAME) $(LIBOBJS) $(LIBCFLAGS)
ln -sf $(DYNLIB) $(SONAME)
ipmimex: Makefile $(DYNLIB) $(PROGOBJS) $(MEXOBJS)
@echo $(PROGOBJS)
[ -z $(DYNLIB) ] && $(CC) -o $@ $(PROGOBJS) $(MEXOBJS) $(LDFLAGS) ||\
$(CC) -o $@ $(MEXOBJS) $(DYNLIB) $(LDFLAGS)
ipmilist: Makefile $(DYNLIB) $(PROGOBJS) $(LISTOBJS)
@echo $(PROGOBJS)
[ -z $(DYNLIB) ] && $(CC) -o $@ $(PROGOBJS) $(LISTOBJS) $(LDFLAGS) || \
$(CC) -o $@ $(LISTOBJS) $(DYNLIB) $(LDFLAGS)
.PHONY: clean distclean install depend
# for maintainers to get _all_ deps wrt. source headers properly honored
DEPENDFILE := makefile.dep
depend: $(DEPENDFILE)
# on Ubuntu, makedepend is included in the 'xutils-dev' package
$(DEPENDFILE): *.c *.h
makedepend -f - -Y/usr/include *.c 2>/dev/null | \
sed -e 's@/usr/include/[^ ]*@@g' -e '/: *$$/ d' >makefile.dep
clean:
rm -f *.o *~ *.so *.dep $(SONAME)* $(PROGS) \
core gmon.out a.out man.1
distclean: clean
rm -f $(DEPENDFILE) *.rej *.orig
install: all
$(INSTALL) -d $(DESTDIR)$(PREFIX)/$(BINDIR)
$(INSTALL) -d $(DESTDIR)$(PREFIX)/$(MANDIR)
$(INSTALL) -m 755 $(PROGS) $(DESTDIR)$(PREFIX)/$(BINDIR)
$(INSTALL) -m 644 ipmimex.8 $(DESTDIR)$(PREFIX)/$(MANDIR)/ipmimex.8
[ -z $(DYNLIB) ] || $(MAKE) install-lib
install-lib: $(DYNLIB)
$(INSTALL) -d $(DESTDIR)$(PREFIX)/$(LIBDIR)
$(INSTALL) -m 755 $(DYNLIB) $(DESTDIR)$(PREFIX)/$(LIBDIR)
ln -sf $(DYNLIB) $(DESTDIR)$(PREFIX)/$(LIBDIR)/$(SONAME)
ln -sf $(DYNLIB) $(DESTDIR)$(PREFIX)/$(LIBDIR)/$(SOBN)
-include $(DEPENDFILE)