Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools/power/cpupower: Support building libcpupower statically

The cpupower Makefile built and installed libcpupower as a shared
library (libcpupower.so) without passing `STATIC=true`, but did not
build a static version of the library even with `STATIC=true`. (Only the
programs were static). Thus, out-of-tree programs using libcpupower
were unable to link statically against the library without having access
to intermediate object files produced during the build.

This fixes that situation by ensuring that libcpupower.a is built and
installed when `STATIC=true` is specified.

Link: https://lore.kernel.org/r/x7geegquiks3zndiavw2arihdc2rk7e2dx3lk7yxkewqii6zpg@tzjijqxyzwmu
Signed-off-by: Zuo An <zuoan.penguin@gmail.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Zuo An and committed by
Shuah Khan
059835bb 3a866087

+21 -11
+21 -11
tools/power/cpupower/Makefile
··· 37 37 # cpufreq-bench benchmarking tool 38 38 CPUFREQ_BENCH ?= true 39 39 40 - # Do not build libraries, but build the code in statically 41 - # Libraries are still built, otherwise the Makefile code would 42 - # be rather ugly. 40 + # Build the code, including libraries, statically. 43 41 export STATIC ?= false 44 42 45 43 # Prefix to the directories we're installing to ··· 205 207 $(ECHO) " CC " $@ 206 208 $(QUIET) $(CC) $(CFLAGS) -fPIC -o $@ -c lib/$*.c 207 209 208 - $(OUTPUT)libcpupower.so.$(LIB_VER): $(LIB_OBJS) 210 + ifeq ($(strip $(STATIC)),true) 211 + LIBCPUPOWER := libcpupower.a 212 + else 213 + LIBCPUPOWER := libcpupower.so.$(LIB_VER) 214 + endif 215 + 216 + $(OUTPUT)$(LIBCPUPOWER): $(LIB_OBJS) 217 + ifeq ($(strip $(STATIC)),true) 218 + $(ECHO) " AR " $@ 219 + $(QUIET) $(AR) rcs $@ $(LIB_OBJS) 220 + else 209 221 $(ECHO) " LD " $@ 210 222 $(QUIET) $(CC) -shared $(CFLAGS) $(LDFLAGS) -o $@ \ 211 223 -Wl,-soname,libcpupower.so.$(LIB_MAJ) $(LIB_OBJS) 212 224 @ln -sf $(@F) $(OUTPUT)libcpupower.so 213 225 @ln -sf $(@F) $(OUTPUT)libcpupower.so.$(LIB_MAJ) 226 + endif 214 227 215 - libcpupower: $(OUTPUT)libcpupower.so.$(LIB_VER) 228 + libcpupower: $(OUTPUT)$(LIBCPUPOWER) 216 229 217 230 # Let all .o files depend on its .c file and all headers 218 231 # Might be worth to put this into utils/Makefile at some point of time ··· 233 224 $(ECHO) " CC " $@ 234 225 $(QUIET) $(CC) $(CFLAGS) -I./lib -I ./utils -o $@ -c $*.c 235 226 236 - $(OUTPUT)cpupower: $(UTIL_OBJS) $(OUTPUT)libcpupower.so.$(LIB_VER) 227 + $(OUTPUT)cpupower: $(UTIL_OBJS) $(OUTPUT)$(LIBCPUPOWER) 237 228 $(ECHO) " CC " $@ 238 229 ifeq ($(strip $(STATIC)),true) 239 230 $(QUIET) $(CC) $(CFLAGS) $(LDFLAGS) $(UTIL_OBJS) -lrt -lpci -L$(OUTPUT) -o $@ ··· 278 269 done; 279 270 endif 280 271 281 - compile-bench: $(OUTPUT)libcpupower.so.$(LIB_VER) 272 + compile-bench: $(OUTPUT)$(LIBCPUPOWER) 282 273 @V=$(V) confdir=$(confdir) $(MAKE) -C bench O=$(OUTPUT) 283 274 284 275 # we compile into subdirectories. if the target directory is not the ··· 296 287 -find $(OUTPUT) \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print \ 297 288 | xargs rm -f 298 289 -rm -f $(OUTPUT)cpupower 290 + -rm -f $(OUTPUT)libcpupower.a 299 291 -rm -f $(OUTPUT)libcpupower.so* 300 292 -rm -rf $(OUTPUT)po/*.gmo 301 293 -rm -rf $(OUTPUT)po/*.pot ··· 305 295 306 296 install-lib: libcpupower 307 297 $(INSTALL) -d $(DESTDIR)${libdir} 298 + ifeq ($(strip $(STATIC)),true) 299 + $(CP) $(OUTPUT)libcpupower.a $(DESTDIR)${libdir}/ 300 + else 308 301 $(CP) $(OUTPUT)libcpupower.so* $(DESTDIR)${libdir}/ 302 + endif 309 303 $(INSTALL) -d $(DESTDIR)${includedir} 310 304 $(INSTALL_DATA) lib/cpufreq.h $(DESTDIR)${includedir}/cpufreq.h 311 305 $(INSTALL_DATA) lib/cpuidle.h $(DESTDIR)${includedir}/cpuidle.h ··· 350 336 @#DESTDIR must be set from outside to survive 351 337 @sbindir=$(sbindir) bindir=$(bindir) docdir=$(docdir) confdir=$(confdir) $(MAKE) -C bench O=$(OUTPUT) install 352 338 353 - ifeq ($(strip $(STATIC)),true) 354 - install: all install-tools install-man $(INSTALL_NLS) $(INSTALL_BENCH) 355 - else 356 339 install: all install-lib install-tools install-man $(INSTALL_NLS) $(INSTALL_BENCH) 357 - endif 358 340 359 341 uninstall: 360 342 - rm -f $(DESTDIR)${libdir}/libcpupower.*