freebsd下的makefile无法编译(适用于linux)

时间:2021-12-29 17:40:40

I got the below makefile which works perfectly fine under linux as well as mac os. However it fails to do anything on FreeBSD, and I have no clue why. It gives the following output:

我得到了下面的makefile,它在linux和mac os下运行得非常好。但它无法在FreeBSD上做任何事情,我也不知道为什么。它给出了以下输出:

19:31:35 user@host:~/libhttp++/src> make
-
Making HTTP++ library..
make[1]: don't know how to make obj/libhttp++.a. Stop

make[1]: stopped in /usr/home/user/libhttp++/src/obj
*** Error code 2

Stop.
make: stopped in /usr/home/user/libhttp++/src

I also tried gmake, which gives the following output:

我也试过gmake,它给出了以下输出:

19:31:35 user@host:~/libhttp++/src> gmake
-
Making HTTP++ library..
Building Lib ...
ar -rs obj/libhttp++.a obj/html.o  obj/http.o  obj/object.o
ar: warning: creating obj/libhttp++.a
ar: warning: can't open file: obj/html.o: No such file or directory
ar: warning: can't open file: obj/http.o: No such file or directory
ar: warning: can't open file: obj/object.o: No such file or directory
ar: fatal: Failed to open 'obj/libhttp++.a'
*** Error code 70

Stop.
make[1]: stopped in /usr/home/user/libhttp++/src
gmake: *** [all] Error 1

One issue might be that i'm trying to keep all intermediate object files as well as the lib itself in a separate subdirectory ("obj").

一个问题可能是我试图将所有中间目标文件以及lib本身保存在一个单独的子目录(“obj”)中。

The problem is, I dont know much about makefiles, and the freebsd handbook as well as any example makefiles i could find via google did not help much. The makefile is basically copied from a working linux makefile I found somewhere, and well, it works on linux and mac os. Is there a way to convert it to a format which works on all 3 platforms? any help would be much appreciated.

问题是,我不太了解makefile,freebsd手册以及我可以通过谷歌找到的任何示例makefile都没有多大帮助。 makefile基本上是从我找到的工作linux makefile复制的,好吧,它适用于linux和mac os。有没有办法将其转换为适用于所有3个平台的格式?任何帮助将非常感激。

makefile:

#--------------------------------------------------------------------------
# defines
#--------------------------------------------------------------------------

LIBDIR       = ../lib
INCDIR       = ../include

OBJDIR       = obj
CXX          = g++
doLib        = ar -rs
doCompile    = $(CXX) $(CXXFLAGS)
doLink       = $(CXX) $(LFLAGS)
doClean      = rm -f *.o *~ *.a

#--------------------------------------------------------------------------
# Library
#--------------------------------------------------------------------------

OBJECTS = $(OBJDIR)/html.o \
          $(OBJDIR)/http.o \
          $(OBJDIR)/object.o

LIBXMLPATH=~/Development/libxml2_2
LIBCURLPATH=~/Development/libcurl

#CDEF += -D__FORIOS__
CXXFLAGS ?= -I ./ -I $(LIBXMLPATH)/include -I $(LIBCURLPATH)/include/curl $(CDEF) -c -ggdb -Wreturn-type -Wformat -pedantic -Wunused-variable -Wunused-label -Wunused-value -Wno-long-long

DISTLIB = http++

#--------------------------------------------------------------------------
# compile lib objects
#--------------------------------------------------------------------------

lib:    all

all:
    @(echo -; echo Making HTTP++ library..; make $(OBJDIR)/lib$(DISTLIB).a)

$(OBJDIR)/lib$(DISTLIB).a: $(OBJECTS)
    @echo Building Lib ...
    $(doLib) $@ $(OBJECTS)

clean:
    @(echo Cleanup HTTP++ library)
    $(doClean)
    (cd $(OBJDIR); $(doClean))

install:
    @(echo Installing HTTP++ library in ../include ../lib)
    (mkdir -p $(LIBDIR); mkdir -p $(INCDIR))
    (cp -p *hpp *h $(INCDIR)/ ; cp -p $(OBJDIR)/lib$(DISTLIB).a $(LIBDIR)/)

#--------------------------------------------------------------------------
# Compiler Call
#--------------------------------------------------------------------------

$(OBJDIR)/%.o: %.cc
    @echo Compile "$(*F)" ...
    $(doCompile) $(*F).cc -o $@

#--------------------------------------------------------------------------
# dependencies
#--------------------------------------------------------------------------

CHECK = def.h

$(OBJDIR)/html.o       : html.cc     $(CHECK) html.hpp
$(OBJDIR)/http.o       : http.cc     $(CHECK) http.hpp
$(OBJDIR)/object.o     : object.cc   $(CHECK) object.hp

2 个解决方案

#1


1  

GNU make has a number of extensions beyond the make on BSDs (which is sometimes available on non-BSD boxes as bsdmake). You can look at the FreeBSD man page for make to see the differences, but the most salient one is that the syntax

GNU make在BSD上有许多扩展(有时在非BSD盒子上可用作bsdmake)。您可以查看FreeBSD手册中的make来查看差异,但最突出的是语法

%.target: %.source

is only available on GNU make (there's a similar syntax, though less flexible, in BSD make).

仅适用于GNU make(在BSD make中有类似的语法,但不太灵活)。

I'd have thought that gmake would work, though. Hmm...

不过,我原本以为gmake会起作用。嗯...

Looking at the makefile, I can't see anything that creates $(OBJDIR), so it might be that that's the problem – it's the first thing I'd try to fix, at any rate. If so, then just mkdir obj beforehand might work.

看看makefile,我看不到任何创建$(OBJDIR)的东西,所以可能是那个问题 - 这是我试图解决的第一件事,无论如何。如果是这样,那么事先只需要mkdir obj即可。

#2


0  

Yesterday I found the problem:

昨天我发现了这个问题:

 all:
    @(echo -; echo Making HTTP++ library..; make $(OBJDIR)/lib$(DISTLIB).a)

This line is bad when the makefile is used with gmake, because it calls make instead of gmake. So the fix is:

当makefile与gmake一起使用时,这一行很糟糕,因为它调用make而不是gmake。所以修复是:

all:
    @(echo -; echo Making HTTP++ library..; gmake $(OBJDIR)/lib$(DISTLIB).a)

Now it works perfectly without any adjustments when using gmake.

现在,使用gmake时无需任何调整即可完美运行。

#1


1  

GNU make has a number of extensions beyond the make on BSDs (which is sometimes available on non-BSD boxes as bsdmake). You can look at the FreeBSD man page for make to see the differences, but the most salient one is that the syntax

GNU make在BSD上有许多扩展(有时在非BSD盒子上可用作bsdmake)。您可以查看FreeBSD手册中的make来查看差异,但最突出的是语法

%.target: %.source

is only available on GNU make (there's a similar syntax, though less flexible, in BSD make).

仅适用于GNU make(在BSD make中有类似的语法,但不太灵活)。

I'd have thought that gmake would work, though. Hmm...

不过,我原本以为gmake会起作用。嗯...

Looking at the makefile, I can't see anything that creates $(OBJDIR), so it might be that that's the problem – it's the first thing I'd try to fix, at any rate. If so, then just mkdir obj beforehand might work.

看看makefile,我看不到任何创建$(OBJDIR)的东西,所以可能是那个问题 - 这是我试图解决的第一件事,无论如何。如果是这样,那么事先只需要mkdir obj即可。

#2


0  

Yesterday I found the problem:

昨天我发现了这个问题:

 all:
    @(echo -; echo Making HTTP++ library..; make $(OBJDIR)/lib$(DISTLIB).a)

This line is bad when the makefile is used with gmake, because it calls make instead of gmake. So the fix is:

当makefile与gmake一起使用时,这一行很糟糕,因为它调用make而不是gmake。所以修复是:

all:
    @(echo -; echo Making HTTP++ library..; gmake $(OBJDIR)/lib$(DISTLIB).a)

Now it works perfectly without any adjustments when using gmake.

现在,使用gmake时无需任何调整即可完美运行。