2015-08-31 64 views
0

當我鍵入make什麼都不會發生。如果我使用Linux Ubuntu做了這些工作,那麼就建立我的項目。爲什麼它不適用於BSD?生成文件是:如何在OpenBSD 5.8中使用makefile

################################################## 
## General configuration 
## ===================== 

# Every Makefile should contain this line: 
SHELL=/bin/sh 

# Program for compiling C programs. 
CC=gcc 

# What allocation strategy to use, and number of quick fit lists. 
STRATEGY=4 
NRQUICKLISTS=6 

# Extra flags to give to the C preprocessor and programs that use it (the C and Fortran compilers). 
CFLAGS=-DSTRATEGY=$(STRATEGY) -DNRQUICKLISTS=$(NRQUICKLISTS) 

# Default plus extra flags for C preprocessor and compiler. 
all_cflags=$(CFLAGS) -Wall -Wextra -ansi -O4 

# Malloc source file to use. Set to empty (with `make MALLOC=`) for system default. 
MALLOC=malloc.c 


################################################## 
## Setup files variables 
## ===================== 

# Source files to compile and link together 
srcs=$(MALLOC) tstalgorithms.c tstcrash.c tstcrash_complex.c tstcrash_simple.c \ 
    tstextreme.c tstmalloc.c tstmemory.c tstmerge.c tstrealloc.c \ 
    tstbestcase.c tstworstcase.c 

# Executables 
execs=$(patsubst tst%.c, tst%, $(filter tst%.c, $(srcs))) 


################################################## 
## Ordinary targets 
## ================ 

# http://www.gnu.org/software/make/manual/make.html#Phony-Targets 
# These are not the name of files that will be created by their recipes. 
.PHONY: all clean 

all: $(execs) 

tst%: tst%.o $(MALLOC:.c=.o) 
    $(CC) $(all_cflags) -o [email protected] $^ 

# These programs can not be compiled as ANSI-standard C. 
tst%.o: tst%.c 
    $(CC) -c $(CFLAGS) $< -o [email protected] 

# But the rest should be ANSI-standard C. 
%.o: %.c 
    $(CC) -c $(all_cflags) $< -o [email protected] 

clean: 
    -rm -f *.o core $(execs) 

這是會話:

$ strings `which make` | grep -B1 MAKE_VERSION 
$ which make 
/usr/bin/make 
$ make -V MAKE_VERSION 

$ make 
$ ls 
Makefile        tstbestcase_time.gnuplot 
README         tstcommon.h 
README.md        tstcrash.c 
RUN_TESTS        tstcrash_complex.c 
a.out         tstcrash_simple.c 
best.c         tstextreme.c 
brk.h         tstmalloc.c 
first.c         tstmemory.c 
malloc.c        tstmerge.c 
malloc.h        tstrealloc.c 
quick.c         tstworstcase.c 
tst.h         tstworstcase.dat.tgz 
tstalgorithms.c       tstworstcase_memory.gnuplot 
tstbestcase.c       tstworstcase_time.gnuplot 
tstbestcase.dat.tgz      worst.c 
tstbestcase_memory.gnuplot 
$ 

如果鍵入make malloc然後我得到這個輸出,我不明白:

$ make malloc 
gcc -DSTRATEGY=4 -DNRQUICKLISTS=6 -o malloc malloc.c 
/usr/lib/crt0.o: In function `_start': 
(.text+0xa4): undefined reference to `main' 
collect2: ld returned 1 exit status 
*** Error 1 in /home/niklas/malloc-master (<sys.mk>:85 'malloc') 
$ 
+2

你是什麼意思「什麼都沒有發生」?一些事情必須發生。你有錯誤嗎?你有沒有得到任何輸出?你會看到下一個提示嗎?外殼是否掛起?該文件的名稱是「Makefile」嗎?你使用的是什麼版本的'make'? –

+0

我使用OpenBSD 5.8中的'/ usr/bin/make'。它沒有掛起,它提供了一個沒有編譯器輸出的新提示。 Makefile與Ubuntu協同工作。 –

+1

這是令人驚訝的。什麼是運行make的返回碼? (即什麼'回聲「$?」'輸出?)這就是說,似乎是一個GNU make makefile和openbsd的默認make是最肯定的**不是** GNU make,因此可能不會工作。 –

回答

2

這是一個GNUmakefilepkg_add gmake然後鍵入gmake,或者,重寫Makefile以在make下工作。