I have a small ANSI C application which compiles cleanly under different tested compilers and platforms. It doesn't use any preprocessor switches or external dependencies and the makefile is simply something like:
myapp: *.c
gcc *.c -Wall -o myapp
If I want to distribute this project in source form as portable as possible, should I wrap it using automake/autoconf? Will this actually increase portability or is it as portable as it gets as it is?
The only thing I can think is that it will automatically select the systems compiler but it will also add a lot of complexity. Is it worth it?
I doubt it's worth it. ANSI C without any OS-specific calls should be supported on every platform that has a working C compiler and adding automake/autoconf to this makes maintenance probably less pleasant than currently.
You can, however, use the $(CC)
variable in your makefile to automatically use the system's compiler:
myapp: *.c
$(CC) *.c $(CFLAGS) -o myapp
You don't need to specify a compilation rule, thus there is no need in $(CC)
, $(CFLAGS)
and $(LDFLAGS)
, because make
has an implicit rule to make an executable from C source.
Keep your Makefile
simple:
all: myapp
myapp: *.c
clean:
rm -f myapp
.PHONY: all clean
BTW it would be better to specify a list of source files because there is no guarantee that your sources will be the only C files in that directory
Although you may feel you'll gain little in terms of functionality, you may still wish to consider it for these reasons:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.