Use CXX and CXXFLAGS, not CC and CFLAGS, for C++ code. Also use CXXFLAGS when linking C++ code so that the right -stdlib flag gets used. Rename DESTDIR to PREFIX and use DESTDIR for its intended purpose. Let the user override the defaults for these variables using env vars. Use short install options; BSD install doesn't know the long ones. Generate config.h (with correct HELP_DIR) from config.h.in. Declare target dependencies (generated by `c++ -MM`). Declare phony targets. --- Makefile.orig 2004-04-26 12:42:38.000000000 -0500 +++ Makefile 2024-10-16 13:33:41.000000000 -0500 @@ -1,14 +1,15 @@ -CC=g++ -LDFLAGS=-lncurses -lpthread -CFLAGS=-O2 -Wall -#CFLAGS=-O2 -Wall -DDEBUG +CXX?=g++ +LDFLAGS+=-lncurses -lpthread +OPTFLAGS?=-O2 +CXXFLAGS?=$(OPTFLAGS) +CXXFLAGS+=-Wall +#CXXFLAGS+=-DDEBUG objects=main.o functions.o screen.o server.o user.o messages.o signals.o parameter.o userdb.o -DESTDIR=/usr +PREFIX?=/usr BINNAME=netwalker MANPAGE=netwalker.1 -#if you alter this you also have to alter the config.h file!!! -HELP_DIR=$(DESTDIR)/share/netwalker-ircc/ +HELP_DIR=$(PREFIX)/share/netwalker-ircc/ all: notice echo_for_objects make_objects link_the_binary @@ -19,12 +20,12 @@ install: notice @echo "--== INSTALLING ==--" - mkdir -p $(DESTDIR)/bin - mkdir -p $(DESTDIR)/share/man/man1 - mkdir -p $(HELP_DIR) - install --mode=0755 $(BINNAME) $(DESTDIR)/bin/$(BINNAME) - install --mode=0644 $(MANPAGE) $(DESTDIR)/share/man/man1/$(MANPAGE) - install --mode=0644 help/* $(HELP_DIR) + mkdir -p $(DESTDIR)$(PREFIX)/bin + mkdir -p $(DESTDIR)$(PREFIX)/share/man/man1 + mkdir -p $(DESTDIR)$(HELP_DIR) + install -m 0755 $(BINNAME) $(DESTDIR)$(PREFIX)/bin/$(BINNAME) + install -m 0644 $(MANPAGE) $(DESTDIR)$(PREFIX)/share/man/man1/$(MANPAGE) + install -m 0644 help/* $(DESTDIR)$(HELP_DIR) @echo "==============================================" @echo "|| ||" @echo "|| Thank you for installing the ||" @@ -41,8 +42,8 @@ uninstall: @echo "--== UNINSTALLING ==--" - rm -f $(DESTDIR)/bin/$(BINNAME) - rm -f $(DESTDIR)/share/man/man1/$(MANPAGE) + rm -f $(DESTDIR)$(PREFIX)/bin/$(BINNAME) + rm -f $(DESTDIR)$(PREFIX)/share/man/man1/$(MANPAGE) rm -rf $(DESTDIR)$(HELP_DIR) update: notice uninstall clean all install @@ -54,7 +55,7 @@ link_the_binary: @echo "--== LINKING THE BINARY ==--" - $(CC) $(LDFLAGS) $(objects) -o $(BINNAME) + $(CXX) $(CXXFLAGS) $(LDFLAGS) $(objects) -o $(BINNAME) help: @echo "Available Options:" @@ -76,29 +77,47 @@ @echo "==============================================" @echo "" -main.o: - $(CC) $(CFLAGS) -c main.cc -o main.o +config.h: config.h.in + sed '/^#define FILES_HELP_DIRECTORY /s|".*"$$|"$(HELP_DIR)"|' < config.h.in > config.h -functions.o: - $(CC) $(CFLAGS) -c functions.cc -o functions.o +main.o: main.cc classes.h server.h config.h functions.h \ + input_parameters.h screen.h user.h messages.h parameter.h userdb.h \ + signals.h + $(CXX) $(CXXFLAGS) -c main.cc -o main.o + +functions.o: functions.cc functions.h classes.h server.h config.h \ + input_parameters.h screen.h user.h messages.h parameter.h userdb.h \ + signals.h + $(CXX) $(CXXFLAGS) -c functions.cc -o functions.o + +screen.o: screen.cc screen.h config.h classes.h server.h functions.h \ + input_parameters.h user.h messages.h parameter.h userdb.h signals.h + $(CXX) $(CXXFLAGS) -c screen.cc -o screen.o + +server.o: server.cc server.h config.h classes.h screen.h functions.h \ + user.h messages.h parameter.h userdb.h signals.h input_parameters.h + $(CXX) $(CXXFLAGS) -c server.cc -o server.o + +user.o: user.cc user.h config.h classes.h server.h functions.h \ + input_parameters.h screen.h messages.h parameter.h userdb.h signals.h + $(CXX) $(CXXFLAGS) -c user.cc -o user.o + +messages.o: messages.cc messages.h config.h classes.h server.h \ + functions.h input_parameters.h screen.h user.h parameter.h userdb.h \ + signals.h + $(CXX) $(CXXFLAGS) -c messages.cc -o messages.o + +signals.o: signals.cc signals.h config.h classes.h server.h functions.h \ + input_parameters.h screen.h user.h messages.h parameter.h userdb.h + $(CXX) $(CXXFLAGS) -c signals.cc -o signals.o + +parameter.o: parameter.cc parameter.h config.h classes.h server.h \ + functions.h input_parameters.h screen.h user.h messages.h userdb.h \ + signals.h + $(CXX) $(CXXFLAGS) -c parameter.cc -o parameter.o + +userdb.o: userdb.cc userdb.h config.h classes.h server.h functions.h \ + input_parameters.h screen.h user.h messages.h parameter.h signals.h + $(CXX) $(CXXFLAGS) -c userdb.cc -o userdb.o -screen.o: - $(CC) $(CFLAGS) -c screen.cc -o screen.o - -server.o: - $(CC) $(CFLAGS) -c server.cc -o server.o - -user.o: - $(CC) $(CFLAGS) -c user.cc -o user.o - -messages.o: - $(CC) $(CFLAGS) -c messages.cc -o messages.o - -signals.o: - $(CC) $(CFLAGS) -c signals.cc -o signals.o - -parameter.o: - $(CC) $(CFLAGS) -c parameter.cc -o parameter.o - -userdb.o: - $(CC) $(CFLAGS) -c userdb.cc -o userdb.o +.PHONY: all clean help install link_the_binary make_objects notice uninstall