Minor linking issue

This isn't a problem, more of a niggle really.

I have a project which is made up of about 7 static libraries and 5 executables. Each executable/library resides in its own directory and has its own Makefile. I have just moved it from OS X to linux, and now one of the libraries requires a function in libcrypt. This means that every executable that uses this library needs to be linked with libcrypt. I'm desperately trying to avoid the Makefiles having a load of platform dependent crap in them, and I really don't want to maintain two versions. For this reason I don't want to add -lcrypt everywhere.

The best I have come up with is this in the Makefile for the static library


$(LIBNAME) : $(OBJ)
ifeq ($(ONLINUX),yes)
        mkdir cryptdir
        cd cryptdir; ar -x /usr/lib/libcrypt.a
        ar rcs $(LIBNAME) cryptdir/*
        rm -rf cryptdir
endif
        ar rcs $(LIBNAME) $(OBJ)


Is there a better solution?
Last edited on
One solution is to create one makefile for each platform with platform-specific stuff in it, then have the initial "make" (or configure) determine which platform it is on, copy the platform-specific makefile (which may be named makefile.linux) to "makefile.global" (or whatever), then have every other makefile include makefile.global.

This keeps all the platform-specific stuff in one makefile.
Topic archived. No new replies allowed.