Skip to content

Commit

Permalink
Build make using cmake+ninja
Browse files Browse the repository at this point in the history
For Windows, we need to avoid cross-compiling using the configure
script, because it will link with more gnulib modules than is
supported. gnulib's fcntl.c module breaks --output-sync (NDK bug 1492).
Instead, mimic build_w32.bat by:
 - building the same list of C files
 - copying the same gnulib headers
 - reusing the same config.h.W32.template file

For Darwin, the host-cpu-c-abi gnulib module breaks universal builds,
but it's easy to disable the module by editing config.h by hand
afterwards. (Removing that module from bootstrap.conf and rerunning
bootstrap might also be an option, but it changes a lot of stuff.)

I created CMakeLists.txt by translating Android.bp manually.

Bug: android/ndk#1492
Bug: android/ndk#1546
Change-Id: I367109233967ec6f0a1637b3ab262a234c93bc5b
(cherry picked from commit 487fc28)
Merged-In: I367109233967ec6f0a1637b3ab262a234c93bc5b
  • Loading branch information
rprichard authored and Android Build Coastguard Worker committed Apr 22, 2022
1 parent 08c7518 commit f080a77
Show file tree
Hide file tree
Showing 6 changed files with 976 additions and 1 deletion.
99 changes: 99 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Copyright 2021 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

project(make)
cmake_minimum_required(VERSION 3.18.1)

add_executable(make
# make_SRCS
src/ar.c
src/arscan.c
src/commands.c
src/default.c
src/dir.c
src/expand.c
src/file.c
src/function.c
src/getopt.c
src/getopt1.c
src/guile.c
src/hash.c
src/implicit.c
src/job.c
src/load.c
src/loadapi.c
src/main.c
src/misc.c
src/output.c
src/read.c
src/remake.c
src/rule.c
src/signame.c
src/strcache.c
src/variable.c
src/version.c
src/vpath.c

# USE_CUSTOMS
src/remote-stub.c
)

target_compile_definitions(make PRIVATE -DHAVE_CONFIG_H)
target_include_directories(make PRIVATE lib src)

if(UNIX)
if(CMAKE_SYSTEM_NAME STREQUAL Linux)
target_include_directories(make PRIVATE soong/linux_glibc)
target_sources(make PRIVATE lib/getloadavg.c)
target_link_libraries(make PRIVATE -ldl)
elseif(APPLE)
target_include_directories(make PRIVATE soong/darwin)
endif()
target_compile_definitions(make PRIVATE
-DLOCALEDIR=NULL
-DINCLUDEDIR=0
-DLIBDIR=0
)
target_sources(make PRIVATE
src/posixos.c
lib/concat-filename.c
lib/exitfail.c
lib/fnmatch.c
lib/findprog-in.c
lib/glob.c
lib/xalloc-die.c
lib/xconcat-filename.c
)
endif()

if(WIN32)
target_include_directories(make PRIVATE
soong/windows
src/w32/include
)
target_compile_definitions(make PRIVATE -DWINDOWS32)
target_sources(make PRIVATE
src/w32/pathstuff.c
src/w32/w32os.c
src/w32/compat/posixfcn.c
src/w32/subproc/misc.c
src/w32/subproc/sub_proc.c
src/w32/subproc/w32err.c
lib/fnmatch.c
lib/glob.c
lib/getloadavg.c
)
endif()

install(TARGETS make)
9 changes: 8 additions & 1 deletion soong/darwin/config.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
/* src/config.h. Generated from config.h.in by configure. */
/* src/config.h.in. Generated from configure.ac by autoheader. */

/* ANDROID: The "CPU and C ABI indicator" section is generated by gnulib's
host-cpu-c-abi module and is incompatible with macOS universal builds, where
a single clang invocation preprocesses source files twice, once for each
architecture. The compiler already defines __x86_64__ or __arm64__ to 1, so
stop doing it here. (For Linux, Clang only defines __aarch64__, but Darwin
Clang defines __arm64__ too.) */

/* CPU and C ABI indicator */
#ifndef __i386__
/* #undef __i386__ */
Expand All @@ -9,7 +16,7 @@
/* #undef __x86_64_x32__ */
#endif
#ifndef __x86_64__
#define __x86_64__ 1
/* #undef __x86_64__ */
#endif
#ifndef __alpha__
/* #undef __alpha__ */
Expand Down
16 changes: 16 additions & 0 deletions soong/windows/NOTE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
This directory was generated by imitating these lines in build_w32.bat:

if exist src\config.h.W32.template call :ConfigSCM
copy src\config.h.W32 %OUTDIR%\src\config.h

copy lib\glob.in.h %OUTDIR%\lib\glob.h
copy lib\fnmatch.in.h %OUTDIR%\lib\fnmatch.h

config.h.W32.template has strings like:

%PACKAGE%
%PACKAGE_VERSION%
%VERSION%

These need to be replaced with their real values. See the other config.h files
for examples.
Loading

0 comments on commit f080a77

Please sign in to comment.