makefilenetbsd

writing a simple makefile for NetBSD


This is my makefile:

CC = gcc
TARGET = target

CFLAGS = -O3 -Wall -Wextra -pedantic

SRCS = $(shell find . -type f -name '*.c')
OBJS = $(patsubst %.c,%.o,$(SRCS))

.PHONY: all clean

all: $(TARGET)

$(OBJS): $(SRCS)
    $(CC) $(CFLAGS) -c $< -o $@

.PRECIOUS: $(TARGET) $(OBJS)

$(TARGET): $(OBJS)
    $(CC) $(OBJS) -o $@

clean:
    -rm -f *.o
    -rm -f $(TARGET)

this is the output message:

gcc  -o target
gcc: fatal error: no input files
compilation terminated.
*** Error code 1

I'm trying to get this to work on NetBSD. What am I doing wrong? Also, I've found that $(SRCS) is just empty, but if I run find . -type f -name '*.c' in the shell on it's own, I do get the desired files. Please help !


Solution

  • Your makefile is using GNU Make syntax. However, NetBSD is a BSD-family version of UNIX, and it doesn't use GNU Make it uses some other implementation of make.

    If you write your makefile to be POSIX-conforming then it will work with either version of make, but that's very difficult because POSIX make is quite anemic. Otherwise you'll have to rewrite your makefile to use NetBSD make syntax, whereupon it will work on your NetBSD system but won't work on Linux or MacOS systems (or other systems that use GNU Make), or install GNU Make on your NetBSD system.