Make it simpler to mix static and shared libraries
Also avoid using libtool -shared, not available by default on many platforms
This commit is contained in:
parent
cedb887262
commit
6a9ad13412
2
Makefile
2
Makefile
|
@ -26,7 +26,7 @@ BUILD=./
|
|||
SOURCES=hello.cpp
|
||||
|
||||
# Define libraries we use in that project
|
||||
LIBRARIES=lib1 lib2
|
||||
LIBRARIES=lib1.dll lib2.lib
|
||||
|
||||
# Define the product of the build (.exe will be removed for Unix builds)
|
||||
PRODUCTS=hello.exe
|
||||
|
|
|
@ -256,7 +256,10 @@ Often, a project is made of several directories or libraries. In
|
|||
must be built every time.
|
||||
|
||||
* `LIBRARIES` lists libraries, which can be subdirectories or not,
|
||||
which the products depends on.
|
||||
which the products depends on. Each library should end in either
|
||||
`.lib` or `.dll` to indicate if it's to be shared statically or
|
||||
dynamically. Note that the `PRODUCTS` in the corresponding
|
||||
subdirectory should match and produce the correct output.
|
||||
|
||||
Subdirectories are re-built everytime a top-level build is started,
|
||||
whereas libraries are re-built only if they are missing. It is
|
||||
|
|
|
@ -72,7 +72,7 @@ MAKE_CXX= $(CXX) $(CXXFLAGS) $(CPPFLAGS_$*) $(CXXFLAGS_$*) -c $< -o $@ $(
|
|||
MAKE_AS= $(CC) $(CFLAGS) $(CPPFLAGS_$*) $(CFLAGS_$*) -c $< -o $@ $(DEPFLAGS)
|
||||
MAKE_OBJDIR= mkdir -p $* && touch $@
|
||||
MAKE_LIB= $(AR) $@ $(LINK_INPUTS)&& $(RANLIB) $@
|
||||
MAKE_DLL= $(LIBTOOL) -shared $(LINK_INPUTS) -o $@
|
||||
MAKE_DLL= $(LD) -shared $(LINK_INPUTS) -o $@
|
||||
MAKE_EXE= $(LD) -o $@ $(LINK_INPUTS) $(LDFLAGS) $(LDFLAGS_$*)
|
||||
|
||||
|
||||
|
|
10
hello.cpp
10
hello.cpp
|
@ -13,6 +13,9 @@
|
|||
#warning "We expect to have iostream"
|
||||
#endif
|
||||
|
||||
extern "C" int lib1_foo(void);
|
||||
extern "C" int lib2_bar(void);
|
||||
|
||||
int main()
|
||||
{
|
||||
#if HAVE_IOSTREAM
|
||||
|
@ -22,4 +25,11 @@ int main()
|
|||
#else
|
||||
#warning "Building without <iostream> or <stdio.h>. Cross-compiling?"
|
||||
#endif // HAVE_IOSTREAM
|
||||
|
||||
if (lib1_foo() != 0)
|
||||
exit(1);
|
||||
if (lib2_bar() != 0)
|
||||
exit(2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -21,6 +21,6 @@
|
|||
|
||||
BUILD=../
|
||||
SOURCES=lib1.c
|
||||
PRODUCTS=lib1.lib
|
||||
PRODUCTS=lib1.dll
|
||||
|
||||
include $(BUILD)rules.mk
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
int lib1_foo()
|
||||
int lib1_foo(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
int lib2_bar()
|
||||
int lib2_bar(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
|
16
rules.mk
16
rules.mk
|
@ -74,9 +74,11 @@ $(error Error: Variable PRODUCTS must end in .exe, .lib or .dll)
|
|||
endif
|
||||
endif
|
||||
|
||||
LIBNAMES:= $(notdir $(LIBRARIES))
|
||||
OBJLIBRARIES:= $(LIBNAMES:%=$(OBJROOT)/%$(LIB_EXT))
|
||||
LINK_INPUTS:= $(OBJECTS) $(LINK_LIBS) $(OBJLIBRARIES)
|
||||
LIBNAMES:= $(filter %.lib, $(notdir $(LIBRARIES)))
|
||||
DLLNAMES:= $(filter %.dll, $(notdir $(LIBRARIES)))
|
||||
OBJLIBS:= $(LIBNAMES:%.lib=$(OBJROOT)/%$(LIB_EXT))
|
||||
OBJDLLS:= $(DLLNAMES:%.dll=$(OBJROOT)/%$(DLL_EXT))
|
||||
LINK_INPUTS:= $(OBJECTS) $(LINK_LIBS) $(OBJLIBS) $(OBJDLLS)
|
||||
ifneq ($(words $(LINK_INPUTS)),0)
|
||||
LINK_WINPUTS= $(patsubst %,"%", $(shell cygpath -aw $(LINK_INPUTS)))
|
||||
endif
|
||||
|
@ -158,10 +160,10 @@ goodbye:
|
|||
|
||||
hello.install:
|
||||
@$(INFO) "[INSTALL]" $(TARGET) $(BUILDENV) in $(PRETTY_DIR)
|
||||
hello.clean:
|
||||
hello.clean:o
|
||||
@$(INFO) "[CLEAN]" $(TARGET) $(BUILDENV) in $(PRETTY_DIR)
|
||||
|
||||
libraries: $(OBJLIBRARIES)
|
||||
libraries: $(OBJLIBS) $(OBJDLLS)
|
||||
product:$(OBJPRODUCTS)
|
||||
objects:$(OBJDIR:%=%/.mkdir) $(OBJECTS)
|
||||
|
||||
|
@ -258,7 +260,9 @@ endif
|
|||
|
||||
# If LIBRARIES=foo/bar, go to directory foo/bar, which should build bar.a
|
||||
$(OBJROOT)/%$(LIB_EXT): $(DEEP_BUILD)
|
||||
+$(PRINT_COMMAND) cd $(filter %$*, $(LIBRARIES) $(SUBDIRS)) && $(RECURSE_CMD)
|
||||
+$(PRINT_COMMAND) cd $(filter %$*, $(LIBRARIES:.lib=) $(SUBDIRS)) && $(RECURSE_CMD)
|
||||
$(OBJROOT)/%$(DLL_EXT): $(DEEP_BUILD)
|
||||
+$(PRINT_COMMAND) cd $(filter %$*, $(LIBRARIES:.dll=) $(SUBDIRS)) && $(RECURSE_CMD)
|
||||
%/.test:
|
||||
+$(PRINT_TEST) cd $* && $(MAKE) TARGET=$(TARGET) test
|
||||
deep_build:
|
||||
|
|
Loading…
Reference in New Issue