@@ -37,9 +37,7 @@ NLS ?= true
3737# cpufreq-bench benchmarking tool
3838CPUFREQ_BENCH ?= true
3939
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.
4341export STATIC ?= false
4442
4543# Prefix to the directories we're installing to
@@ -207,14 +205,25 @@ $(OUTPUT)lib/%.o: $(LIB_SRC) $(LIB_HEADERS)
207205 $(ECHO ) " CC " $@
208206 $(QUIET ) $(CC ) $(CFLAGS ) -fPIC -o $@ -c lib/$* .c
209207
210- $(OUTPUT ) libcpupower.so.$(LIB_VER ) : $(LIB_OBJS )
208+ ifeq ($(strip $(STATIC ) ) ,true)
209+ LIBCPUPOWER := libcpupower.a
210+ else
211+ LIBCPUPOWER := libcpupower.so.$(LIB_VER )
212+ endif
213+
214+ $(OUTPUT )$(LIBCPUPOWER ) : $(LIB_OBJS )
215+ ifeq ($(strip $(STATIC ) ) ,true)
216+ $(ECHO) " AR " $@
217+ $(QUIET) $(AR) rcs $@ $(LIB_OBJS)
218+ else
211219 $(ECHO) " LD " $@
212220 $(QUIET) $(CC) -shared $(CFLAGS) $(LDFLAGS) -o $@ \
213221 -Wl,-soname,libcpupower.so.$(LIB_MAJ) $(LIB_OBJS)
214222 @ln -sf $(@F) $(OUTPUT)libcpupower.so
215223 @ln -sf $(@F) $(OUTPUT)libcpupower.so.$(LIB_MAJ)
224+ endif
216225
217- libcpupower : $(OUTPUT ) libcpupower.so. $( LIB_VER )
226+ libcpupower : $(OUTPUT )$( LIBCPUPOWER )
218227
219228# Let all .o files depend on its .c file and all headers
220229# Might be worth to put this into utils/Makefile at some point of time
@@ -224,7 +233,7 @@ $(OUTPUT)%.o: %.c
224233 $(ECHO ) " CC " $@
225234 $(QUIET ) $(CC ) $(CFLAGS ) -I./lib -I ./utils -o $@ -c $* .c
226235
227- $(OUTPUT ) cpupower : $(UTIL_OBJS ) $(OUTPUT ) libcpupower.so. $( LIB_VER )
236+ $(OUTPUT ) cpupower : $(UTIL_OBJS ) $(OUTPUT )$( LIBCPUPOWER )
228237 $(ECHO ) " CC " $@
229238ifeq ($(strip $(STATIC ) ) ,true)
230239 $(QUIET) $(CC) $(CFLAGS) $(LDFLAGS) $(UTIL_OBJS) -lrt -lpci -L$(OUTPUT) -o $@
@@ -269,7 +278,7 @@ update-po: $(OUTPUT)po/$(PACKAGE).pot
269278 done ;
270279endif
271280
272- compile-bench : $(OUTPUT ) libcpupower.so. $( LIB_VER )
281+ compile-bench : $(OUTPUT )$( LIBCPUPOWER )
273282 @V=$(V ) confdir=$(confdir ) $(MAKE ) -C bench O=$(OUTPUT )
274283
275284# we compile into subdirectories. if the target directory is not the
@@ -287,6 +296,7 @@ clean:
287296 -find $(OUTPUT ) \( -not -type d \) -and \( -name ' *~' -o -name ' *.[oas]' \) -type f -print \
288297 | xargs rm -f
289298 -rm -f $(OUTPUT ) cpupower
299+ -rm -f $(OUTPUT ) libcpupower.a
290300 -rm -f $(OUTPUT ) libcpupower.so*
291301 -rm -rf $(OUTPUT ) po/* .gmo
292302 -rm -rf $(OUTPUT ) po/* .pot
@@ -295,7 +305,11 @@ clean:
295305
296306install-lib : libcpupower
297307 $(INSTALL ) -d $(DESTDIR ) ${libdir}
308+ ifeq ($(strip $(STATIC ) ) ,true)
309+ $(CP) $(OUTPUT)libcpupower.a $(DESTDIR)${libdir}/
310+ else
298311 $(CP) $(OUTPUT)libcpupower.so* $(DESTDIR)${libdir}/
312+ endif
299313 $(INSTALL) -d $(DESTDIR)${includedir}
300314 $(INSTALL_DATA) lib/cpufreq.h $(DESTDIR)${includedir}/cpufreq.h
301315 $(INSTALL_DATA) lib/cpuidle.h $(DESTDIR)${includedir}/cpuidle.h
@@ -336,11 +350,7 @@ install-bench: compile-bench
336350 @# DESTDIR must be set from outside to survive
337351 @sbindir=$(sbindir ) bindir=$(bindir ) docdir=$(docdir ) confdir=$(confdir ) $(MAKE ) -C bench O=$(OUTPUT ) install
338352
339- ifeq ($(strip $(STATIC ) ) ,true)
340- install : all install-tools install-man $(INSTALL_NLS ) $(INSTALL_BENCH )
341- else
342353install : all install-lib install-tools install-man $(INSTALL_NLS ) $(INSTALL_BENCH )
343- endif
344354
345355uninstall :
346356 - rm -f $(DESTDIR ) ${libdir} /libcpupower.*
0 commit comments