Skip to content

Commit 89612f0

Browse files
committed
sys-libs/libnvidia-container: improve compiler compatibility
Upstream: NVIDIA/libnvidia-container#271 Bug: #19 Signed-off-by: Huang Rui <vowstar@gmail.com>
1 parent 2cc0d62 commit 89612f0

File tree

1 file changed

+72
-39
lines changed

1 file changed

+72
-39
lines changed
Lines changed: 72 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,32 @@
1-
# https://gitlab.archlinux.org/archlinux/packaging/packages/libnvidia-container/-/blob/main/fix-makefile.patch
1+
From 10291d688da827a199b9fb965c630192be0b7baf Mon Sep 17 00:00:00 2001
2+
From: Huang Rui <vowstar@gmail.com>
3+
Date: Tue, 18 Jun 2024 11:55:50 +0800
4+
Subject: [PATCH] Fix makefile for gcc and clang build
5+
6+
https://gitlab.archlinux.org/archlinux/packaging/packages/libnvidia-container/-/blob/main/fix-makefile.patch
7+
8+
Signed-off-by: Huang Rui <vowstar@gmail.com>
9+
---
10+
Makefile | 56 ++++++++++---------------------------------
11+
mk/nvcgo.mk | 5 +---
12+
mk/nvidia-modprobe.mk | 2 +-
13+
src/nvcgo/Makefile | 8 +++----
14+
4 files changed, 19 insertions(+), 52 deletions(-)
15+
16+
diff --git a/Makefile b/Makefile
17+
index a374cc098d95..967470a52913 100644
218
--- a/Makefile
319
+++ b/Makefile
4-
@@ -18,8 +18,6 @@
20+
@@ -18,18 +18,15 @@
521
##### Global variables #####
6-
22+
723
WITH_NVCGO ?= yes
824
-WITH_LIBELF ?= no
925
-WITH_TIRPC ?= no
1026
WITH_SECCOMP ?= yes
11-
27+
1228
##### Global definitions #####
13-
@@ -27,9 +25,8 @@
29+
1430
-export prefix = /usr/local
1531
+export prefix = /usr
1632
export exec_prefix = $(prefix)
@@ -21,8 +37,17 @@
2137
-export libdbgdir = $(prefix)/lib/debug$(libdir)
2238
export includedir = $(prefix)/include
2339
export pkgconfdir = $(libdir)/pkgconfig
24-
25-
@@ -155,17 +152,12 @@
40+
41+
@@ -137,7 +134,7 @@ LIBGO_SYMLINK := $(LIBGO_NAME).so
42+
43+
# Common flags
44+
CPPFLAGS := -D_GNU_SOURCE -D_FORTIFY_SOURCE=2 $(CPPFLAGS)
45+
-CFLAGS := -std=gnu11 -O2 -g -fdata-sections -ffunction-sections -fplan9-extensions -fstack-protector -fno-strict-aliasing -fvisibility=hidden \
46+
+CFLAGS := -std=gnu11 -O2 -g -fdata-sections -ffunction-sections -fms-extensions -fstack-protector -fno-strict-aliasing -fvisibility=hidden \
47+
-Wall -Wextra -Wcast-align -Wpointer-arith -Wmissing-prototypes -Wnonnull \
48+
-Wwrite-strings -Wlogical-op -Wformat=2 -Wmissing-format-attribute -Winit-self -Wshadow \
49+
-Wstrict-prototypes -Wunreachable-code -Wconversion -Wsign-conversion \
50+
@@ -155,17 +152,12 @@ ifeq ($(WITH_NVCGO), yes)
2651
LIB_CPPFLAGS += -DWITH_NVCGO
2752
LIB_LDLIBS_SHARED += -lpthread
2853
endif
@@ -44,30 +69,30 @@
4469
ifeq ($(WITH_SECCOMP), yes)
4570
LIB_CPPFLAGS += -DWITH_SECCOMP $(shell pkg-config --cflags libseccomp)
4671
LIB_LDLIBS_SHARED += $(shell pkg-config --libs libseccomp)
47-
@@ -219,22 +211,14 @@
72+
@@ -219,22 +211,14 @@ $(BIN_OBJS): %.o: %.c | shared
4873
-include $(DEPENDENCIES)
49-
74+
5075
$(LIB_SHARED): $(LIB_OBJS)
5176
- $(MKDIR) -p $(DEBUG_DIR)
5277
$(CC) $(LIB_CFLAGS) $(LIB_CPPFLAGS) $(LIB_LDFLAGS) $(OUTPUT_OPTION) $^ $(LIB_SCRIPT) $(LIB_LDLIBS)
5378
- $(OBJCPY) --only-keep-debug $@ $(LIB_SONAME)
5479
- $(OBJCPY) --add-gnu-debuglink=$(LIB_SONAME) $@
5580
- $(MV) $(LIB_SONAME) $(DEBUG_DIR)
5681
- $(STRIP) --strip-unneeded -R .comment $@
57-
82+
5883
$(LIB_STATIC_OBJ): $(LIB_OBJS)
5984
# FIXME Handle user-defined LDFLAGS and LDLIBS
6085
$(LD) -d -r --exclude-libs ALL -L$(DEPS_DIR)$(libdir) $(OUTPUT_OPTION) $^ $(LIB_LDLIBS_STATIC)
6186
- $(OBJCPY) --localize-hidden $@
6287
- $(STRIP) --strip-unneeded -R .comment $@
63-
88+
6489
$(BIN_NAME): $(BIN_OBJS)
6590
$(CC) $(BIN_CFLAGS) $(BIN_CPPFLAGS) $(BIN_LDFLAGS) $(OUTPUT_OPTION) $^ $(BIN_SCRIPT) $(BIN_LDLIBS)
6691
- $(STRIP) --strip-unneeded -R .comment $@
67-
92+
6893
##### Public rules #####
69-
70-
@@ -259,15 +243,9 @@
94+
95+
@@ -259,15 +243,9 @@ deps: $(LIB_RPC_SRCS) $(BUILD_DEFS)
7196
ifeq ($(WITH_NVCGO), yes)
7297
$(MAKE) -f $(MAKE_DIR)/nvcgo.mk DESTDIR=$(DEPS_DIR) MAJOR=$(MAJOR) VERSION=$(VERSION) LIB_NAME=$(LIBGO_NAME) install
7398
endif
@@ -77,14 +102,14 @@
77102
-ifeq ($(WITH_TIRPC), yes)
78103
- $(MAKE) -f $(MAKE_DIR)/libtirpc.mk DESTDIR=$(DEPS_DIR) install
79104
-endif
80-
105+
81106
install: all
82107
- $(INSTALL) -d -m 755 $(addprefix $(DESTDIR),$(includedir) $(bindir) $(libdir) $(docdir) $(libdbgdir) $(pkgconfdir))
83108
+ $(INSTALL) -d -m 755 $(addprefix $(DESTDIR),$(includedir) $(bindir) $(libdir) $(pkgconfdir))
84109
# Install header files
85110
$(INSTALL) -m 644 $(LIB_INCS) $(DESTDIR)$(includedir)
86111
# Install library files
87-
@@ -276,18 +254,18 @@
112+
@@ -276,18 +254,18 @@ install: all
88113
$(LN) -sf $(LIB_SONAME) $(DESTDIR)$(libdir)/$(LIB_SYMLINK)
89114
ifeq ($(WITH_NVCGO), yes)
90115
$(INSTALL) -m 755 $(DEPS_DIR)$(libdir)/$(LIBGO_SHARED) $(DESTDIR)$(libdir)
@@ -104,10 +129,10 @@
104129
- $(INSTALL) -m 644 $(DOC_FILES) $(DESTDIR)$(docdir)/$(LIB_NAME)-$(VERSION)
105130
+ # $(INSTALL) -d -m 755 $(DESTDIR)$(docdir)/$(LIB_NAME)-$(VERSION)
106131
+ # $(INSTALL) -m 644 $(DOC_FILES) $(DESTDIR)$(docdir)/$(LIB_NAME)-$(VERSION)
107-
132+
108133
uninstall:
109134
# Uninstall header files
110-
@@ -297,14 +275,12 @@
135+
@@ -297,14 +275,12 @@ uninstall:
111136
ifeq ($(WITH_NVCGO), yes)
112137
$(RM) $(addprefix $(DESTDIR)$(libdir)/,$(LIBGO_SHARED) $(LIBGO_SONAME) $(LIBGO_SYMLINK))
113138
endif
@@ -120,10 +145,10 @@
120145
# Uninstall documentation files
121146
- $(RM) -r $(DESTDIR)$(docdir)/$(LIB_NAME)-$(VERSION)
122147
+ # $(RM) -r $(DESTDIR)$(docdir)/$(LIB_NAME)-$(VERSION)
123-
148+
124149
dist: DESTDIR:=$(DIST_DIR)/$(LIB_NAME)_$(VERSION)$(addprefix -,$(TAG))
125150
dist: install
126-
@@ -317,12 +293,6 @@
151+
@@ -317,12 +293,6 @@ depsclean:
127152
ifeq ($(WITH_NVCGO), yes)
128153
-$(MAKE) -f $(MAKE_DIR)/nvcgo.mk clean
129154
endif
@@ -133,61 +158,69 @@
133158
-ifeq ($(WITH_TIRPC), yes)
134159
- -$(MAKE) -f $(MAKE_DIR)/libtirpc.mk clean
135160
-endif
136-
161+
137162
mostlyclean:
138163
$(RM) $(LIB_OBJS) $(LIB_STATIC_OBJ) $(BIN_OBJS) $(DEPENDENCIES)
139-
--- a/mk/nvcgo.mk 2024-02-27 13:34:22.000000000 +0100
140-
+++ b/mk/nvcgo.mk 2024-03-21 12:57:18.094692606 +0100
141-
@@ -17,7 +17,7 @@
164+
diff --git a/mk/nvcgo.mk b/mk/nvcgo.mk
165+
index 0060f0e96f8c..877a72ba21ec 100644
166+
--- a/mk/nvcgo.mk
167+
+++ b/mk/nvcgo.mk
168+
@@ -17,7 +17,7 @@ include $(MAKE_DIR)/common.mk
142169
##### Source definitions #####
143-
170+
144171
PREFIX := nvcgo
145172
-SRCS_DIR := $(DEPS_DIR)/src/$(PREFIX)
146173
+SRCS_DIR := $(CURDIR)/src/$(PREFIX)
147174
VERSION := $(VERSION)
148-
175+
149176
##### Public rules #####
150-
@@ -25,9 +25,6 @@
177+
@@ -25,9 +25,6 @@ VERSION := $(VERSION)
151178
.PHONY: all install clean
152-
179+
153180
build:
154181
- $(RM) -rf $(SRCS_DIR)
155182
- $(CP) -R $(CURDIR)/src/$(PREFIX) $(SRCS_DIR)
156183
- $(MAKE) -C $(SRCS_DIR) VERSION=$(VERSION) clean
157184
$(MAKE) -C $(SRCS_DIR) VERSION=$(VERSION) build
158-
185+
159186
install: build
187+
diff --git a/mk/nvidia-modprobe.mk b/mk/nvidia-modprobe.mk
188+
index 1633e0c47072..645cfd0e0e18 100644
160189
--- a/mk/nvidia-modprobe.mk
161190
+++ b/mk/nvidia-modprobe.mk
162-
@@ -25,7 +25,7 @@
163-
191+
@@ -25,7 +25,7 @@ PATCH_FILE := $(MAKE_DIR)/nvidia-modprobe.patch
192+
164193
ARFLAGS := -rU
165194
CPPFLAGS := -D_FORTIFY_SOURCE=2 -DNV_LINUX
166195
-CFLAGS := -O2 -g -fdata-sections -ffunction-sections -fstack-protector -fno-strict-aliasing -fPIC
167196
+CFLAGS := -O2 -g -fdata-sections -ffunction-sections -fstack-protector -fno-strict-aliasing -fPIC $(CFLAGS)
168-
197+
169198
##### Private rules #####
170-
199+
200+
diff --git a/src/nvcgo/Makefile b/src/nvcgo/Makefile
201+
index eaee95a4fb15..2ed78156d553 100644
171202
--- a/src/nvcgo/Makefile
172203
+++ b/src/nvcgo/Makefile
173-
@@ -31,15 +31,15 @@
204+
@@ -31,15 +31,15 @@ OBJ_NAME := $(LIB_NAME).so
174205
HDR_NAME := $(LIB_NAME).h
175206
CTYPES_H := ctypes.h
176-
207+
177208
-CGO_CFLAGS := -std=gnu11 -O2
178209
-CGO_LDFLAGS := -Wl,--gc-sections -Wl,-s -Wl,-soname,$(LIB_SONAME)
179210
+CGO_CFLAGS := -std=gnu11 -O2 $(CGO_CFLAGS)
180211
+CGO_LDFLAGS := -Wl,--gc-sections -Wl,-soname,$(LIB_SONAME) $(CGO_LDFLAGS)
181-
212+
182213
build: $(OBJ_NAME)
183-
214+
184215
$(OBJ_NAME): $(wildcard $(CURDIR)/*.go) $(wildcard */*.go)
185216
export CGO_CFLAGS="$(CGO_CFLAGS)"; \
186217
- export CGO_LDFLAGS="$(CGO_LDFLAGS)"; \
187-
+ export CGO_LDFLAGS="-Wl,--gc-sections -Wl,-soname,$(LIB_SONAME) $(CGO_LDFLAGS)"; \
188218
- $(GO) build -o $(@) -ldflags "-s -w" -buildmode=c-shared .
219+
+ export CGO_LDFLAGS="-Wl,--gc-sections -Wl,-soname,$(LIB_SONAME) $(CGO_LDFLAGS)"; \
189220
+ $(GO) build -o $(@) -ldflags "$(GO_LDFLAGS)" -buildmode=c-shared .
190-
221+
191222
install: $(OBJ_NAME)
192223
$(INSTALL) -d -m 755 $(addprefix $(DESTDIR),$(libdir) $(includedir)/$(PKG_NAME))
224+
--
225+
2.45.2
193226

0 commit comments

Comments
 (0)