ProcDump-for-Linux icon indicating copy to clipboard operation
ProcDump-for-Linux copied to clipboard

Do not hardcode CC=gcc in the Makefile

Open mcilloni opened this issue 6 years ago • 3 comments

The Makefile hardcodes the CC variable as CC=gcc, forcing users to comment it out in case they want to use clang/a different version of gcc.

It would be wiser IMHO to just leave the CC variable alone, given that in GNU Make it defaults to cc when not set (which is almost always a symlink to gcc).

mcilloni avatar Nov 05 '18 09:11 mcilloni

You can also use make CC=clang (or whatever compiler) to use a different C compiler. No need for modifying the Makefile.

alois31 avatar Nov 09 '18 17:11 alois31

@alois31 yes, you can also use that, but it doesn't really solve the issue - the Makefile should pick CC from the environment make is running from, and having GCC hardcoded it's really not useful to anyone. For instance, a script that automates package building (like Arch Linux PKGBUILDs) would have to invoke make as make CC=$CC, which is rather clunky.

mcilloni avatar Nov 09 '18 17:11 mcilloni

I was recently trying to cross compile procdump as a package for openwrt Following are some methods I tried: A. edit the CC var in the Makefile of procdump source code to "CC ?= gcc"

  1. add in my openwrt makefile the following: CC=$(TARGET_CROSS)gcc $(MAKE) This uses default cc instead of what I set(built for host rather than cross compiled). Output in logs: cc -c -g -o obj/Procdump.o src/Procdump.c -I ./include -pthread -std=gnu99
  2. export the CC variable and then invoke make export CC=$(TARGET_CROSS)gcc $(MAKE) The cross compilation is successful. Output in logs: aarch64-openwrt-linux-gnu-gcc -c -g -o obj/Procdump.o src/Procdump.c -I ./include -pthread -std=gnu99 B. Using existing Makefile, instead pass CC to make and override the one in Makefile $(MAKE) CC=$(TARGET_CROSS)gcc Output in logs: aarch64-openwrt-linux-gnu-gcc -c -g -o obj/Procdump.o src/Procdump.c -I ./include -pthread -std=gnu99

Method A.2 should be similar to what the scripts would usually have when automating package build. Change "CC=gcc" to "CC ?= gcc" should solve the problem of 1. Makefile using specifying gcc if env not set. 2. Problem of explicitly passing CC to make. Proposed Solution: --- ProcDump-for-Linux-1.1.1/Makefile 2020-04-03 12:03:02.000000000 -0700 +++ procdump/Makefile 2020-06-13 20:31:31.307826141 -0700 @@ -1,5 +1,5 @@ ROOT=. -CC=gcc +CC ?= gcc CFLAGS ?= -Wall CCFLAGS=$(CFLAGS) -I ./include -pthread -std=gnu99 LIBDIR=lib

dakshil avatar Jun 14 '20 03:06 dakshil

Fixed.

MarioHewardt avatar Apr 18 '23 18:04 MarioHewardt